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 Jonathan Spooner <sp...@gmail.com> on 2011/05/17 15:40:42 UTC

AWTRenderer With Intermediate Format

Hello,

Is it currently possible to render an intermediate format with the 
AWTRenderer?  I am using the intermediate format to concatenate pages as 
shown in the ExampleConcat.java example and I would like to be able to 
render the results to an AWTRenderer.

I've found a post in the archive that hinted at the capability 
(http://www.mail-archive.com/fop-users@xmlgraphics.apache.org/msg09528.html)  
but it does not work with FOP 1.0.

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


Re: AWTRenderer With Intermediate Format

Posted by Jonathan Spooner <sp...@gmail.com>.
Eric,

Thanks for your response.  I will try to answer all of your questions.  
Yes, I am using embedded code.  I am using the intermediate format to do 
simple 2-up imposition.  As for the code, I have used the 
ExampleConcat.java almost verbatim.  The only difference is that I've 
written a class (MyImposition) that wraps the document handler 
(IFDocumentHandler) which handles the rotation/translation/scaling for 
the imposition (using a custom IFParser (not shown)):

// From embedding.intermediate.ExampleConcat.java with my modifications
             FOUserAgent userAgent = fopFactory.newFOUserAgent();

             String mime = MimeConstants.MIME_PDF;
             IFDocumentHandler targetHandler = 
fopFactory.getRendererFactory().createDocumentHandler(
                     userAgent, mime);

             IFUtil.setupFonts(targetHandler);
             targetHandler.setResult(new StreamResult(pdffile));

             // MyImposition is where the custom IFParser lives
             MyImposition concatenator = new MyImposition(targetHandler, 
null);

             for (int i = 0; i < files.length; i++) {
                 Source src = new StreamSource(files[i]);
                 concatenator.appendDocument(src);
             }
             concatenator.finish();


In other parts of the application I use the AWTRenderer to show a print 
preview by basically the same method that is shown in 
ExampleAWTViewer.java except I am using AWTRender directly to fit it 
into a custom JFrame instead of using the default AWT_PREVIEW:

         AWTRenderer renderer = new AWTRenderer();
         FOUserAgent agent = fopFactory.newFOUserAgent();
         agent.setRendererOverride(renderer);

         // MyPrintPreviewDialog is a JFrame that implements 
org.apache.fop.render.awt.viewer.StatusListener
         MyPrintPreviewDialog dialog = 
MyPrintPreviewDialog.createDialog(agent, "Title");

         renderer.setStatusListener(dialog);
         renderer.setPreviewDialogDisplayed(false);
         renderer.setUserAgent(agent);
         renderer.clearViewportList();

         Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, agent);
         try {
             TransformerFactory factory = TransformerFactory.newInstance();
             Transformer transformer = factory.newTransformer();
             Source src = new StreamSource(fo);
             Result res = new SAXResult(fop.getDefaultHandler());
             transformer.transform(src, res);
         } catch (Exception e) {
         }

The problem that I'm having is understanding how to use AWTRenderer 
outside of the context of a Fop object.  This is all for a desktop 
application that is standalone so I don't have the ability to do 
anything on a server but thanks for the PNGRenderer tip, I'll be sure to 
keep this in mind for the future.


On 5/17/2011 7:30 AM, Eric Douglas wrote:
> Are you using embedded code?  Do you have a better description, any
> example, of what exactly you're trying to do?  Source code?  Test files?
> I'm sure this is possible but there are several ways to do it depending
> what exactly your goal is.
>
> I needed it to break up large reports because I kept running out of
> memory.  I just broke up my input to multiple jobs, setting an
> initial-page-number attribute under my fo:page-sequence.  I'm currently
> using the PDFRenderer and the PNGRenderer.  The PDFs create in memory
> and I merge them using pdfbox.  The PNGs are already in an array so I
> just add the next set of pages without resetting the array.
>
> Are you doing everything on one machine?  I tried using the AWTRenderer
> initially to create a print preview, but if you're able to transform on
> a server and display on a client as I am I think you'll find the
> PNGRenderer to be a much faster method as I did.
>
>
> -----Original Message-----
> From: Jonathan Spooner [mailto:spoonerj30@gmail.com]
> Sent: Tuesday, May 17, 2011 9:41 AM
> To: fop-users@xmlgraphics.apache.org
> Subject: AWTRenderer With Intermediate Format
>
> Hello,
>
> Is it currently possible to render an intermediate format with the
> AWTRenderer?  I am using the intermediate format to concatenate pages as
> shown in the ExampleConcat.java example and I would like to be able to
> render the results to an AWTRenderer.
>
> I've found a post in the archive that hinted at the capability
> (http://www.mail-archive.com/fop-users@xmlgraphics.apache.org/msg09528.h
> tml)
> but it does not work with FOP 1.0.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>

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


RE: AWTRenderer With Intermediate Format

Posted by Eric Douglas <ed...@blockhouse.com>.
Are you using embedded code?  Do you have a better description, any
example, of what exactly you're trying to do?  Source code?  Test files?
I'm sure this is possible but there are several ways to do it depending
what exactly your goal is.

I needed it to break up large reports because I kept running out of
memory.  I just broke up my input to multiple jobs, setting an
initial-page-number attribute under my fo:page-sequence.  I'm currently
using the PDFRenderer and the PNGRenderer.  The PDFs create in memory
and I merge them using pdfbox.  The PNGs are already in an array so I
just add the next set of pages without resetting the array.

Are you doing everything on one machine?  I tried using the AWTRenderer
initially to create a print preview, but if you're able to transform on
a server and display on a client as I am I think you'll find the
PNGRenderer to be a much faster method as I did.
 

-----Original Message-----
From: Jonathan Spooner [mailto:spoonerj30@gmail.com] 
Sent: Tuesday, May 17, 2011 9:41 AM
To: fop-users@xmlgraphics.apache.org
Subject: AWTRenderer With Intermediate Format

Hello,

Is it currently possible to render an intermediate format with the
AWTRenderer?  I am using the intermediate format to concatenate pages as
shown in the ExampleConcat.java example and I would like to be able to
render the results to an AWTRenderer.

I've found a post in the archive that hinted at the capability
(http://www.mail-archive.com/fop-users@xmlgraphics.apache.org/msg09528.h
tml)
but it does not work with FOP 1.0.

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


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