Yes, CachedRenderPagesModel lies around unused but it still works.
Here's some (uncleaned) example code that shows how to use it.

public class AreaTreeTests {

    private static class MyAreaTreeHandler extends AreaTreeHandler {

        public MyAreaTreeHandler(FOUserAgent userAgent, String outputFormat,
                OutputStream stream) throws FOPException {
            super(userAgent, outputFormat, stream);

        protected void setupModel(FOUserAgent userAgent, String outputFormat, 
OutputStream stream) throws FOPException {
            //super.setupModel(userAgent, outputFormat, stream);
            this.model = new CachedRenderPagesModel(userAgent, outputFormat, 


    private static void doit() throws Exception {
        FopFactory fopFactory = FopFactory.newInstance();
        fopFactory.setUserConfig(new File("C:/Dev/FOP/main/userconfig.xml"));

        final int maxRepeats = 100;
        for (int repeat = 0; repeat < maxRepeats; repeat++) {
            FOUserAgent ua = fopFactory.newFOUserAgent();
            //String outputFormat = MimeConstants.MIME_FOP_AREA_TREE;
            //outputFormat = MimeConstants.MIME_PDF;
            String outputFormat = MimeConstants.MIME_POSTSCRIPT;

            //File foFile = new 
            File foFile = new File("C:/Dev/FOP/temp/");
            //File outFile = new File("D:/");
            File outFile = new File("D:/");

            OutputStream out = new FileOutputStream(outFile);
            out = new BufferedOutputStream(out);
            try {
                Fop fop = fopFactory.newFop(outputFormat, ua, out);

                AreaTreeHandler atHandler = new MyAreaTreeHandler(ua, 
outputFormat, out);

                TransformerFactory tf = TransformerFactory.newInstance();
                Transformer transformer = tf.newTransformer();
                Source src = new StreamSource(foFile);
                Result res = new SAXResult(fop.getDefaultHandler());
                transformer.transform(src, res);
            } finally {


    public static void main(String[] args) {
        try {
        } catch (Exception e) {


This should allow you to do a few experiments.

At any rate, this approach may help in certain situations (such as many
small page-sequences). But in situation with large page-sequences, it
won't help as the layout engine can't process the FO tree while it is
built and because finished FOs are not released before the page-sequence
is finished. Have fun.

On 17.09.2008 18:16:15 Dario Laera wrote:
> Hi all,
> in fop documentation site there are at least two page that talk about  
> memory caching on disk for page that contains unresolved forward  
> references: 
>   and 
> areas.html#caching . I was thinking that this was just a nice idea not  
> implemented yet: my tests with hundreds of single page page-sequences  
> was often ending in OutOfMemory due to the "Page X of Y" block in the  
> footer. But looking at the code in FOP trunk I found the class  
> CachedRenderPagesModel that seems to do that caching; unfortunately  
> this class is never instantiated.
> Was this class intended for unresolved forward reference issue? What  
> is missing for having this kind of caching working? Is someone working  
> on it?
> Thanks in advances
> Dario

Jeremias Maerki

Reply via email to