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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?xml version="1.0" standalone="no"?>
  2. <!--
  3. Copyright 1999-2005 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 OutputStream (out) to the PCLRenderer and it happily sends the
  67. 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.
  83. </p>
  84. <section id="pdf-fonts">
  85. <title>Fonts</title>
  86. <p>
  87. PDF has a set of fonts that are always available to all PDF viewers,
  88. to quote from the PDF Specification:
  89. <em>"PDF prescribes a set of 14 standard fonts that can be used without prior
  90. definition.
  91. These include four faces each of three Latin text typefaces (Courier,
  92. Helvetica, and Times), as well as two symbolic fonts (Symbol and ITC Zapf
  93. Dingbats). These fonts, or suitable substitute fonts with the same metrics, are
  94. guaranteed to be available in all PDF viewer applications."</em>
  95. </p>
  96. </section>
  97. <section id="pdf-postprocess">
  98. <title>Post-processing</title>
  99. <p>
  100. FOP does not currently support several desirable PDF features: XMP metadata and watermarks.
  101. One workaround is to use Adobe Acrobat (the full version, not the Reader) to process
  102. the file manually or with scripting that it supports.
  103. </p>
  104. <p>
  105. Another popular post-processing tool is <a href="http://www.lowagie.com/iText">iText</a>,
  106. which has tools for adding security features, document properties, watermarks, and many
  107. other features to PDF files.
  108. </p>
  109. <warning>
  110. Caveat: iText may swallow PDF bookmarks. But
  111. <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=37589">Jens Stavnstrup tells us</a>
  112. that this doesn't happen if you use iText's PDFStamper.
  113. </warning>
  114. <p>
  115. Here is some sample code that uses iText to encrypt a FOP-generated PDF. (Note that FOP now
  116. supports <a href="pdfencryption.html">PDF encryption</a>. However the principles for using
  117. iText for other PDF features are similar.)
  118. </p>
  119. <source><![CDATA[public static void main(String args[]) {
  120. try {
  121. ByteArrayOutputStream fopout = new ByteArrayOutputStream();
  122. FileOutputStream outfile = new FileOutputStream(args[2]);
  123. Fop fop = new Fop(Constants.RENDER_PDF);
  124. fop.setOutputStream(fopout);
  125. Transformer transformer = TransformerFactory.newInstance().newTransformer(
  126. new StreamSource(new File(args[1])));
  127. transformer.transform(new StreamSource(new File(args[0])),
  128. new SAXResult(fop.getDefaultHandler()));
  129. PdfReader reader = new PdfReader(fopout.toByteArray());
  130. int n = reader.getNumberOfPages();
  131. Document document = new Document(reader.getPageSizeWithRotation(1));
  132. PdfWriter writer = PdfWriter.getInstance(document, outfile);
  133. writer.setEncryption(PdfWriter.STRENGTH40BITS, "pdf", null,
  134. PdfWriter.AllowCopy);
  135. document.open();
  136. PdfContentByte cb = writer.getDirectContent();
  137. PdfImportedPage page;
  138. int rotation;
  139. int i = 0;
  140. while (i < n) {
  141. i++;
  142. document.setPageSize(reader.getPageSizeWithRotation(i));
  143. document.newPage();
  144. page = writer.getImportedPage(reader, i);
  145. rotation = reader.getPageRotation(i);
  146. if (rotation == 90 || rotation == 270) {
  147. cb.addTemplate(page, 0, -1f, 1f, 0, 0,
  148. reader.getPageSizeWithRotation(i).height());
  149. } else {
  150. cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
  151. }
  152. System.out.println("Processed page " + i);
  153. }
  154. document.close();
  155. } catch( Exception e) {
  156. e.printStackTrace();
  157. }
  158. }]]></source>
  159. <p>
  160. Check the iText tutorial and documentation for setting access flags, password,
  161. encryption strength and other parameters.
  162. </p>
  163. </section>
  164. <section id="pdf-watermark">
  165. <title>Watermarks</title>
  166. <p>
  167. In addition to the <a href="#pdf-postprocess">PDF Post-processing</a> options, consider the following workarounds:
  168. </p>
  169. <ul>
  170. <li>
  171. Use a background image for the body region.
  172. </li>
  173. <li>
  174. (submitted by Trevor Campbell) Place an image in a
  175. region that overlaps the flowing text. For example, make
  176. region-before large enough to contain your image. Then include a
  177. block (if necessary, use an absolutely positioned block-container)
  178. containing the watermark image in the static-content for the
  179. region-before. Note that the image will be drawn on top of the
  180. normal content.
  181. </li>
  182. </ul>
  183. </section>
  184. </section>
  185. <section id="ps">
  186. <title>PostScript</title>
  187. <p>
  188. The PostScript renderer has been brought up to a similar quality as the
  189. PDF renderer, but may still be missing certain features. It provides good
  190. support for most text and layout.
  191. Images and SVG are not fully supported, yet. Currently, the PostScript
  192. renderer generates PostScript Level 3 with most DSC comments. Actually,
  193. the only Level 3 feature used is FlateDecode, everything else is Level 2.
  194. </p>
  195. <section id="ps-limitations">
  196. <title>Limitations</title>
  197. <ul>
  198. <li>Images and SVG may not be display correctly. SVG support is far from being complete. No image transparency is available.</li>
  199. <li>Only Type 1 fonts are supported.</li>
  200. <li>Multibyte characters are not supported.</li>
  201. <li>PPD support is still missing.</li>
  202. <li>The renderer is not yet configurable.</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 for testing and verification. The XML created is simply
  220. a representation of the internal area tree put into XML. It does
  221. not perform any other purpose.
  222. </p>
  223. </section>
  224. <section id="awt">
  225. <title>Java2D/AWT</title>
  226. <warning>The Java2D/AWT, Print and Bitmap renderers may not yet fully work as expected. There are some known bugs and missing features.</warning>
  227. <p>
  228. The AWT viewer shows a window with the pages displayed inside a
  229. Java graphic. It displays one page at a time.
  230. The fonts used for the formatting and viewing depend on the fonts
  231. available to your JRE.
  232. </p>
  233. </section>
  234. <section id="print">
  235. <title>Print</title>
  236. <p>
  237. It is possible to directly print the document from the command line.
  238. This is done with the same code that renders to the Java2D/AWT renderer.
  239. </p>
  240. </section>
  241. <section id="bitmap">
  242. <title>Bitmap (TIFF/PNG)</title>
  243. <p>
  244. It is possible to directly create bitmap images from the individual
  245. pages generated by the layout engine.
  246. This is done with the same code that renders to the Java2D/AWT renderer.
  247. </p>
  248. <p>
  249. Currently, two output formats are supported: PNG and TIFF. TIFF produces
  250. one file with multiple pages, while PNG output produces one file per
  251. page. The quality of the bitmap depends on the resolution setting on the
  252. FOUserAgent.
  253. </p>
  254. </section>
  255. <section id="txt">
  256. <title>TXT</title>
  257. <p>
  258. The text renderer produces plain ASCII text output
  259. that attempts to match the output of the PDFRenderer as closely as
  260. possible. This was originally developed to accommodate an archive system
  261. that could only accept plain text files, and is primarily useful for getting
  262. a quick-and-dirty view of the document text. The renderer is very limited,
  263. so do not be surprised if it gives unsatisfactory results.
  264. </p>
  265. <p>
  266. The Text renderer works with a fixed size page buffer. The size of this
  267. buffer is controlled with the textCPI and textLPI public variables.
  268. The textCPI is the effective horizontal characters per inch to use.
  269. The textLPI is the vertical lines per inch to use. From these values
  270. and the page width and height the size of the buffer is calculated.
  271. The formatting objects to be rendered are then mapped to this grid.
  272. Graphic elements (lines, borders, etc) are assigned a lower priority
  273. than text, so text will overwrite any graphic element representations.
  274. </p>
  275. <p>
  276. Because FOP lays the text onto a grid during layout, there are frequently
  277. extra or missing spaces between characters and lines, which is generally
  278. unsatisfactory.
  279. Users have reported that the optimal settings to avoid such spacing problems are:
  280. </p>
  281. <ul>
  282. <li>font-family="Courier"</li>
  283. <li>font-size="7.3pt"</li>
  284. <li>line-height="10.5pt"</li>
  285. </ul>
  286. </section>
  287. <section id="sandbox">
  288. <title>Output Formats in the Sandbox</title>
  289. <p>
  290. Due to the state of certain renderers we moved some of them to a "sandbox" area until
  291. they are ready for more serious use. The renderers and FOEventHandlers in the sandbox
  292. can be found under src/sandbox and are compiled into build/fop-sandbox.jar during the
  293. main build. The output formats in the sandbox are marked as such below.
  294. </p>
  295. <section id="pcl">
  296. <title>PCL</title>
  297. <warning>The PCL Renderer is in the sandbox and not yet functional in FOP Trunk!!! Please help us ressurrect this feature.</warning>
  298. <p>
  299. This format is for the Hewlett-Packard PCL printers.
  300. It should produce output as close to identical as possible to the
  301. printed output of the PDFRenderer within the limitations of the
  302. renderer, and output device.
  303. </p>
  304. <!--p>
  305. The output created by the PCLRenderer is generic PCL 5 as documented
  306. in the "HP PCL 5 Printer Language Technical Reference Manual" (copyright 1990).
  307. This should allow any device fully supporting PCL 5 to be able to
  308. print the output generated by the PCLRenderer.
  309. </p>
  310. <section id="pcl-limitations">
  311. <title>Limitations</title>
  312. <ul>
  313. <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>
  314. <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>
  315. <li>Only the original fonts built into FOP are supported.</li>
  316. <li>For the non-symbol fonts, the ISO 8859/1 symbol set is used (PCL set "0N").</li>
  317. <li>Multibyte characters are not supported.</li>
  318. <li>SVG is not supported.</li>
  319. <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>
  320. <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>
  321. <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>
  322. </ul>
  323. </section>
  324. <section id="pcl-additional">
  325. <title>Additional Features</title>
  326. <p>There are some special features that are controlled by some public variables on the PCLRenderer class.</p>
  327. <dl>
  328. <dt>orientation</dt>
  329. <dd>The logical page orientation is controlled by the public orientation variable. Legal values are:-->
  330. <!--ul>
  331. <li>0 Portrait</li>
  332. <li>1 Landscape</li>
  333. <li>2 Reverse Portrait</li>
  334. <li>3 Reverse Landscape</li>
  335. </ul-->
  336. <!--/dd>
  337. <dt>curdiv, paperheight</dt>
  338. <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>
  339. <dt>topmargin, leftmargin</dt>
  340. <dd>The topmargin and leftmargin may be used to increase the top and left margins for printing.</dd>
  341. </dl>
  342. </section-->
  343. </section>
  344. <section id="mif">
  345. <title>MIF</title>
  346. <warning>The MIF handler is in the sandbox and not yet functional in FOP Trunk!!! Please help us ressurrect this feature.</warning>
  347. <p>
  348. This format is the Maker Interchange Format which is used by
  349. Adobe Framemaker.
  350. </p>
  351. </section>
  352. <section id="svg">
  353. <title>SVG</title>
  354. <warning>The SVG renderer is in the sandbox and may not work as expected in FOP Trunk!!! Please help us improve this feature.</warning>
  355. <p>
  356. This format creates an SVG document that has links between the pages.
  357. This is primarily for slides and creating svg images of pages.
  358. Large documents will create SVG files that are far too large for
  359. and SVG viewer to handle. Since FO documents usually have text the
  360. SVG document will have a large number of text elements.
  361. The font information for the text is obtained from the JVM in the
  362. same way as the AWT viewer, if the SVG is view where the fonts are
  363. different, such as another platform, then the page may appear wrong.
  364. </p>
  365. </section>
  366. </section>
  367. </body>
  368. </document>