Returning a PDF file
Returning a PDF file
- Subject: Returning a PDF file
- From: Johann Werner <email@hidden>
- Date: Wed, 28 Mar 2007 14:34:43 +0200
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:
This email sent to email@hidden