Solved

Apache FOP Servlet - How to change title?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 55
login jsp example 24 46
Tomcat: Unable to run tomcat service. 2 18
by zero exception 10 39
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

816 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

9 Experts available now in Live!

Get 1:1 Help Now