xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <...@jeremias-maerki.ch>
Subject Re: HowTo export several pages to PNG-format
Date Tue, 31 Mar 2009 08:33:23 GMT
If you set up a user agent, you can set the output file in addition to
the output stream. That way, the PNG renderer will be able to create
additional files in the same location for the pages > 1.

File outputFile = new File(path + ".png") 

FOUserAgent ua = fopFactory.newUserAgent();
ua.setOutputFile(outputFile);

Fop fop = fopFactory.newFop(MimeConstants.MIME_PNG, ua, output);

Of course, that doesn't give you much control over how the various files
are produced but it might be enough for your case. If you need more
control over the output files, you need to subclass
org.apache.fop.render.bitmap.PNGRenderer and override
getCurrentOutputStream(int). If you do that you need to construct the
renderer yourself and pass it into FOP through
FOUserAgent.setRendererOverride(Renderer).

HTH


On 31.03.2009 10:16:08 Leopard2A5 wrote:
> 
> Hello!
> 
> I've searched the mailing lists and the docs but i somehow couldn't find
> help.
> I'm using fop to generate PDFs in my web-application, but i also need
> preview-pictures to display via HTML.
> Generating PDFs via FOP works great, but i can't manage to get more than the
> first page as a preview.
> 
> Here's my code:
> 
> private int getImagesFromPDF(String path, Reader stylesheet) throws
> Exception
>     {
>         FileOutputStream output = new FileOutputStream(path + ".png");
>         
>         //Instantiate FOP
>         FopFactory fopFactory = FopFactory.newInstance();
>         fopFactory.setSourceResolution(96);
>         fopFactory.setBaseURL(VISITE_BASE_PATH);
>         try
>         {
>             fopFactory.setUserConfig(VISITE_BASE_PATH + "fop_config2.xml");
>         } 
>         catch (SAXException e)
>         {
>             e.printStackTrace();
>         }
>         
>         Fop fop = fopFactory.newFop(MimeConstants.MIME_PNG, output);
>             
>         TransformerFactory factory = TransformerFactory.newInstance();
>         Transformer transformer = factory.newTransformer();
> 
>         // get the right input format for conversion
>         Source style = new StreamSource(stylesheet);
>         Result res = new SAXResult(fop.getDefaultHandler());
> 
>         // Step 6: Start XSLT transformation and FOP processing
>         transformer.transform(style, res);
> 
>         return 0;
>     }
> 
> and my fop_config-file:
> 
> <fop version="1.0">
>   <renderers>
>    <renderer mime="image/png">
>       <fonts>
>         <!-- register a particular font -->
>         
>           <font-triplet name="Georgia" style="normal" weight="normal"/>
>         
>         
>           <font-triplet name="Georgia" style="normal" weight="bold"/>
>         
>         
>           <font-triplet name="Georgia" style="italic" weight="normal"/>
>         
>         
>           <font-triplet name="Georgia" style="italic" weight="bold"/>
>         
>       </fonts>
>    </renderer>
> </renderers>
> 
> </fop>
> 
> Any help would be appreciated!
> Thx in advance!
> -- 
> View this message in context: http://www.nabble.com/HowTo-export-several-pages-to-PNG-format-tp22800402p22800402.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 
> 


Jeremias Maerki


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


Mime
View raw message