Karl, thanks for the heads-up. One comment on your Java class: To
improve performance you should reuse the FopFactory and the
TransformerFactory instead of constructing them each time.

See also: http://xmlgraphics.apache.org/fop/trunk/embedding.html#basics

On 19.04.2006 02:09:24 Karl Roberts wrote:
> Hi Jeremias,
> 
> FYI
> I've now had time to try the latest FOP trunk and patch it into my code
> (instead of my workaround) and I can confirm the the URL resolving
> issues when deploying FOP in a webapp so that URL's can be relative to
> the ServletContext are gone when using the ServletContextURIResolver and
> the FopFactory helper methods to set it up.
> External graphics url's in the xsl-fo file are resolved OK (when the URL
> scheme is servlet-context: )
> And all references to the font "metrics-url" and "embed-url" in the
> fopconfig xml are also resolved OK (again using the servlet-context:
> scheme)
> 
> Thanks for all your help, it's a pleasure to use such an activly
> maintained piece of software like FOP.
> 
> Cheers
> 
> Karl
> 
> PS for anyone wondering what this thread is about see the following code
> snippets and config xml to see how to use the ServletContextURIResolver
> to resolve URL's in XSL-FO and FOP config file relative to a web
> applications ServletContext.
> 
> // code snippet .......
> public void PDFDocumentGenerator(InputSource fopconfigInputSource,
> ServletContext context, Source xmlSrc, Source xslSrc){
> 
>       //Set up stuff from fop config file if it exists                
>       if(fopconfigInputSource!=null)
>       {
>         try{
>               DefaultConfigurationBuilder cfgBuilder = new
> DefaultConfigurationBuilder();                                
>               Configuration cfg =
> cfgBuilder.build(this.fopconfigInputSource);
>               FopFactory ff =FopFactory.newInstance();
>               ff.setUserConfig(cfg);
>               FOUserAgent userAgent=ff.newFOUserAgent();
>               //If ServletContext is not null then add
> ServletContextURIResolver
>               // incase URI's in the config file and xsl-fo input are
> special ones that are relative to servlet-context:
>               if(context!=null)
>               {
>                       ff.setURIResolver(new
> ServletContextURIResolver(context));
>               }
>               ByteArrayOutputStream out = new ByteArrayOutputStream();
>               // Construct fop with desired output format
> 
>               Fop fop = ff.newFop(MimeConstants.MIME_PDF,
> userAgent,out);
> 
>               // Setup XSLT if exists// if not then we are assuming
> src is already in xsl-fo format
>               TransformerFactory factory =
> TransformerFactory.newInstance();
>               Transformer transformer;
>               if(xslSource!=null)
>               {
>                       transformer = factory.newTransformer(xslSrc);
>               }
>               else
>               {
>                       transformer = factory.newTransformer();
>               }                               
>               // Resulting SAX events (the generated FO) must be piped
> through
>               // to FOP
>               Result res = new SAXResult(fop.getDefaultHandler());    
>               // Start XSLT transformation and FOP processing
>               transformer.transform(xmlSrc, res);
> 
>               //got here so no transform exceptions now deal with the
> output collect as byte array (or just stream it somewhere)
>               byte[] theBytes= out.toByteArray();
>               .....etc....
>               }catch(Exception e)
>          { ....deal with it ...}
>       }
> }
> 
> // fopconfig.xml using url's with servlet-context scheme
> <fop version="1.0">
> <!-- Base URL for resolving relative URLs -->
> <base>./</base>
> <source-resolution>72</source-resolution>
> <target-resolution>72</target-resolution>
> <!-- ie A4 -->
> <default-page-settings height="29.7cm" width="21cm"/>
> <renderers>
>   <renderer mime="application/pdf">
>     <filterList>
>      <value>flate</value>
>     </filterList>
>     <fonts>
>      <font metrics-url="servlet-context:///WEB-INF/Arial.xml"
> kerning="no" embed-url="servlet-context:///WEB-INF/arial.ttf" >
>       <font-triplet name="Arial" style="normal" weight="normal"/>
>       <font-triplet name="ArialMT" style="normal" weight="normal"/>
>      </font>
>      <font metrics-url="servlet-context:///WEB-INF/ArialBd.xml"
> kerning="no" embed-url="servlet-context:///WEB-INF/arialbd.ttf" >
>       <font-triplet name="Arial" style="normal" weight="bold"/>
>        <font-triplet name="ArialMT" style="normal" weight="bold"/>
>      </font>  
>     </fonts>
>   </renderer>
> </renderers>
> </fop>
<snip/>


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to