Solved

Apache FOP Servlet - How to change title?

Posted on 2004-08-26
2
518 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 250 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now