Last modified by Pascal Robert on 2013/05/03 09:29

From version 5.1
edited by Quinton Dolan
on 2007/07/12 20:36
Change comment: There is no comment for this version
To version 6.1
edited by Pascal Robert
on 2007/09/03 15:14
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Programming__WebObjects-Web Applications-Development-PDF Generation
1 +Web Applications-Development-PDF Generation
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.qdolan
1 +XWiki.probert
Content
... ... @@ -1,8 +1,8 @@
1 -== Overview ==
1 +== Overview ==
2 2  
3 -You might want to also review the [[Returning a File>>Programming__WebObjects-Web Applications-Development-Examples-Return a File]] example.
3 +You might want to also review the [[Returning a File>>Web Applications-Development-Examples-Return a File]] example.
4 4  
5 -== Zak Burke's Example ==
5 +== Zak Burke's Example ==
6 6  
7 7  It is important to add "-Djava.awt.headless=true" to the "Additional Arguments" list to suppress a console window running WOBootstrap that will try to pop up and then fail to close, which seems to prevent the thread from returning, which causes the app to hang.
8 8  
... ... @@ -12,26 +12,26 @@
12 12  {
13 13   // binary container for PDF
14 14   ByteArrayOutputStream out = null;
15 -
15 +
16 16   try
17 17   {
18 18   // assume these exist
19 19   String xsl, xml;
20 -
20 +
21 21   TransformerFactory transformerFactory = TransformerFactory.newInstance();
22 -
22 +
23 23   // configure FOP, apache's XML->PDF transformer
24 24   Fop fop = new Fop(MimeConstants.MIME_PDF);
25 25   out = new ByteArrayOutputStream();
26 26   fop.setOutputStream(out);
27 -
27 +
28 28   // configure XSLT transformer
29 29   Source xsltSrc = new StreamSource(new StringReader(xsl));
30 30   Transformer transformer = transformerFactory.newTransformer(xsltSrc);
31 -
31 +
32 32   // pipe XSL transformation through to FOP
33 33   Result res = new SAXResult(fop.getDefaultHandler());
34 -
34 +
35 35   // grab XML input stream
36 36   Source src = new StreamSource(new StringReader(xml));
37 37  
... ... @@ -46,7 +46,7 @@
46 46   // TransformerFactoryConfigurationError
47 47   // TransformerException
48 48   }
49 -
49 +
50 50   return out;
51 51  }
52 52  
... ... @@ -53,14 +53,14 @@
53 53  public void appendToResponse(WOResponse response, WOContext context)
54 54  {
55 55   ByteArrayOutputStream out = pdf();
56 -
56 +
57 57   // without data, show the PDF page, which is just an error message.
58 58   if (out == null)
59 59   super.appendToResponse(response, context);
60 -
60 +
61 61   // assume this exists
62 62   String filename;
63 -
63 +
64 64   response.setHeader("application/pdf", "Content-Type");
65 65   response.setHeader("" + out.size() + "", "Content-Length");
66 66   response.setHeader("attachment;filename=" + filename, "Content-Disposition");
... ... @@ -69,7 +69,7 @@
69 69  
70 70  {{/code}}
71 71  
72 -== Related Links ==
72 +== Related Links ==
73 73  
74 74  * [[FyTek Exe/DLL PDF Libraries>>http://www.fytek.com]]
75 75  * [[Java PDF Libraries>>http://schmidt.devlib.org/java/libraries-pdf.html]]
... ... @@ -84,5 +84,3 @@
84 84  * [[WebPDF Reports>>http://www.secondmove.com/WebPDFReports/index.shtml.en]]
85 85  * [[XSL:FO Examples>>http://www.dpawson.co.uk/xsl/sect3/]]
86 86  * [[ReportMill>>http://www.reportmill.com/product/]]
87 -
88 -Category:WebObjects