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 Gregory Buchenberger <gr...@eightfoldconsulting.com> on 2009/12/16 19:19:39 UTC

Relative path to font directory

I'm embedding FOP version 627324 (trunk) in a Java application and am
trying to register a font directory using the configuration file and
the method fopFactory.setFontBaseURL(). The font directory is in the
same parent directory as the jar file. The jar file directory
basically looks like this (using indentation to represent folder
hierarchy) :

MyJar.jar
conf/
    fopconf.xml
xml/
    xslt/
        mystylesheet.xsl
        includes/
lib/
    fop.jar
fonts/
    dejavu-ttf-2.30/
        DejaVuSans.ttf

The file conf/fopconf.xml contains the following:

<?xml version="1.0"?>
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <directory recursive="true">./fonts</directory>
      </fonts>
    </renderer>
  </renderers>
</fop>

The class in my Java code that interacts with FOP contains this:

public class XMLConverter {

    private Logger logger = Logger.getLogger(this.getClass().getName());
    private File xmlFile;
    private File xsltFile;
    private FopFactory fopFactory;

     public XMLConverter(File xmlfile, File xsltfile) {
        this.xmlFile = xmlfile;
        this.xsltFile = xsltfile;
        initFopFactory();
    }

     private void initFopFactory() {
        try {
            File jarFile = new File
(MainFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath().toString());
            String jarDir = jarFile.getParent();
            String xmlDir = xmlFile.getParent();
            this.fopFactory = FopFactory.newInstance();
            fopFactory.setUserConfig(new File(jarDir, "conf/fopconf.xml"));
            fopFactory.setFontBaseURL("file:///"+jarDir);
            fopFactory.setBaseURL("file:///"+xmlDir);
        } catch (Exception ex) {
            logger.severe(ex.getMessage());
        }
    }

..........

The setUserConfig() and setBaseURL() methods seem to work as expected.
I've tried using the following to my FOP configuration file as well.

<font-base>../</font-base>

The only way I can get it to work is by using an absolute path in the
config , like so:

<?xml version="1.0"?>
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <directory
recursive="true">/home/greg/NetBeansProjects/NIMAS2PDF/dist/fonts</directory>
      </fonts>
    </renderer>
  </renderers>
</fop>

Have any of you any idea what stupid thing I am doing wrong here?
While it's possible to obtain an absolute path via interaction with
the user, I would prefer to store at least a base set of fonts within
the jar directory that is installed with the application.

Kind Regards,

Gregory Buchenberger

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


Re: Relative path to font directory

Posted by Gregory Buchenberger <gr...@eightfoldconsulting.com>.
Thanks for your reply. I've tried that. It sort-of works because my Java
project is in my home folder. In other words, <font-base>./</font-base>
points to /home/greg (I'm on linux). I've set FOP to look for fonts
recursively and so it finds them there. However, if I move the
application somewhere else with the font folder out of my home directory
it fails to find the fonts. What's odd is that the behavior is different
on Windows Vista. Can anyone shed some light on the issue? I would like
my app to be portable. How can I make my font base the application
folder?

fopFactory.setUserConfig(new File(jarDir, "conf/fopconf.xml")) works
just fine but fopFactory.setFontBaseURL("file:///"+jarDir); doesn't.

On Thu, 2009-12-17 at 12:07 +0000, Venkat Reddy wrote:
> Hi,
> 
> Have you tried the following?
> 
> <!-- Base URL for resolving relative URLs -->
> <base>./</base>
> <!-- Font Base URL for resolving relative font URLs -->
> <font-base>./</font-base>
> 
> Source:
> http://xmlgraphics.apache.org/fop/trunk/configuration.html#general-elements
> 
> Thanks,
> Venkat.
> 
> 
> 
> Gregory Buchenberger wrote:
> > I'm embedding FOP version 627324 (trunk) in a Java application and
> am
> > trying to register a font directory using the configuration file and
> > the method fopFactory.setFontBaseURL(). The font directory is in the
> > same parent directory as the jar file. The jar file directory
> > basically looks like this (using indentation to represent folder
> > hierarchy) :
> >
> > MyJar.jar
> > conf/
> >     fopconf.xml
> > xml/
> >     xslt/
> >         mystylesheet.xsl
> >         includes/
> > lib/
> >     fop.jar
> > fonts/
> >     dejavu-ttf-2.30/
> >         DejaVuSans.ttf
> >
> > The file conf/fopconf.xml contains the following:
> >
> > <?xml version="1.0"?>
> > <fop version="1.0">
> >   <renderers>
> >     <renderer mime="application/pdf">
> >       <fonts>
> >         <directory recursive="true">./fonts</directory>
> >       </fonts>
> >     </renderer>
> >   </renderers>
> > </fop>
> >
> > The class in my Java code that interacts with FOP contains this:
> >
> > public class XMLConverter {
> >
> >     private Logger logger =
> Logger.getLogger(this.getClass().getName());
> >     private File xmlFile;
> >     private File xsltFile;
> >     private FopFactory fopFactory;
> >
> >      public XMLConverter(File xmlfile, File xsltfile) {
> >         this.xmlFile = xmlfile;
> >         this.xsltFile = xsltfile;
> >         initFopFactory();
> >     }
> >
> >      private void initFopFactory() {
> >         try {
> >             File jarFile = new File
> >
> (MainFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath().toString());
> >             String jarDir = jarFile.getParent();
> >             String xmlDir = xmlFile.getParent();
> >             this.fopFactory = FopFactory.newInstance();
> >             fopFactory.setUserConfig(new File(jarDir,
> "conf/fopconf.xml"));
> >             fopFactory.setFontBaseURL("file:///"+jarDir);
> >             fopFactory.setBaseURL("file:///"+xmlDir);
> >         } catch (Exception ex) {
> >             logger.severe(ex.getMessage());
> >         }
> >     }
> >
> > ..........
> >
> > The setUserConfig() and setBaseURL() methods seem to work as
> expected.
> > I've tried using the following to my FOP configuration file as well.
> >
> > <font-base>../</font-base>
> >
> > The only way I can get it to work is by using an absolute path in
> the
> > config , like so:
> >
> > <?xml version="1.0"?>
> > <fop version="1.0">
> >   <renderers>
> >     <renderer mime="application/pdf">
> >       <fonts>
> >         <directory
> >
> recursive="true">/home/greg/NetBeansProjects/NIMAS2PDF/dist/fonts</directory>
> >       </fonts>
> >     </renderer>
> >   </renderers>
> > </fop>
> >
> > Have any of you any idea what stupid thing I am doing wrong here?
> > While it's possible to obtain an absolute path via interaction with
> > the user, I would prefer to store at least a base set of fonts
> within
> > the jar directory that is installed with the application.
> >
> > Kind Regards,
> >
> > Gregory Buchenberger
> >
> >
> ---------------------------------------------------------------------
> > 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
> 
> 
> 


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


Re: Relative path to font directory

Posted by Venkat Reddy <va...@googlemail.com>.
Hi,

Have you tried the following?

<!-- Base URL for resolving relative URLs -->
<base>./</base>
<!-- Font Base URL for resolving relative font URLs -->
<font-base>./</font-base>

Source:
http://xmlgraphics.apache.org/fop/trunk/configuration.html#general-elements

Thanks,
Venkat.



Gregory Buchenberger wrote:
> I'm embedding FOP version 627324 (trunk) in a Java application and am
> trying to register a font directory using the configuration file and
> the method fopFactory.setFontBaseURL(). The font directory is in the
> same parent directory as the jar file. The jar file directory
> basically looks like this (using indentation to represent folder
> hierarchy) :
>
> MyJar.jar
> conf/
>     fopconf.xml
> xml/
>     xslt/
>         mystylesheet.xsl
>         includes/
> lib/
>     fop.jar
> fonts/
>     dejavu-ttf-2.30/
>         DejaVuSans.ttf
>
> The file conf/fopconf.xml contains the following:
>
> <?xml version="1.0"?>
> <fop version="1.0">
>   <renderers>
>     <renderer mime="application/pdf">
>       <fonts>
>         <directory recursive="true">./fonts</directory>
>       </fonts>
>     </renderer>
>   </renderers>
> </fop>
>
> The class in my Java code that interacts with FOP contains this:
>
> public class XMLConverter {
>
>     private Logger logger = Logger.getLogger(this.getClass().getName());
>     private File xmlFile;
>     private File xsltFile;
>     private FopFactory fopFactory;
>
>      public XMLConverter(File xmlfile, File xsltfile) {
>         this.xmlFile = xmlfile;
>         this.xsltFile = xsltfile;
>         initFopFactory();
>     }
>
>      private void initFopFactory() {
>         try {
>             File jarFile = new File
> (MainFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath().toString());
>             String jarDir = jarFile.getParent();
>             String xmlDir = xmlFile.getParent();
>             this.fopFactory = FopFactory.newInstance();
>             fopFactory.setUserConfig(new File(jarDir, "conf/fopconf.xml"));
>             fopFactory.setFontBaseURL("file:///"+jarDir);
>             fopFactory.setBaseURL("file:///"+xmlDir);
>         } catch (Exception ex) {
>             logger.severe(ex.getMessage());
>         }
>     }
>
> ..........
>
> The setUserConfig() and setBaseURL() methods seem to work as expected.
> I've tried using the following to my FOP configuration file as well.
>
> <font-base>../</font-base>
>
> The only way I can get it to work is by using an absolute path in the
> config , like so:
>
> <?xml version="1.0"?>
> <fop version="1.0">
>   <renderers>
>     <renderer mime="application/pdf">
>       <fonts>
>         <directory
> recursive="true">/home/greg/NetBeansProjects/NIMAS2PDF/dist/fonts</directory>
>       </fonts>
>     </renderer>
>   </renderers>
> </fop>
>
> Have any of you any idea what stupid thing I am doing wrong here?
> While it's possible to obtain an absolute path via interaction with
> the user, I would prefer to store at least a base set of fonts within
> the jar directory that is installed with the application.
>
> Kind Regards,
>
> Gregory Buchenberger
>
> ---------------------------------------------------------------------
> 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: Relative path to font directory

Posted by Gregory Buchenberger <gr...@eightfoldconsulting.com>.
Sorry but the FOP version was incorrect. That was the documentation
revision. I am using a very recent version.

On Wed, 2009-12-16 at 11:19 -0700, Gregory Buchenberger wrote:
> I'm embedding FOP version 627324 (trunk) in a Java application and am
> trying to register a font directory using the configuration file and
> the method fopFactory.setFontBaseURL(). The font directory is in the
> same parent directory as the jar file. The jar file directory
> basically looks like this (using indentation to represent folder
> hierarchy) :
> 
> MyJar.jar
> conf/
>     fopconf.xml
> xml/
>     xslt/
>         mystylesheet.xsl
>         includes/
> lib/
>     fop.jar
> fonts/
>     dejavu-ttf-2.30/
>         DejaVuSans.ttf
> 
> The file conf/fopconf.xml contains the following:
> 
> <?xml version="1.0"?>
> <fop version="1.0">
>   <renderers>
>     <renderer mime="application/pdf">
>       <fonts>
>         <directory recursive="true">./fonts</directory>
>       </fonts>
>     </renderer>
>   </renderers>
> </fop>
> 
> The class in my Java code that interacts with FOP contains this:
> 
> public class XMLConverter {
> 
>     private Logger logger = Logger.getLogger(this.getClass().getName());
>     private File xmlFile;
>     private File xsltFile;
>     private FopFactory fopFactory;
> 
>      public XMLConverter(File xmlfile, File xsltfile) {
>         this.xmlFile = xmlfile;
>         this.xsltFile = xsltfile;
>         initFopFactory();
>     }
> 
>      private void initFopFactory() {
>         try {
>             File jarFile = new File
> (MainFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath().toString());
>             String jarDir = jarFile.getParent();
>             String xmlDir = xmlFile.getParent();
>             this.fopFactory = FopFactory.newInstance();
>             fopFactory.setUserConfig(new File(jarDir, "conf/fopconf.xml"));
>             fopFactory.setFontBaseURL("file:///"+jarDir);
>             fopFactory.setBaseURL("file:///"+xmlDir);
>         } catch (Exception ex) {
>             logger.severe(ex.getMessage());
>         }
>     }
> 
> ..........
> 
> The setUserConfig() and setBaseURL() methods seem to work as expected.
> I've tried using the following to my FOP configuration file as well.
> 
> <font-base>../</font-base>
> 
> The only way I can get it to work is by using an absolute path in the
> config , like so:
> 
> <?xml version="1.0"?>
> <fop version="1.0">
>   <renderers>
>     <renderer mime="application/pdf">
>       <fonts>
>         <directory
> recursive="true">/home/greg/NetBeansProjects/NIMAS2PDF/dist/fonts</directory>
>       </fonts>
>     </renderer>
>   </renderers>
> </fop>
> 
> Have any of you any idea what stupid thing I am doing wrong here?
> While it's possible to obtain an absolute path via interaction with
> the user, I would prefer to store at least a base set of fonts within
> the jar directory that is installed with the application.
> 
> Kind Regards,
> 
> Gregory Buchenberger



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