returning PDF via appendToResponse
returning PDF via appendToResponse
- Subject: returning PDF via appendToResponse
- From: Patrick Robinson <email@hidden>
- Date: Thu, 13 Dec 2007 15:18:53 -0500
I've seen lots of examples for returning a PDF by fiddling with the
WOResponse in a component's appendToResponse() method. Code like this:
public void appendToResponse(WOResponse res, WOContext con) {
super.appendToResponse(res, con);
if (someCondition) {
res.setContent(pdfFile);
res.setHeader("application/pdf", "Content-Type");
res.setHeader("attachment; filename=MyFile.pdf",
"Content-disposition");
res.disableClientCaching();
res.removeHeadersForKey("Cache-Control");
res.removeHeadersForKey("pragma");
}
}
We've made use of this kind of thing by having an action method that
sets "someCondition", as well as the details of what pdfFile to
download:
public void awake() {
someCondition = false;
}
public WOComponent downloadFile() {
someCondition = true;
pdfFile = nsDataForSelectedFile(selectedFile);
}
I have two problems:
(1) I was getting the PDF downloaded only every other time I clicked
the link bound to the downloadFile() action method. Because I was
curious, I implemented Application.dispatchRequest(), and discovered
that the first time I clicked the link, I'd get a PDF file in the
WOResponse. The next time I clicked it, the WOResponse would contain
the HTML of the page where the link lived! Then, the next time, I'd
get the pdf again. Why is this?
(2) I'd like to get the pdf to open in the browser, in the Acrobat
plugin (if there is one), rather than downloading it to the
downloaded file dir. I've read things suggesting that:
- you just need to change the content-disposition from "attachment"
to "inline".
- you may also need to specify "; name=MyFile.pdf" after the
"application/pdf" content-type.
- you may or may not need to specify the content-length.
- you shouldn't be calling super.appendToResponse(). I don't
understand how this would make a difference, as I'm replacing the
response's content, anyway.
But none of these things seems to work. Just changing the content-
disposition to inline has the effect of making the browser window go
black for a sec, then back to the HTML page (making me think maybe I
was on the right track).
At this point, I discovered problem (1), and wondered if the way I'm
mangling the WOResponse has something to do with it.
Anyone have any insights? I'd sure appreciate it!
--
Patrick Robinson
AHNR Info Technology, Virginia Tech
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden