選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

intermediate.xml 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- $Id$ -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
  18. <document>
  19. <header>
  20. <title>Intermediate Format</title>
  21. <version>$Revision$</version>
  22. </header>
  23. <body>
  24. <note>
  25. Please note that the intermediate format is an <strong>advanced feature</strong> and can be ignored by most
  26. users of Apache FOP.
  27. </note>
  28. <section id="introduction">
  29. <title>Introduction</title>
  30. <p>
  31. The intermediate format (IF) is a proprietary XML format that represents the area tree
  32. generated by the layout engine. The area tree is conceptually defined in the
  33. <a href="http://www.w3.org/TR/2001/REC-xsl-20011015/slice1.html#section-N742-Formatting">XSL-FO specification in chapter 1.1.2</a>.
  34. The IF can be generated through the area tree XML Renderer (the XMLRenderer).
  35. </p>
  36. <p>
  37. The intermediate format can be used to generate intermediate documents that are modified
  38. before they are finally rendered to their ultimate output format. Modifications include
  39. adjusting and changing trait values, adding or modifying area objects, inserting prefabricated
  40. pages, overlays, imposition (n-up, rotation, scaling etc.). Multiple IF files can be combined
  41. to a single output file.
  42. </p>
  43. </section>
  44. <section id="usage">
  45. <title>Usage of the Intermediate Format</title>
  46. <p>
  47. As already mentioned, the IF is generated by using the <strong>XMLRenderer</strong> (MIME type:
  48. <strong>application/X-fop-areatree</strong>). So, you basically set the right MIME type for
  49. the output format and process your FO files as if you would create a PDF file. However, there
  50. is an important detail to consider: The various Renderers don't all use the same font sources.
  51. To be able to create the right area tree for the ultimate output file, you need to create
  52. the IF file using the right font setup. This is achieved by telling the XMLRenderer to mimic
  53. another renderer. This is done by calling the XMLRenderer's mimicRenderer() method with an
  54. instance of the ultimate target renderer as the single parameter. This has a consequence: An
  55. IF file rendered with the Java2DRenderer may not look as expected when it was actually generated
  56. for the PDF renderer. For renderers that use the same font setup, this restriction does not
  57. apply (PDF and PS, for example). Generating the intermediate format file is the first step.
  58. </p>
  59. <p>
  60. The second step is to reparse the IF file using the <strong>AreaTreeParser</strong> which is
  61. found in the org.apache.fop.area package. The pages retrieved from the IF file are added to an
  62. AreaTreeModel instance from where they are normally rendered using one of the available Renderer
  63. implementations. You can find examples for the IF processing in the
  64. <a href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/"><code>examples/embedding</code></a>
  65. directory in the FOP distribution
  66. </p>
  67. <p>
  68. The basic pattern to parse the IF format looks like this:
  69. </p>
  70. <source><![CDATA[
  71. FopFactory fopFactory = FopFactory.newInstance();
  72. // Setup output
  73. OutputStream out = new java.io.FileOutputStream(pdffile);
  74. out = new java.io.BufferedOutputStream(out);
  75. try {
  76. //Setup fonts and user agent
  77. FontInfo fontInfo = new FontInfo();
  78. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  79. //Construct the AreaTreeModel that will received the individual pages
  80. AreaTreeModel treeModel = new RenderPagesModel(userAgent,
  81. MimeConstants.MIME_PDF, fontInfo, out);
  82. //Parse the IF file into the area tree
  83. AreaTreeParser parser = new AreaTreeParser();
  84. Source src = new StreamSource(myIFFile);
  85. parser.parse(src, treeModel, userAgent);
  86. //Signal the end of the processing. The renderer can finalize the target document.
  87. treeModel.endDocument();
  88. } finally {
  89. out.close();
  90. }]]></source>
  91. <p>
  92. This example simply reads an IF file and renders it to a PDF file. Please note, that in normal
  93. FOP operation you're shielded from having to instantiate the FontInfo object yourself. This
  94. is normally a task of the AreaTreeHandler which is not present in this scenario. The same
  95. applies to the AreaTreeModel instance, in this case an instance of a subclass called
  96. RenderPagesModel. RenderPagesModel is ideal in this case as it has very little overhead
  97. processing the individual pages. An important line in the example is the call to
  98. <code>endDocument()</code> on the AreaTreeModel. This lets the Renderer know that the processing
  99. is now finished.
  100. </p>
  101. <p>
  102. The intermediate format can also be used from the <a href="running.html#standalone-start">command-line</a>
  103. by using the "-atin" parameter for specifying the area tree XML as input file. You can also
  104. specify a "mimic renderer" by inserting a MIME type between "-at" and the output file.
  105. </p>
  106. <section id="concat">
  107. <title>Concatenating Documents</title>
  108. <p>
  109. This initial example is obviously not very useful. It would be faster to create the PDF file
  110. directly. As the <a href="http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleConcat.java">ExampleConcat.java</a>
  111. example shows you can easily parse multiple IF files in a row and add the parsed pages to the
  112. same AreaTreeModel instance which essentially concatenates all the input document to one single
  113. output document.
  114. </p>
  115. </section>
  116. <section id="modifying">
  117. <title>Modifying Documents</title>
  118. <p>
  119. One of the most important use cases for the intermediate format is obviously modifying the area
  120. tree XML before finally rendering it to the target format. You can easily use XSLT to process
  121. the IF file according to your needs. Please note, that we will currently not formally describe
  122. the intermediate format. You need to have a good understanding its structure so you don't
  123. create any non-parseable files. We may add an XML Schema and more detailed documentation at a
  124. later time. You're invited to help us with that.
  125. </p>
  126. </section>
  127. <section id="advanced">
  128. <title>Advanced Use</title>
  129. <p>
  130. The generation of the intermediate format as well as it parsing process has been designed to allow
  131. for maximum flexibility and optimization. Please note that you can call <code>setTransformerHandler()</code> on
  132. XMLRenderer to give the XMLRenderer your own TransformerHandler instance in case you would like to
  133. do custom serialization (to a W3C DOM, for example) and/or to directly modify the area tree using
  134. XSLT. The AreaTreeParser on the other side allows you to retrieve a ContentHandler instance where
  135. you can manually send SAX events to to start the parsing process (see <code>getContentHandler()</code>).
  136. </p>
  137. </section>
  138. </section>
  139. </body>
  140. </document>