xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r840710 - in /websites/staging/xmlgraphics/trunk/content: ./ fop/fo.html
Date Tue, 04 Dec 2012 13:17:53 GMT
Author: buildbot
Date: Tue Dec  4 13:17:52 2012
New Revision: 840710

Log:
Staging update by buildbot for xmlgraphics

Modified:
    websites/staging/xmlgraphics/trunk/content/   (props changed)
    websites/staging/xmlgraphics/trunk/content/fop/fo.html

Propchange: websites/staging/xmlgraphics/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Dec  4 13:17:52 2012
@@ -1 +1 @@
-1416834
+1416923

Modified: websites/staging/xmlgraphics/trunk/content/fop/fo.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/fop/fo.html (original)
+++ websites/staging/xmlgraphics/trunk/content/fop/fo.html Tue Dec  4 13:17:52 2012
@@ -610,57 +610,105 @@ Getting your XML correctly encoded is on
 
 
 <p>The FOP library provides a method to get the total page count after an FO document
has been rendered. One possibility is to implement your own wrapper to do a dummy rendering,
inquire the total page count and then perform the real rendering, passing the total page count
to the XSLT processor to splice it into the generated FO. For example:</p>
-<div class="codehilite"><pre><span class="nb">import</span> <span
class="n">org</span><span class="o">.</span><span class="n">apache</span><span
class="o">.</span><span class="n">fop</span><span class="o">.</span><span
class="n">apps</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span
class="o">.</span><span class="n">xml</span><span class="o">.</span><span
class="n">sax</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span
class="o">.</span><span class="n">io</span><span class="o">.*</span><span
class="p">;</span>
-<span class="nb">import</span> <span class="n">javax</span><span
class="o">.</span><span class="n">xml</span><span class="o">.</span><span
class="n">transform</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">javax</span><span
class="o">.</span><span class="n">xml</span><span class="o">.</span><span
class="n">transform</span><span class="o">.</span><span class="n">sax</span><span
class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">javax</span><span
class="o">.</span><span class="n">xml</span><span class="o">.</span><span
class="n">transform</span><span class="o">.</span><span class="n">stream</span><span
class="o">.*</span><span class="p">;</span>
-
-<span class="n">class</span> <span class="n">rendtest</span> <span
class="p">{</span>
-
-  <span class="n">private</span> <span class="n">static</span> <span
class="n">FopFactory</span> <span class="n">fopFactory</span> <span
class="o">=</span> <span class="n">FopFactory</span><span class="o">.</span><span
class="n">newInstance</span><span class="p">();</span>
-  <span class="n">private</span> <span class="n">static</span> <span
class="n">TransformerFactory</span> <span class="n">tFactory</span> <span
class="o">=</span> <span class="n">TransformerFactory</span><span
class="o">.</span><span class="n">newInstance</span><span class="p">();</span>
-
-  <span class="n">public</span> <span class="n">static</span> <span
class="n">void</span> <span class="n">main</span><span class="p">(</span><span
class="n">String</span> <span class="n">args</span><span class="o">[]</span><span
class="p">)</span> <span class="p">{</span>
-    <span class="n">OutputStream</span> <span class="n">out</span><span
class="p">;</span>
-    <span class="n">try</span> <span class="p">{</span>
-      <span class="sr">//</span><span class="n">Load</span> <span
class="n">the</span> <span class="n">stylesheet</span>
-      <span class="n">Templates</span> <span class="n">templates</span>
<span class="o">=</span> <span class="n">tFactory</span><span class="o">.</span><span
class="n">newTemplates</span><span class="p">(</span>
-          <span class="k">new</span> <span class="n">StreamSource</span><span
class="p">(</span><span class="k">new</span> <span class="n">File</span><span
class="p">(</span><span class="n">args</span><span class="p">[</span><span
class="mi">1</span><span class="p">])));</span>
-
-      <span class="sr">//</span><span class="n">First</span> <span
class="n">run</span> <span class="p">(</span><span class="n">to</span>
<span class="sr">/dev/</span><span class="n">null</span><span class="p">)</span>
-      <span class="n">out</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">org</span><span class="o">.</span><span
class="n">apache</span><span class="o">.</span><span class="n">commons</span><span
class="o">.</span><span class="n">io</span><span class="o">.</span><span
class="n">output</span><span class="o">.</span><span class="n">NullOutputStream</span><span
class="p">();</span>
-      <span class="n">FOUserAgent</span> <span class="n">foUserAgent</span>
<span class="o">=</span> <span class="n">fopFactory</span><span
class="o">.</span><span class="n">newFOUserAgent</span><span class="p">();</span>
-      <span class="n">Fop</span> <span class="n">fop</span> <span
class="o">=</span> <span class="n">fopFactory</span><span class="o">.</span><span
class="n">newFop</span><span class="p">(</span><span class="n">MimeConstants</span><span
class="o">.</span><span class="n">MIME_PDF</span><span class="p">,</span>
<span class="n">foUserAgent</span><span class="p">,</span> <span
class="n">out</span><span class="p">);</span>
-      <span class="n">Transformer</span> <span class="n">transformer</span>
<span class="o">=</span> <span class="n">templates</span><span
class="o">.</span><span class="n">newTransformer</span><span class="p">();</span>
-      <span class="n">transformer</span><span class="o">.</span><span
class="n">setParameter</span><span class="p">(</span><span class="s">&quot;page-count&quot;</span><span
class="p">,</span> <span class="s">&quot;#&quot;</span><span
class="p">);</span>
-      <span class="n">transformer</span><span class="o">.</span><span
class="n">transform</span><span class="p">(</span><span class="k">new</span>
<span class="n">StreamSource</span><span class="p">(</span><span
class="k">new</span> <span class="n">File</span><span class="p">(</span><span
class="n">args</span><span class="p">[</span><span class="mi">0</span><span
class="p">])),</span>
-          <span class="k">new</span> <span class="n">SAXResult</span><span
class="p">(</span><span class="n">fop</span><span class="o">.</span><span
class="n">getDefaultHandler</span><span class="p">()));</span>
-
-      <span class="sr">//</span><span class="n">Get</span> <span
class="n">total</span> <span class="n">page</span> <span class="n">count</span>
-      <span class="n">String</span> <span class="n">pageCount</span>
<span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span
class="n">toString</span><span class="p">(</span><span class="n">driver</span><span
class="o">.</span><span class="n">getResults</span><span class="p">()</span><span
class="o">.</span><span class="n">getPageCount</span><span class="p">());</span>
-
-      <span class="sr">//</span><span class="n">Second</span> <span
class="n">run</span> <span class="p">(</span><span class="n">the</span>
<span class="n">real</span> <span class="n">thing</span><span class="p">)</span>
-      <span class="n">out</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">java</span><span class="o">.</span><span
class="n">io</span><span class="o">.</span><span class="n">FileOutputStream</span><span
class="p">(</span><span class="n">args</span><span class="p">[</span><span
class="mi">2</span><span class="p">]);</span>
-      <span class="n">out</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">java</span><span class="o">.</span><span
class="n">io</span><span class="o">.</span><span class="n">BufferedOutputStream</span><span
class="p">(</span><span class="n">out</span><span class="p">);</span>
-      <span class="n">try</span> <span class="p">{</span>
-      <span class="n">foUserAgent</span> <span class="o">=</span>
<span class="n">fopFactory</span><span class="o">.</span><span
class="n">newFOUserAgent</span><span class="p">();</span>
-      <span class="n">fop</span> <span class="o">=</span> <span
class="n">fopFactory</span><span class="o">.</span><span class="n">newFop</span><span
class="p">(</span><span class="n">MimeConstants</span><span class="o">.</span><span
class="n">MIME_PDF</span><span class="p">,</span> <span class="n">foUserAgent</span><span
class="p">,</span> <span class="n">out</span><span class="p">);</span>
-      <span class="n">transformer</span> <span class="o">=</span>
<span class="n">templates</span><span class="o">.</span><span class="n">newTransformer</span><span
class="p">();</span>
-      <span class="n">transformer</span><span class="o">.</span><span
class="n">setParameter</span><span class="p">(</span><span class="s">&quot;page-count&quot;</span><span
class="p">,</span> <span class="n">pageCount</span><span class="p">);</span>
-      <span class="n">transformer</span><span class="o">.</span><span
class="n">transform</span><span class="p">(</span><span class="k">new</span>
<span class="n">StreamSource</span><span class="p">(</span><span
class="k">new</span> <span class="n">File</span><span class="p">(</span><span
class="n">args</span><span class="p">[</span><span class="mi">0</span><span
class="p">])),</span>
-          <span class="k">new</span> <span class="n">SAXResult</span><span
class="p">(</span><span class="n">fop</span><span class="o">.</span><span
class="n">getDefaultHandler</span><span class="p">()));</span>
-      <span class="p">}</span> <span class="n">finally</span> <span
class="p">{</span>
-        <span class="n">out</span><span class="o">.</span><span
class="nb">close</span><span class="p">();</span>
-      <span class="p">}</span>
-    <span class="p">}</span> <span class="n">catch</span><span
class="p">(</span> <span class="n">Exception</span> <span class="n">e</span><span
class="p">)</span> <span class="p">{</span>
-      <span class="n">e</span><span class="o">.</span><span class="n">printStackTrace</span><span
class="p">();</span>
-    <span class="p">}</span>
-  <span class="p">}</span>
-<span class="p">}</span>
+<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>
1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49</pre></div></td><td class="code"><div class="codehilite"><pre><span
class="kn">import</span> <span class="nn">org.apache.fop.apps.*</span><span
class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.xml.sax.*</span><span
class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.io.*</span><span
class="o">;</span>
+<span class="kn">import</span> <span class="nn">javax.xml.transform.*</span><span
class="o">;</span>
+<span class="kn">import</span> <span class="nn">javax.xml.transform.sax.*</span><span
class="o">;</span>
+<span class="kn">import</span> <span class="nn">javax.xml.transform.stream.*</span><span
class="o">;</span>
+
+<span class="kd">class</span> <span class="nc">rendtest</span> <span
class="o">{</span>
+
+  <span class="kd">private</span> <span class="kd">static</span>
<span class="n">FopFactory</span> <span class="n">fopFactory</span>
<span class="o">=</span> <span class="n">FopFactory</span><span
class="o">.</span><span class="na">newInstance</span><span class="o">();</span>
+  <span class="kd">private</span> <span class="kd">static</span>
<span class="n">TransformerFactory</span> <span class="n">tFactory</span>
<span class="o">=</span> <span class="n">TransformerFactory</span><span
class="o">.</span><span class="na">newInstance</span><span class="o">();</span>
+
+  <span class="kd">public</span> <span class="kd">static</span> <span
class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span
class="n">String</span> <span class="n">args</span><span class="o">[])</span>
<span class="o">{</span>
+    <span class="n">OutputStream</span> <span class="n">out</span><span
class="o">;</span>
+    <span class="k">try</span> <span class="o">{</span>
+      <span class="c1">//Load the stylesheet</span>
+      <span class="n">Templates</span> <span class="n">templates</span>
<span class="o">=</span> <span class="n">tFactory</span><span class="o">.</span><span
class="na">newTemplates</span><span class="o">(</span>
+          <span class="k">new</span> <span class="nf">StreamSource</span><span
class="o">(</span><span class="k">new</span> <span class="n">File</span><span
class="o">(</span><span class="n">args</span><span class="o">[</span><span
class="mi">1</span><span class="o">])));</span>
+
+      <span class="c1">//First run (to /dev/null)</span>
+      <span class="n">out</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">org</span><span class="o">.</span><span
class="na">apache</span><span class="o">.</span><span class="na">commons</span><span
class="o">.</span><span class="na">io</span><span class="o">.</span><span
class="na">output</span><span class="o">.</span><span class="na">NullOutputStream</span><span
class="o">();</span>
+      <span class="n">FOUserAgent</span> <span class="n">foUserAgent</span>
<span class="o">=</span> <span class="n">fopFactory</span><span
class="o">.</span><span class="na">newFOUserAgent</span><span class="o">();</span>
+      <span class="n">Fop</span> <span class="n">fop</span> <span
class="o">=</span> <span class="n">fopFactory</span><span class="o">.</span><span
class="na">newFop</span><span class="o">(</span><span class="n">MimeConstants</span><span
class="o">.</span><span class="na">MIME_PDF</span><span class="o">,</span>
<span class="n">foUserAgent</span><span class="o">,</span> <span
class="n">out</span><span class="o">);</span>
+      <span class="n">Transformer</span> <span class="n">transformer</span>
<span class="o">=</span> <span class="n">templates</span><span
class="o">.</span><span class="na">newTransformer</span><span class="o">();</span>
+      <span class="n">transformer</span><span class="o">.</span><span
class="na">setParameter</span><span class="o">(</span><span class="s">&quot;page-count&quot;</span><span
class="o">,</span> <span class="s">&quot;#&quot;</span><span
class="o">);</span>
+      <span class="n">transformer</span><span class="o">.</span><span
class="na">transform</span><span class="o">(</span><span class="k">new</span>
<span class="n">StreamSource</span><span class="o">(</span><span
class="k">new</span> <span class="n">File</span><span class="o">(</span><span
class="n">args</span><span class="o">[</span><span class="mi">0</span><span
class="o">])),</span>
+          <span class="k">new</span> <span class="nf">SAXResult</span><span
class="o">(</span><span class="n">fop</span><span class="o">.</span><span
class="na">getDefaultHandler</span><span class="o">()));</span>
+
+      <span class="c1">//Get total page count</span>
+      <span class="n">String</span> <span class="n">pageCount</span>
<span class="o">=</span> <span class="n">Integer</span><span class="o">.</span><span
class="na">toString</span><span class="o">(</span><span class="n">driver</span><span
class="o">.</span><span class="na">getResults</span><span class="o">().</span><span
class="na">getPageCount</span><span class="o">());</span>
+
+      <span class="c1">//Second run (the real thing)</span>
+      <span class="n">out</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">java</span><span class="o">.</span><span
class="na">io</span><span class="o">.</span><span class="na">FileOutputStream</span><span
class="o">(</span><span class="n">args</span><span class="o">[</span><span
class="mi">2</span><span class="o">]);</span>
+      <span class="n">out</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">java</span><span class="o">.</span><span
class="na">io</span><span class="o">.</span><span class="na">BufferedOutputStream</span><span
class="o">(</span><span class="n">out</span><span class="o">);</span>
+      <span class="k">try</span> <span class="o">{</span>
+      <span class="n">foUserAgent</span> <span class="o">=</span>
<span class="n">fopFactory</span><span class="o">.</span><span
class="na">newFOUserAgent</span><span class="o">();</span>
+      <span class="n">fop</span> <span class="o">=</span> <span
class="n">fopFactory</span><span class="o">.</span><span class="na">newFop</span><span
class="o">(</span><span class="n">MimeConstants</span><span class="o">.</span><span
class="na">MIME_PDF</span><span class="o">,</span> <span class="n">foUserAgent</span><span
class="o">,</span> <span class="n">out</span><span class="o">);</span>
+      <span class="n">transformer</span> <span class="o">=</span>
<span class="n">templates</span><span class="o">.</span><span class="na">newTransformer</span><span
class="o">();</span>
+      <span class="n">transformer</span><span class="o">.</span><span
class="na">setParameter</span><span class="o">(</span><span class="s">&quot;page-count&quot;</span><span
class="o">,</span> <span class="n">pageCount</span><span class="o">);</span>
+      <span class="n">transformer</span><span class="o">.</span><span
class="na">transform</span><span class="o">(</span><span class="k">new</span>
<span class="n">StreamSource</span><span class="o">(</span><span
class="k">new</span> <span class="n">File</span><span class="o">(</span><span
class="n">args</span><span class="o">[</span><span class="mi">0</span><span
class="o">])),</span>
+          <span class="k">new</span> <span class="nf">SAXResult</span><span
class="o">(</span><span class="n">fop</span><span class="o">.</span><span
class="na">getDefaultHandler</span><span class="o">()));</span>
+      <span class="o">}</span> <span class="k">finally</span> <span
class="o">{</span>
+        <span class="n">out</span><span class="o">.</span><span
class="na">close</span><span class="o">();</span>
+      <span class="o">}</span>
+    <span class="o">}</span> <span class="k">catch</span><span
class="o">(</span> <span class="n">Exception</span> <span class="n">e</span><span
class="o">)</span> <span class="o">{</span>
+      <span class="n">e</span><span class="o">.</span><span class="na">printStackTrace</span><span
class="o">();</span>
+    <span class="o">}</span>
+  <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
-
+</td></tr></table>
 
 <p>Declare and use the parameter "page-count" in your XSLT.</p>
 <p><warning>It is possible to run into a convergence problem with this solution.
Replacing the "#" placeholder in the first run with the actual page count in the second run,
may change the total number of pages in the document.</warning></p>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message