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 Al Dancer <re...@yahoo.com> on 2009/04/21 11:29:49 UTC

FOP in servlet and configuration

Hello,

I'm running FOP 0.95 and Tomcat 6, OS : Solaris 10, java version "1.6.0_10"

How can I tell the FOP in Servlet to use my FOP configuration from file 
/opt/fop/conf/fop.xconf ?

When I run from web: http://localhost:8080/fop/fop?fo=/home/path/to/fofile.fo

I see the PDF document, but without my fonts (which are from my fop.xconf).
It seems, the FOP in servlet, didn't read the FOP config file at all.
When I run the fop from command line:
fop -c  /opt/fop/conf/fop.xconf -fo /home/path/to/fofile.fo -pdf /tmp/fofile.pdf
the created PDF file is with the correct fonts.

I read the FOP document about configuration file at:
http://xmlgraphics.apache.org/fop/0.94/embedding.html#config-external

But, in which script (java) should I add the following lines, so I can use FOP in servlet with
configuration ?
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
fopFactory.setUserConfig(new File("/opt/fop/conf/fop.xconf"));

Any help would be appreciated.

Al




      

Re: FOP in servlet and configuration

Posted by Sam Fuqua <sa...@gmail.com>.
Hi Al,

You need to put those lines in the Java file that contains your FopFactory.
The imports go at the top with the rest of your imports, and the
setUserConfig line needs to be inserted just after the FopFactory is
initialized, but before you use it to create another object.

Assuming you are still using some altered version of the ExampleFO2PDF
class, you'd need something like the following:
...
*import org.apache.avalon.framework.configuration.Configuration;
import
org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;*

public class ExampleFO2PDF {


    // configure fopFactory as desired
    private FopFactory fopFactory = FopFactory.newInstance();
    *fopFactory.setUserConfig(new File("/opt/fop/conf/fop.xconf"));*
    /**

     * Converts an FO file to a PDF file using FOP
     * @param fo the FO file
     * @param pdf the target PDF file
     * @throws IOException In case of an I/O problem
     * @throws FOPException In case of a FOP problem

     */
    public void convertFO2PDF(File fo, File pdf) throws IOException,
FOPException {
...

This of course assumes that your FopFactory is called fopFactory.  Hope that
helped!


On Tue, Apr 21, 2009 at 5:29 AM, Al Dancer <re...@yahoo.com> wrote:

>  Hello,
>
> I'm running FOP 0.95 and Tomcat 6, OS : Solaris 10, java version "1.6.0_10"
>
> How can I tell the FOP in Servlet to use my FOP configuration from file
> /opt/fop/conf/fop.xconf ?
>
> When I run from web:
> http://localhost:8080/fop/fop?fo=/home/path/to/fofile.fo
>
> I see the PDF document, but without my fonts (which are from my fop.xconf).
> It seems, the FOP in servlet, didn't read the FOP config file at all.
> When I run the fop from command line:
> fop -c /opt/fop/conf/fop.xconf -fo /home/path/to/fofile.fo -pdf
> /tmp/fofile.pdf
> the created PDF file is with the correct fonts.
>
> I read the FOP document about configuration file at:
> http://xmlgraphics.apache.org/fop/0.94/embedding.html#config-external
>
> But, in which script (java) should I add the following lines, so I can use
> FOP in servlet with
> configuration ?
>
> import org.apache.avalon.framework.configuration.Configuration;
> import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
>
> fopFactory.setUserConfig(new File("/opt/fop/conf/fop.xconf"));
>
> Any help would be appreciated.
>
> Al
>
>
>
>


-- 
Sam Fuqua
ΣΝ ΘΗ 454