You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by alex elsholz <al...@gmx.de> on 2003/02/05 20:22:14 UTC

Calculate number of pages without complete rendering-process was: Re: Counting the number of pages generated in the pdf file

Hi,

Check the FAQ for hints and caveats:
 http://xml.apache.org/fop/faq.html#faq-N10597

public static void main(String args[]) {
    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","#");
      transformer.transform(new StreamSource(new File(args[0])),

        new SAXResult(driver.getContentHandler()));

here i get a nullpointer, because first you must call driver.run.   

     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);
      transformer.transform(new StreamSource(new File(args[0])),
        new SAXResult(driver.getContentHandler()));
    }
    catch( Exception e) {
      e.printStackTrace();
    }
  }
}


but thats not what i want.

I'm looking for an solution to calculate the number of pages without the
complete rendering process.

The FOP library provides a method to get the total page count after a FO
document has been rendered. You can implement your own wrapper to do a dummy
rendering, inquire the total page count and the perform the real rendering

an own wrapper? why doesnt exists a default-wrapper? How could i implemet
this?

thanks alex

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Calculate number of pages without complete rendering-process was: Re: Counting the number of pages generated in the pdf file

Posted by "J.Pietschmann" <j3...@yahoo.de>.
alex elsholz wrote:
> but thats not what i want.
> 
> I'm looking for an solution to calculate the number of pages without the
> complete rendering process.

Great idea. If you tell me how to do it, I'll implement it.
Note: In general, you can't know how many pages a text fills
unless you actually filled the pages with the text.

> an own wrapper? why doesnt exists a default-wrapper? How could i implemet
> this?
I took the freedom to delete the code you generously pseudo-quoted
from the FAQ and which does exactly what you described.

J.Pietschmann


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org