Re: Returning a PDF file
Re: Returning a PDF file
- Subject: Re: Returning a PDF file
- From: George Domurot <email@hidden>
- Date: Wed, 28 Mar 2007 07:02:03 -0700
Johann: I believe here's the entire list of method calls you want
within appendToResponse for a PDF response:
aResponse.disableClientCaching();
aResponse.removeHeadersForKey("cache-control");
aResponse.removeHeadersForKey("pragma");
aResponse.setHeader("application/pdf", "content-type");
aResponse.setHeader("Report PDF", "content-description");
aResponse.setHeader("inline; filename=\"" + --> your PDF
file name <-- + ".pdf\"", "content-disposition");
aResponse.setHeader( --> your PDF file length <--, "content-length");
aResponse.setContent( --> your PDF <-- );
-George
On Mar 28, 2007, at 5:34 AM, Johann Werner wrote:
Hi,
I have some trouble returning a PDF file that I am creating on the
fly to a browser. I set the header information as noted on the
wikibooks website to:
public void appendToResponse(WOResponse aResponse, WOContext
aContext) {
super.appendToResponse(aResponse, aContext);
aResponse.setHeader("application/pdf", "Content-Type");
aResponse.setHeader("inline; attachment; filename=\"MyPDF.pdf\"",
"Content-Disposition");
aResponse.setHeader("" + aktPDF.length(), "Content-Length");
aResponse.setContent(aktPDF);
}
where aktPDF is of type NSData. When I click on the link to return
the PDF I get a blank page in Safari. When I look at the page
source I can see that the data has been loaded. In order to see the
PDF I have to save the page and change the file extension to pdf
prior to being able to open it in Preview.
Firefox displays all the ASCII text in the browser window instead
of a blank page.
By changing the second header information from "inline;
attachment;" to "application;" Firefox ask to download the pdf
file. Safari behaves as in the first case.
How can I get that to work? Could it be related to the fact, that I
am setting the default encoding to UTF8 and setting header
information in the applications appendToResponse?
public Application() {
super();
System.out.println("Welcome to " + this.name() + "!");
/* ** Put your application initialization code here ** */
WOMessage.setDefaultEncoding("UTF8");
}
public void appendToResponse(WOResponse response, WOContext
wocontext) {
super.appendToResponse(response, wocontext);
if (_NSUtilities.UTF8StringEncoding.equals
(response.contentEncoding()))
response.setHeader("text/html; charset=UTF-8", "Content-Type");
}
But if I call super first and then set the header to "application/
pdf" there should be no problem?
Johann
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40boxofficetickets.com
This email sent to 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