Link to home
Start Free TrialLog in
Avatar of blackfrancis75
blackfrancis75

asked on

Apache FOP Servlet - How to change title?

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();

ASKER CERTIFIED SOLUTION
Avatar of pat5star
pat5star

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blackfrancis75
blackfrancis75

ASKER

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?