You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

output.xml 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?xml version="1.0" standalone="no"?>
  2. <!--
  3. Copyright 1999-2006 The Apache Software Foundation
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. -->
  14. <!-- $Id$ -->
  15. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
  16. <!-- Output Formats: Renderers -->
  17. <document>
  18. <header>
  19. <title>Apache FOP Output Formats</title>
  20. <version>$Revision$</version>
  21. <authors>
  22. <person name="Keiron Liddle" email="keiron@aftexsw.com"/>
  23. <person name="Art Welch" email=""/>
  24. </authors>
  25. </header>
  26. <body>
  27. <p>
  28. FOP supports multiple output formats by using a different renderer for each format.
  29. The renderers do not all have the same set of capabilities, sometimes because of
  30. the output format itself, sometimes because some renderers get more development
  31. attention than others.
  32. </p>
  33. <section id="general">
  34. <title>General Information</title>
  35. <section id="general-fonts">
  36. <title>Fonts</title>
  37. <p>
  38. Most FOP renderers use a FOP-specific system for font registration.
  39. However, the Java2D/AWT and print renderers use the Java AWT package, which gets its
  40. font information from the operating system registration.
  41. This can result in several differences, including actually using different fonts,
  42. and having different font metrics for the same font.
  43. The net effect is that the layout of a given FO document can be quite different between
  44. renderers that do not use the same font information.
  45. </p>
  46. </section>
  47. <section id="general-direct-output">
  48. <title>Output to a Printer or Other Device</title>
  49. <p>
  50. The most obvious way to print your document is to use the FOP
  51. <a href="#print">print renderer</a>, which uses the Java2D API (AWT).
  52. However, you can also send output from the Postscript renderer directly to a Postscript
  53. device, or output from the PCL renderer directly to a PCL device.
  54. </p>
  55. <p>
  56. Here are Windows command-line examples for Postscript and PCL:
  57. </p>
  58. <source><![CDATA[fop ... -ps \\computername\printer]]></source>
  59. <source><![CDATA[fop ... -pcl \\computername\printer]]></source>
  60. <p>
  61. Here is some Java code to accomplish the task in UNIX:
  62. </p>
  63. <source><![CDATA[proc = Runtime.getRuntime().exec("lp -d" + print_queue + " -o -dp -");
  64. out = proc.getOutputStream();]]></source>
  65. <p>
  66. Set the output MIME type to "application/x-pcl" (MimeConstants.MIME_PCL) and
  67. it happily sends the PCL to the UNIX printer queue.
  68. </p>
  69. </section>
  70. </section>
  71. <section id="pdf">
  72. <title>PDF</title>
  73. <p>
  74. PDF is the best supported output format. It is also the most accurate
  75. with text and layout. This creates a PDF document that is streamed out
  76. as each page is rendered. This means that the internal page index
  77. information is stored near the end of the document.
  78. The PDF version supported is 1.4. PDF versions are forwards/backwards
  79. compatible.
  80. </p>
  81. <p>
  82. Note that FOP does not currently support "tagged PDF", PDF/X or PDF/A-1a.
  83. <a href="pdfa.html">Support for PDF/A-1b</a> has recently been added, however.
  84. </p>
  85. <section id="pdf-fonts">
  86. <title>Fonts</title>
  87. <p>
  88. PDF has a set of fonts that are always available to all PDF viewers;
  89. to quote from the PDF Specification:
  90. <em>"PDF prescribes a set of 14 standard fonts that can be used without prior
  91. definition.
  92. These include four faces each of three Latin text typefaces (Courier,
  93. Helvetica, and Times), as well as two symbolic fonts (Symbol and ITC Zapf
  94. Dingbats). These fonts, or suitable substitute fonts with the same metrics, are
  95. guaranteed to be available in all PDF viewer applications."</em>
  96. </p>
  97. </section>
  98. <section id="pdf-postprocess">
  99. <title>Post-processing</title>
  100. <p>
  101. FOP does not currently support several desirable PDF features: XMP metadata and watermarks.
  102. One workaround is to use Adobe Acrobat (the full version, not the Reader) to process
  103. the file manually or with scripting that it supports.
  104. </p>
  105. <p>
  106. Another popular post-processing tool is <a href="http://www.lowagie.com/iText">iText</a>,
  107. which has tools for adding security features, document properties, watermarks, and many
  108. other features to PDF files.
  109. </p>
  110. <warning>
  111. Caveat: iText may swallow PDF bookmarks. But
  112. <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=37589">Jens Stavnstrup tells us</a>
  113. that this doesn't happen if you use iText's PDFStamper.
  114. </warning>
  115. <p>
  116. Here is some sample code that uses iText to encrypt a FOP-generated PDF. (Note that FOP now
  117. supports <a href="pdfencryption.html">PDF encryption</a>. However the principles for using
  118. iText for other PDF features are similar.)
  119. </p>
  120. <source><![CDATA[public static void main(String args[]) {
  121. try {
  122. ByteArrayOutputStream fopout = new ByteArrayOutputStream();
  123. FileOutputStream outfile = new FileOutputStream(args[2]);
  124. FopFactory fopFactory = FopFactory.newInstance();
  125. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, fopout);
  126. Transformer transformer = TransformerFactory.newInstance().newTransformer(
  127. new StreamSource(new File(args[1])));
  128. transformer.transform(new StreamSource(new File(args[0])),
  129. new SAXResult(fop.getDefaultHandler()));
  130. PdfReader reader = new PdfReader(fopout.toByteArray());
  131. int n = reader.getNumberOfPages();
  132. Document document = new Document(reader.getPageSizeWithRotation(1));
  133. PdfWriter writer = PdfWriter.getInstance(document, outfile);
  134. writer.setEncryption(PdfWriter.STRENGTH40BITS, "pdf", null,
  135. PdfWriter.AllowCopy);
  136. document.open();
  137. PdfContentByte cb = writer.getDirectContent();
  138. PdfImportedPage page;
  139. int rotation;
  140. int i = 0;
  141. while (i < n) {
  142. i++;
  143. document.setPageSize(reader.getPageSizeWithRotation(i));
  144. document.newPage();
  145. page = writer.getImportedPage(reader, i);
  146. rotation = reader.getPageRotation(i);
  147. if (rotation == 90 || rotation == 270) {
  148. cb.addTemplate(page, 0, -1f, 1f, 0, 0,
  149. reader.getPageSizeWithRotation(i).height());
  150. } else {
  151. cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
  152. }
  153. System.out.println("Processed page " + i);
  154. }
  155. document.close();
  156. } catch( Exception e) {
  157. e.printStackTrace();
  158. }
  159. }]]></source>
  160. <p>
  161. Check the iText tutorial and documentation for setting access flags, password,
  162. encryption strength and other parameters.
  163. </p>
  164. </section>
  165. <section id="pdf-watermark">
  166. <title>Watermarks</title>
  167. <p>
  168. In addition to the <a href="#pdf-postprocess">PDF Post-processing</a> options, consider the following workarounds:
  169. </p>
  170. <ul>
  171. <li>
  172. Use a background image for the body region.
  173. </li>
  174. <li>
  175. (submitted by Trevor Campbell) Place an image in a
  176. region that overlaps the flowing text. For example, make
  177. region-before large enough to contain your image. Then include a
  178. block (if necessary, use an absolutely positioned block-container)
  179. containing the watermark image in the static-content for the
  180. region-before. Note that the image will be drawn on top of the
  181. normal content.
  182. </li>
  183. </ul>
  184. </section>
  185. </section>
  186. <section id="ps">
  187. <title>PostScript</title>
  188. <p>
  189. The PostScript renderer has been brought up to a similar quality as the
  190. PDF renderer, but may still be missing certain features. It provides good
  191. support for most text and layout.
  192. Images and SVG are not fully supported, yet. Currently, the PostScript
  193. renderer generates PostScript Level 3 with most DSC comments. Actually,
  194. the only Level 3 feature used is FlateDecode, everything else is Level 2.
  195. </p>
  196. <section id="ps-limitations">
  197. <title>Limitations</title>
  198. <ul>
  199. <li>Images and SVG may not be displayed correctly. SVG support is far from being complete. No image transparency is available.</li>
  200. <li>Only Type 1 fonts are supported.</li>
  201. <li>Multibyte characters are not supported.</li>
  202. <li>PPD support is still missing.</li>
  203. </ul>
  204. </section>
  205. </section>
  206. <section id="rtf">
  207. <title>RTF</title>
  208. <p>
  209. JFOR, an open source XSL-FO to RTF converter has been integrated into Apache FOP.
  210. This will create an RTF (rich text format) document that will
  211. attempt to contain as much information from the fo document as
  212. possible. The RTF output follows Microsoft's RTF specifications
  213. and produces best results on Microsoft Word.
  214. </p>
  215. </section>
  216. <section id="xml">
  217. <title>XML (Area Tree XML)</title>
  218. <p>
  219. This is primarily for testing and verification. The XML created is simply
  220. a representation of the internal area tree put into XML. We use that to verify
  221. the functionality of FOP's layout engine.
  222. </p>
  223. <p>
  224. The other use case of the Area Tree XML is as FOP's "intermediate format". More information
  225. on that can be found on the page dedicated to the <a href="intermediate.html">Intermediate Format</a>.
  226. </p>
  227. </section>
  228. <section id="awt">
  229. <title>Java2D/AWT</title>
  230. <warning>The Java2D/AWT, Print and Bitmap renderers may not yet fully work as expected. There are some known bugs and missing features.</warning>
  231. <p>
  232. The AWT viewer shows a window with the pages displayed inside a
  233. Java graphic. It displays one page at a time.
  234. The fonts used for the formatting and viewing depend on the fonts
  235. available to your JRE.
  236. </p>
  237. </section>
  238. <section id="print">
  239. <title>Print</title>
  240. <p>
  241. It is possible to directly print the document from the command line.
  242. This is done with the same code that renders to the Java2D/AWT renderer.
  243. </p>
  244. </section>
  245. <section id="bitmap">
  246. <title>Bitmap (TIFF/PNG)</title>
  247. <p>
  248. It is possible to directly create bitmap images from the individual
  249. pages generated by the layout engine.
  250. This is done with the same code that renders to the Java2D/AWT renderer.
  251. </p>
  252. <p>
  253. Currently, two output formats are supported: PNG and TIFF. TIFF produces
  254. one file with multiple pages, while PNG output produces one file per
  255. page. The quality of the bitmap depends on the resolution setting on the
  256. FOUserAgent.
  257. </p>
  258. </section>
  259. <section id="txt">
  260. <title>TXT</title>
  261. <p>
  262. The text renderer produces plain ASCII text output
  263. that attempts to match the output of the PDFRenderer as closely as
  264. possible. This was originally developed to accommodate an archive system
  265. that could only accept plain text files, and is primarily useful for getting
  266. a quick-and-dirty view of the document text. The renderer is very limited,
  267. so do not be surprised if it gives unsatisfactory results.
  268. </p>
  269. <p>
  270. The Text renderer works with a fixed size page buffer. The size of this
  271. buffer is controlled with the textCPI and textLPI public variables.
  272. The textCPI is the effective horizontal characters per inch to use.
  273. The textLPI is the vertical lines per inch to use. From these values
  274. and the page width and height the size of the buffer is calculated.
  275. The formatting objects to be rendered are then mapped to this grid.
  276. Graphic elements (lines, borders, etc) are assigned a lower priority
  277. than text, so text will overwrite any graphic element representations.
  278. </p>
  279. <p>
  280. Because FOP lays the text onto a grid during layout, there are frequently
  281. extra or missing spaces between characters and lines, which is generally
  282. unsatisfactory.
  283. Users have reported that the optimal settings to avoid such spacing problems are:
  284. </p>
  285. <ul>
  286. <li>font-family="Courier"</li>
  287. <li>font-size="7.3pt"</li>
  288. <li>line-height="10.5pt"</li>
  289. </ul>
  290. </section>
  291. <section id="sandbox">
  292. <title>Output Formats in the Sandbox</title>
  293. <p>
  294. Due to the state of certain renderers we moved some of them to a "sandbox" area until
  295. they are ready for more serious use. The renderers and FOEventHandlers in the sandbox
  296. can be found under src/sandbox and are compiled into build/fop-sandbox.jar during the
  297. main build. The output formats in the sandbox are marked as such below.
  298. </p>
  299. <section id="pcl">
  300. <title>PCL</title>
  301. <warning>The PCL Renderer is in the sandbox and not yet functional in FOP Trunk!!! Please help us ressurrect this feature.</warning>
  302. <p>
  303. This format is for the Hewlett-Packard PCL printers.
  304. It should produce output as close to identical as possible to the
  305. printed output of the PDFRenderer within the limitations of the
  306. renderer, and output device.
  307. </p>
  308. <!--p>
  309. The output created by the PCLRenderer is generic PCL 5 as documented
  310. in the "HP PCL 5 Printer Language Technical Reference Manual" (copyright 1990).
  311. This should allow any device fully supporting PCL 5 to be able to
  312. print the output generated by the PCLRenderer.
  313. </p>
  314. <section id="pcl-limitations">
  315. <title>Limitations</title>
  316. <ul>
  317. <li>Text or graphics outside the left or top of the printable area are not rendered properly. In general things that should print to the left of the printable area are shifted to the right so that they start at the left edge of the printable area and an error message is generated.</li>
  318. <li>The Helvetica and Times fonts are not well supported among PCL printers so Helvetica is mapped to Arial and Times is mapped to Times New. This is done in the PCLRenderer, no changes are required in the FO's. The metrics and appearance for Helvetica/Arial and Times/Times New are nearly identical, so this has not been a problem so far.</li>
  319. <li>Only the original fonts built into FOP are supported.</li>
  320. <li>For the non-symbol fonts, the ISO 8859/1 symbol set is used (PCL set "0N").</li>
  321. <li>Multibyte characters are not supported.</li>
  322. <li>SVG is not supported.</li>
  323. <li>Images print black and white only (not dithered). When the renderer prints a color image it uses a threshold value, colors above the threshold are printed as white and below are black. If you need to print a non-monochrome image you should dither it first.</li>
  324. <li>Image scaling is accomplished by modifying the effective resolution of the image data. The available resolutions are 75, 100, 150, 300, and 600 DPI.</li>
  325. <li>Color printing is not supported. Colors are rendered by mapping the color intensity to one of the PCL fill shades (from white to black in 9 steps).</li>
  326. </ul>
  327. </section>
  328. <section id="pcl-additional">
  329. <title>Additional Features</title>
  330. <p>There are some special features that are controlled by some public variables on the PCLRenderer class.</p>
  331. <dl>
  332. <dt>orientation</dt>
  333. <dd>The logical page orientation is controlled by the public orientation variable. Legal values are:-->
  334. <!--ul>
  335. <li>0 Portrait</li>
  336. <li>1 Landscape</li>
  337. <li>2 Reverse Portrait</li>
  338. <li>3 Reverse Landscape</li>
  339. </ul-->
  340. <!--/dd>
  341. <dt>curdiv, paperheight</dt>
  342. <dd>The curdiv and paperheight variables allow multiple virtual pages to be printed on a piece of paper. This allows a standard laser printer to use perforated paper where every perforation will represent an individual page. The paperheight sets the height of a piece of paper in decipoints. This will be divided by the page.getHeight() to determine the number of equal sized divisions (pages) that will fit on the paper. The curdiv variable may be read/written to get/set the current division on the page (to set the starting division and read the ending division for multiple invocations).</dd>
  343. <dt>topmargin, leftmargin</dt>
  344. <dd>The topmargin and leftmargin may be used to increase the top and left margins for printing.</dd>
  345. </dl>
  346. </section-->
  347. </section>
  348. <section id="mif">
  349. <title>MIF</title>
  350. <warning>The MIF handler is in the sandbox and not yet functional in FOP Trunk!!! Please help us ressurrect this feature.</warning>
  351. <p>
  352. This format is the Maker Interchange Format which is used by
  353. Adobe Framemaker.
  354. </p>
  355. </section>
  356. <section id="svg">
  357. <title>SVG</title>
  358. <warning>The SVG renderer is in the sandbox and may not work as expected in FOP Trunk!!! Please help us improve this feature.</warning>
  359. <p>
  360. This format creates an SVG document that has links between the pages.
  361. This is primarily for slides and creating svg images of pages.
  362. Large documents will create SVG files that are far too large for
  363. an SVG viewer to handle. Since FO documents usually have text the
  364. SVG document will have a large number of text elements.
  365. The font information for the text is obtained from the JVM in the
  366. same way as for the AWT viewer. If the SVG is viewed on a
  367. system where the fonts are different, such as another platform,
  368. then the page may look wrong.
  369. </p>
  370. </section>
  371. </section>
  372. <section id="wishlist">
  373. <title>Wish list</title>
  374. <p>
  375. Apache FOP is easily extensible and allows you to add new output formats to enhance FOP's functionality. There's a number of output formats
  376. which are on our wish list. We're looking for volunteers to help us implement them.
  377. </p>
  378. <ul>
  379. <li>
  380. <a href="http://en.wikipedia.org/wiki/Advanced_Function_Presentation">AFP (Advanced Function Presentation)</a>:
  381. The renderer has already been built and is in the process of being brought into the Apache FOP codebase.
  382. </li>
  383. <li>
  384. <a href="http://en.wikipedia.org/wiki/OpenDocument">ODF (Open Document Format)</a>:
  385. The standardized successor to OpenOffice's file format.
  386. </li>
  387. </ul>
  388. </section>
  389. </body>
  390. </document>