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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?xml version="1.0" standalone="no"?>
  2. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN"
  3. "http://cvs.apache.org/viewcvs.cgi/*checkout*/xml-forrest/src/resources/schema/dtd/document-v11.dtd">
  4. <!-- Output Formats: Renderers -->
  5. <document>
  6. <header>
  7. <title>FOP Output Options</title>
  8. <authors>
  9. <person name="Keiron Liddle" email="keiron@aftexsw.com"/>
  10. <person name="Art Welch" email=""/>
  11. </authors>
  12. </header>
  13. <body>
  14. <p>
  15. FOP supports multiple output formats by using a different renderer for each format.
  16. The renderers do not all have the same set of capabilities, sometimes because of the output format itself, sometimes because some renderers get more development attention than others.
  17. </p>
  18. <section id="general">
  19. <title>General Information</title>
  20. <section id="general-fonts">
  21. <title>Fonts</title>
  22. <p>
  23. Most FOP renderers use a FOP-specific system for font registration.
  24. However, the AWT and print renderers use the java awt package, which gets its font information from the operating system registration.
  25. This can result in several differences, including actually using different fonts, and having different font metrics for the same font.
  26. The net effect is that the layout of a given FO document can be quite different between renderers that do not use the same font information.
  27. </p>
  28. </section>
  29. <section id="general-direct-output">
  30. <title>Output to a Printer or Other Device</title>
  31. <p>
  32. The most obvious way to print your document is to use the FOP <link href="#print">print renderer</link>, which uses the Java API (AWT).
  33. However, you can also send output from the Postscript renderer directly to a Postscript device, or output from the PCL renderer directly to a PCL device.
  34. </p>
  35. <p>
  36. Here are Windows command-line examples for Postscript and PCL:
  37. </p>
  38. <source><![CDATA[fop ... -ps \\computername\printer]]></source>
  39. <source><![CDATA[fop ... -pcl \\computername\printer]]></source>
  40. <p>
  41. Here is some Java code to accomplish the task in UNIX:
  42. </p>
  43. <source><![CDATA[proc = Runtime.getRuntime().exec("lp -d" + print_queue + " -o -dp -");
  44. out = proc.getOutputStream();]]></source>
  45. <p>
  46. Set the OutputStream (out) to the PCLRenderer and it happily sends the
  47. PCL to the UNIX printer queue.
  48. </p>
  49. </section>
  50. </section>
  51. <section id="pdf">
  52. <title>PDF</title>
  53. <p>
  54. PDF is the best supported output format. It is also the most accurate
  55. with text and layout. This creates a PDF document that is streamed out
  56. as each page is rendered. This means that the internal page index
  57. information is stored near the end of the document.
  58. The PDF version supported is 1.3 which is currently the most popular
  59. version for Acrobat Reader (4.0), PDF versions are forwards/backwards
  60. compatible.
  61. </p>
  62. <p>Note that FOP does not currently support "tagged pdf".</p>
  63. <section id="pdf-fonts">
  64. <title>Fonts</title>
  65. <p>
  66. PDF has a set of fonts that are always available to all PDF viewers,
  67. to quote from the PDF Specification:
  68. <em>"PDF prescribes a set of 14 standard fonts that can be used without prior
  69. definition.
  70. These include four faces each of three Latin text typefaces (Courier,
  71. Helvetica, and Times), as well as two symbolic fonts (Symbol and ITC Zapf
  72. Dingbats). These fonts, or suitable substitute fonts with the same metrics, are
  73. guaranteed to be available in all PDF viewer applications."</em>
  74. </p>
  75. </section>
  76. <section id="pdf-postprocess">
  77. <title>Post-processing</title>
  78. <p>FOP does not currently support several desirable PDF features: document properties (title, author, etc.), and watermarks. One workaround is to use Adobe Acrobat (the full version, not the Reader) to process the file manually or with scripting that it supports.</p>
  79. <p>Another popular post-processing tool is <link href="http://www.lowagie.com/iText">iText</link>, which has tools for adding security features, document properties, watermarks, and many other features to PDF files.
  80. </p>
  81. <warning>Caveat: iText swallows PDF bookmarks.</warning>
  82. <p>Here is some sample code that uses iText to encrypt a FOP-generated PDF. (Note that FOP now supports <link href="pdfencryption.html">PDF encryption</link>. However the principles for using iText for other PDF features are similar.)</p>
  83. <source><![CDATA[public static void main(String args[]) {
  84. try {
  85. ByteArrayOutputStream fopout=new ByteArrayOutputStream();
  86. FileOutputStream outfile=new FileOutputStream(args[2]);
  87. Driver driver =new Driver();
  88. driver.setOutputStream(fopout);
  89. driver.setRenderer(Driver.RENDER_PDF);
  90. Transformer transformer=TransformerFactory
  91. .newInstance().newTransformer(new StreamSource(new File(args[1])));
  92. transformer.transform(new StreamSource(new File(args[0])),
  93. new SAXResult(driver.getContentHandler()));
  94. PdfReader reader = new PdfReader(fopout.toByteArray());
  95. int n = reader.getNumberOfPages();
  96. Document document = new Document(reader.getPageSizeWithRotation(1));
  97. PdfWriter writer = PdfWriter.getInstance(document, outfile);
  98. writer.setEncryption(PdfWriter.STRENGTH40BITS, "pdf", null,
  99. PdfWriter.AllowCopy);
  100. document.open();
  101. PdfContentByte cb = writer.getDirectContent();
  102. PdfImportedPage page;
  103. int rotation;
  104. int i = 0;
  105. while (i < n) {
  106. i++;
  107. document.setPageSize(reader.getPageSizeWithRotation(i));
  108. document.newPage();
  109. page = writer.getImportedPage(reader, i);
  110. rotation = reader.getPageRotation(i);
  111. if (rotation == 90 || rotation == 270) {
  112. cb.addTemplate(page, 0, -1f, 1f, 0, 0,
  113. reader.getPageSizeWithRotation(i).height()); }
  114. else {
  115. cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
  116. }
  117. System.out.println("Processed page " + i);
  118. }
  119. document.close();
  120. }
  121. catch( Exception e) {
  122. e.printStackTrace();
  123. }
  124. }]]></source>
  125. <p>Check the iText tutorial and documentation for setting access flags, password, encryption strength and other parameters.
  126. </p>
  127. </section>
  128. <section id="pdf-watermark">
  129. <title>Watermarks</title>
  130. <p>
  131. In addition to the <link href="#pdf-postprocess">PDF Post-processing</link> options, consider the following workarounds:
  132. </p>
  133. <ul>
  134. <li>
  135. Use a background image for the body region.
  136. </li>
  137. <li>
  138. (submitted by Trevor_Campbell@kaz.com.au) Place an image in a
  139. region that overlaps the flowing text. For example, make
  140. region-before large enough to contain your image. Then include a
  141. block (if necessary, use an absolutely positioned block-container)
  142. containing the watermark image in the static-content for the
  143. region-before. Note that the image will be drawn on top of the
  144. normal content.
  145. </li>
  146. </ul>
  147. </section>
  148. </section>
  149. <section id="pcl">
  150. <title>PCL</title>
  151. <p>
  152. This format is for the Hewlett-Packard PCL printers.
  153. It should produce output as close to identical as possible to the
  154. printed output of the PDFRenderer within the limitations of the
  155. renderer, and output device.
  156. </p>
  157. <p>
  158. The output created by the PCLRenderer is generic PCL 5 as documented
  159. in the "HP PCL 5 Printer Language Technical Reference Manual" (copyright 1990).
  160. This should allow any device fully supporting PCL 5 to be able to
  161. print the output generated by the PCLRenderer.
  162. </p>
  163. <section id="pcl-limitations">
  164. <title>Limitations</title>
  165. <ul>
  166. <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>
  167. <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>
  168. <li>Only the original fonts built into FOP are supported.</li>
  169. <li>For the non-symbol fonts, the ISO 8859/1 symbol set is used (PCL set "0N").</li>
  170. <li>Multibyte characters are not supported.</li>
  171. <li>SVG support is limited. Currently only lines, rectangles (may be rounded), circles, ellipses, text, simple paths, and images are supported. Colors are supported (dithered black and white) but not gradients.</li>
  172. <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>
  173. <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>
  174. <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>
  175. <li>SVG clipping is not supported.</li>
  176. </ul>
  177. </section>
  178. <section id="pcl-additional">
  179. <title>Additional Features</title>
  180. <p>There are some special features that are controlled by some public variables on the PCLRenderer class.</p>
  181. <dl>
  182. <dt>orientation</dt>
  183. <dd>The logical page orientation is controlled by the public orientation variable. Legal values are:
  184. <!--ul>
  185. <li>0 Portrait</li>
  186. <li>1 Landscape</li>
  187. <li>2 Reverse Portrait</li>
  188. <li>3 Reverse Landscape</li>
  189. </ul-->
  190. </dd>
  191. <dt>curdiv, paperheight</dt>
  192. <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>
  193. <dt>topmargin, leftmargin</dt>
  194. <dd>The topmargin and leftmargin may be used to increase the top and left margins for printing.</dd>
  195. </dl>
  196. </section>
  197. </section>
  198. <section id="ps">
  199. <title>PostScript</title>
  200. <p>
  201. The PostScript renderer is still in its early stages and therefore still
  202. missing some features. It provides good support for most text and layout.
  203. Images and SVG are not fully supported, yet. Currently, the PostScript
  204. renderer generates PostScript Level 3 with most DSC comments. Actually,
  205. the only Level 3 feature used is FlateDecode, everthing else is Level 2.
  206. </p>
  207. <section id="ps-limitations">
  208. <title>Limitations</title>
  209. <ul>
  210. <li>Images and SVG may not be display correctly. SVG support is far from being complete. No image transparency is available.</li>
  211. <li>Character spacing may be wrong.</li>
  212. <li>No font embedding is supported.</li>
  213. <li>Multibyte characters are not supported.</li>
  214. <li>PPD support is still missing.</li>
  215. <li>The renderer is not yet configurable.</li>
  216. </ul>
  217. </section>
  218. </section>
  219. <section id="rtf">
  220. <title>RTF</title>
  221. <p>
  222. This is currently not integrated with FOP but it will soon.
  223. This will create an rtf (rich text format) document that will
  224. attempt to contain as much information from the fo document as
  225. possible.
  226. </p>
  227. </section>
  228. <section id="svg">
  229. <title>SVG</title>
  230. <p>
  231. This format creates an SVG document that has links between the pages.
  232. This is primarily for slides and creating svg images of pages.
  233. Large documents will create SVG files that are far too large for
  234. and SVG viewer to handle. Since fo documents usually have text the
  235. SVG document will have a large number of text elements.
  236. The font information for the text is obtained from the jvm in the
  237. same way as the AWT viewer, if the svg is view where the fonts are
  238. different, such as another platform, then the page will appear wrong.
  239. </p>
  240. </section>
  241. <section id="xml">
  242. <title>XML</title>
  243. <p>
  244. This is for testing and verification. The XML created is simply
  245. a representation of the internal area tree put into XML. It does
  246. not perform any other purpose.
  247. </p>
  248. </section>
  249. <section id="print">
  250. <title>Print</title>
  251. <p>
  252. It is possible to directly print the document from the command line.
  253. This is done with the same code that renders to the AWT renderer.
  254. </p>
  255. </section>
  256. <section id="awt">
  257. <title>AWT</title>
  258. <p>
  259. The AWT viewer shows a window with the pages displayed inside a
  260. java graphic. It displays one page at a time.
  261. The fonts used for the formatting and viewing depend on the fonts
  262. available to your JRE.
  263. </p>
  264. </section>
  265. <section id="mif">
  266. <title>MIF</title>
  267. <p>
  268. This format is the Maker Interchange Format which is used by
  269. Adobe Framemaker. This is currently not fully implemented.
  270. </p>
  271. </section>
  272. <section id="txt">
  273. <title>TXT</title>
  274. <p>
  275. The text renderer produces plain ASCII text output
  276. that attempts to match the output of the PDFRenderer as closely as
  277. possible. This was originally developed to accommodate an archive system
  278. that could only accept plain text files, and is primarily useful for getting
  279. a quick-and-dirty view of the document text. The renderer is very limited,
  280. so do not be surprised if it gives unsatisfactory results.
  281. </p>
  282. <p>
  283. The Text renderer works with a fixed size page buffer. The size of this
  284. buffer is controlled with the textCPI and textLPI public variables.
  285. The textCPI is the effective horizontal characters per inch to use.
  286. The textLPI is the vertical lines per inch to use. From these values
  287. and the page width and height the size of the buffer is calculated.
  288. The formatting objects to be rendered are then mapped to this grid.
  289. Graphic elements (lines, borders, etc) are assigned a lower priority
  290. than text, so text will overwrite any graphic element representations.
  291. </p>
  292. <p>Because FOP lays the text onto a grid during layout, there are frequently extra or missing spaces between characters and lines, which is generally unsatisfactory.
  293. Users have reported that the optimal settings to avoid such spacing problems are:</p>
  294. <ul>
  295. <li>font-family="Courier"</li>
  296. <li>font-size="7.3pt"</li>
  297. <li>line-height="10.5pt"</li>
  298. </ul>
  299. </section>
  300. </body>
  301. </document>