Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set filename of the Pdf that is streamed back to the browser

I have a Java webapp creating a pdf and streaming it back to the browser.

 byte[] pdf = report.exportPdfToArray(user);
response.setContentType("application/pdf");
response.setHeader("content-disposition", "inline; filename=\"My.pdf\"");
outStream = response.getOutputStream();
outStream.write(pdf);
outStream.flush();
outStream.close();

The report is executed and it is sent back to the browser, but I can not control the name of the file even though I set the content-disposition. I am using Jboss 4.2.1. Do you know what am I missing?

EDIT: So is there any way to set the filename when the content-disposition is inline?

like image 588
Atticus Avatar asked Jan 28 '11 14:01

Atticus


People also ask

How do I change the PDF title that appears in the browser?

Open the PDF document in Adobe Acrobat Pro: Select File > Properties. Select the Description tab to view the metadata in the document, including the document information dictionary. Modify the Title field to add or change the document's Title entry.

Can I set the filename of a PDF object displayed in Chrome?

In Chrome, the filename is derived from the URL, so as long as you are using a blob URL, the short answer is "No, you cannot set the filename of a PDF object displayed in Chrome." You have no control over the UUID assigned to the blob URL and no way to override that as the name of the page using the object element.

How do you change a PDF file name?

Here's the steps of renaming PDF files or folders:Select(long press/select icon) the target PDF or folder. Tap the 'Rename' icon at the top-right corner of PDF window. Enter the new name and tap the 'Change' button to finish.

How can I serve a PDF to a browser without storing a File on the server side?

How can I serve a PDF to a browser without storing a file on the server side? But what you can do is to use the stream that is present in HttpServletResponse on server side method and write the file directly to it. Show activity on this post. You can receive an OutputStream in your generatePDF method.


1 Answers

content-disposition: attachment ....

like image 115
Spliffster Avatar answered Oct 13 '22 23:10

Spliffster