Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Apache FOP Servlet - How to change title?

Posted on 2004-08-26
2
Medium Priority
?
546 Views
Last Modified: 2013-11-24
Hi Experts,

I have a basic FOP Servlet which works well, except that when I try to save the PDF that's generated the filename is always 'FOPServlet.pdf'
This name is being read from the browser window title, so my question is; can someone tell me how to change the title of the browser window?
Note that I can't use:
                PrintWriter out = response.getWriter();
                out.println("<html><head><title>My Title</title></head>\n");
As I normally would for a servlet window title, because of the FOP processing element.

Here is the FOP servlet code:

                Driver driver = new Driver();
                driver.setLogger(this.log);
                driver.setRenderer(Driver.RENDER_PDF);

                //Setup a buffer to obtain the content length
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                driver.setOutputStream(out);

                //Setup Transformer
                Source xsltSrc = new StreamSource(new File( xslParam ));
                Transformer transformer = this.transformerFactory.newTransformer(xsltSrc);

                //Make sure the XSL transformation's result is piped through to FOP
                Result res = new SAXResult(driver.getContentHandler());

                //Setup input
                Source src = new StreamSource( new StringReader( xmlParam ) );

                //Start the transformation and rendering process
                transformer.transform(src, res);

                //Prepare response
                response.setContentType("application/pdf");
                response.setContentLength(out.size());
               
                //Send content to Browser
                response.getOutputStream().write(out.toByteArray());
                response.getOutputStream().flush();

0
Comment
Question by:blackfrancis75
2 Comments
 
LVL 3

Accepted Solution

by:
pat5star earned 750 total points
ID: 11909575
Add the Content-Disposition header to the response.

//Prepare response
response.setContentType("application/pdf");
response.setContentLength(out.size());
response.setHeader( "Content-Disposition", "attachment; filename=whatever.pdf" );

-Pat

0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 11909719
Adobe acrobat seems to ignore it if I change this to:
response.setHeader( "Content-Disposition", "inline; filename=whatever.pdf" );

do you know if this should be/ is supported?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question