[xep-support] Question: get the number of page of the PDF file rendered byXEP
Nikolai Grigoriev
grig at renderx.com
Wed Feb 6 12:34:56 PST 2002
Daniel,
> We are currently using the version 2.7 of XEP in a Java application
> to render XML files to PDF files at WIPO.
>
> Is there any possibility to get the number of pages of the result files,
> rather than writing our own event Logger to count the pages ?
No, we don't have any method of getting the number of pages in a single
Java call. You can count them programmatically in two ways:
- either catch respective Logger events,
- or, intercept pages as they are passed from the formatter to PDF/PS generator.
Both logger and generator implement standard SAX interfaces, so
the procedure is similar in all cases. Here's a class that inserts
itself between the formatter and the generator, and counts pages:
public class MyPDFProducer extends com.renderx.FO2PDF.T.H4PDFJ {
private int pageCount = 0;
public int getPageCount() { return pageCount; };
public void startElement(String name,
org.xml.sax.AttributeList attrs)
throws org.xml.sax.SAXException {
if ("page".equals(name)) pageCount++;
super.startElement(name, attrs);
}
}
In your rendering call, substitute MyPDFProducer to H4PDFJ.
After rendering, the number of pages actually passed to the formatter
will be stored inside the producer instance; retrieve it with
getPageCount() method.
Hope this helps.
Best regards,
Nikolai Grigoriev
RenderX
-------------------
By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/tos.html
More information about the Xep-support
mailing list