Browse Source

ApacheCon US is over.

OSSSummit was cancelled/postponed.
Added example for total page count using XSL 1.1
Adjusted total page count example to new FOP API. (Thanks to Miroslav Gregan for the hint)

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@596072 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_95beta
Jeremias Maerki 16 years ago
parent
commit
42efdd9b24
2 changed files with 51 additions and 35 deletions
  1. 51
    21
      src/documentation/content/xdocs/fo.xml
  2. 0
    14
      src/documentation/skinconf.xml

+ 51
- 21
src/documentation/content/xdocs/fo.xml View File

@@ -362,9 +362,14 @@ Omit your normal headers and footers, and use (for example) an extended header t
<section id="fo-total-pages">
<title>Total Document Pages</title>
<p>
It is frequently desirable to know the total number of pages in a document and to use that number within the document.
For example, you might wish to show the page number on the first page as being "page 1 of 12".
To accomplish this, place an empty block with an id at the end of the flow:
It is frequently desirable to know the total number of pages in a
document and to use that number within the document. For example, you
might wish to show the page number on the first page as being
"page 1 of 12".
</p>
<p>
To accomplish this in <strong>XSL 1.0</strong>, place an empty block
with an id at the end of the flow:
</p>
<source><![CDATA[<fo:flow ...>
...
@@ -373,10 +378,20 @@ To accomplish this, place an empty block with an id at the end of the flow:
<p>
Get the number of the last page as follows:
</p>
<source><![CDATA[ <fo:page-number-citation ref-id="last-page"/>]]></source>
<source><![CDATA[<fo:page-number-citation ref-id="last-page"/>]]></source>
<p>
This does not work in certain situations: multiple page sequences, an initial page number other than 1, or forcing a certain page count, thereby producing blank pages at the end.
</p>
<p>
In <strong>XSL 1.1</strong>, you get another option to do this: make
sure an "id" is set on the page-sequence and reference it using
fo:page-number-citation-last. First, the page-sequence:
</p>
<source><![CDATA[<fo:page-sequence id="seq1" ...]]></source>
<p>
After that, reference the last page the page-sequence generates:
</p>
<source><![CDATA[<fo:page-number-citation-last ref-id="seq1"/>]]></source>
<warning>
There is no reliable way to get the real total page count with FO mechanisms. You can only get <em>page numbers</em>.
</warning>
@@ -394,27 +409,42 @@ import javax.xml.transform.stream.*;

class rendtest {

private static FopFactory fopFactory = FopFactory.newInstance();
private static TransformerFactory tFactory = TransformerFactory.newInstance();

public static void main(String args[]) {
OutputStream out;
try {
Driver driver=new Driver();
driver.setOutputStream(new FileOutputStream(args[2]));
driver.setRenderer(Driver.RENDER_PDF);
Transformer transformer=TransformerFactory.newInstance()
.newTransformer(new StreamSource(new File(args[1])));
transformer.setParameter("page-count","#");
//Load the stylesheet
Templates templates = tFactory.newTemplates(
new StreamSource(new File(args[1])));

//First run (to /dev/null)
out = new org.apache.commons.io.output.NullOutputStream();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
Transformer transformer = templates.newTransformer();
transformer.setParameter("page-count", "#");
transformer.transform(new StreamSource(new File(args[0])),
new SAXResult(driver.getContentHandler()));
String pageCount=Integer.toString(driver.getResults().getPageCount());
driver=new Driver();
driver.setOutputStream(new FileOutputStream(args[2]));
driver.setRenderer(Driver.RENDER_PDF);
transformer=TransformerFactory.newInstance()
.newTransformer(new StreamSource(new File(args[1])));
transformer.setParameter("page-count",pageCount);
new SAXResult(fop.getDefaultHandler()));

//Get total page count
String pageCount = Integer.toString(driver.getResults().getPageCount());

//Second run (the real thing)
out = new java.io.FileOutputStream(args[2]);
out = new java.io.BufferedOutputStream(out);
try {
foUserAgent = fopFactory.newFOUserAgent();
fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
transformer = templates.newTransformer();
transformer.setParameter("page-count", pageCount);
transformer.transform(new StreamSource(new File(args[0])),
new SAXResult(driver.getContentHandler()));
}
catch( Exception e) {
new SAXResult(fop.getDefaultHandler()));
} finally {
out.close();
}
} catch( Exception e) {
e.printStackTrace();
}
}

+ 0
- 14
src/documentation/skinconf.xml View File

@@ -368,20 +368,6 @@ which will be used to configure the chosen Forrest skin.
<width>88</width>
<height>31</height>
</credit>
<credit box-location="alt2">
<name>ApacheCon US 2007 (Atlanta)</name>
<url>http://apachecon.com/2007/US/</url>
<image>http://www.apache.org/ads/ApacheCon/2007-usa-125x125.png</image>
<width>125</width>
<height>125</height>
</credit>
<credit box-location="alt2">
<name>OS Summit Asia 2007</name>
<url>http://www.ossummit.com/</url>
<image>http://www.ossummit.com/ads/ossummit_button_3.jpg</image>
<width>125</width>
<height>125</height>
</credit>
<credit box-location="alt2">
<name>ApacheCon Europe 2008</name>
<url>http://eu.apachecon.com/</url>

Loading…
Cancel
Save