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 Stefan Radermacher <st...@zaister.de> on 2016/07/26 15:07:25 UTC

Problem embedding fonts in PDF

Hello, I am looking for some help on embedding fonts with FOP (version
2.1). I am working on program that uses FOP to create PDF files.
Unfortunately the standard fonts included in FOP do not have glyphs for
many international character that we would like to be able to include in
our generated PDFs. So I have started on looking to embed custom fonts.
I am trying this with a free font called Gandhi Sans for now.

I think I have set up the stuff as the documentation indicates, but my
font configuration gets ignored and FOP produces a lot of warnings
listing: "Font "Gandhi Sans,normal,400" not found. Substituting with
"any,normal,400""

My fop.xconf file looks as follows (relevant parts only):
-------- snip --------
<fop version="1.0">
  <base>./</base>
  <font-base>fonts/</font-base>
  <renderers>
    <renderer mime="application/pdf">
      <filterList>
        <value>flate</value>
      </filterList>

      <fonts>
        <font kerning="yes" embed-url="Gandhi_Sans_Regular.otf">
          <font-triplet name="Gandhi Sans" style="normal"
            weight="normal" />
        </font>
        <font kerning="yes" embed-url="Gandhi_Sans_Bold.otf">
          <font-triplet name="Gandhi Sans" style="normal"
            weight="bold" />
        </font>
        <font kerning="yes" embed-url="Gandhi_Sans_Italic.otf">
          <font-triplet name="Gandhi Sans" style="italic"
            weight="normal" />
        </font>
        <font kerning="yes" embed-url="Gandhi_Sans_Bold_Italic.otf">
          <font-triplet name="Gandhi Sans" style="italic"
            weight="bold" />
        </font>
      </fonts>
    </renderer>
...
</fop>
-------- snip --------

I do have the weird feeling that the file gets ignored somehow, since
even when I modify it to point to a non-existent font file or even to
have an invalid xml structure, I'm not getting any errors or exceptions
about this. Anyway, the fonts are located in a folder "fonts" that is on
the same level as the fop.xconf file. I have tried using full paths or
full URIs with file:// prefix to indicate the font files, but no change.
I have also tried with and without trailing slash for the base and
font-base properties.

I'm adding the file in my Java code like this:
-------- snip --------
FopFactoryBuilder builder;
File userConfigFile = new
    File(ConfigurationSettings.getOutputSheetsDir()
    + File.separator + "fop.xconf");
try
{
  builder = new FopFactoryBuilder(userConfigFile.toURI());
}
catch (Exception e)
{
  [exception handling]
}

builder.setStrictFOValidation(false);
builder.setStrictUserConfigValidation(true);

FopFactory fopFactory = builder.build();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.getEventBroadcaster().addEventListener(
    new FOPEventListener());

[set some userAgent attributes]

try
{
  Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);

  TransformerFactory transFactory = TransformerFactory.newInstance();
  Transformer transformer = transFactory.newTransformer(xsltSource);
  transformer.setErrorListener(new FOPErrorListener());
  transformer.transform(inputSource,
    new SAXResult(fop.getDefaultHandler()));
}
catch (TransformerException | FOPException | IOException e)
{
  [exception handling]
}
-------- snip --------

What am I doing wrong?

Kind regards and thanks for any help,
Stefan

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


Re: Problem embedding fonts in PDF

Posted by Stefan Radermacher <st...@zaister.de>.
On 26.07.2016 17:26, Simon Steiner wrote:
> What about:
> 	
>         FopConfParser parser = new FopConfParser(configFile, currentDir);
>         FopFactoryBuilder fopFactoryBuilder = parser.getFopFactoryBuilder();

Thank you, that looks much better. I used the FopConfParser constructor
that just takes the config File, and then got this error:

"The Fontbox jar was not found in the classpath. This is required for
OTF CFF ssupport." (sic)

I added Fontbox 1.8.9 to my dependencies, and voila the font loads!

Kind regards and thank you,
Stefan

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


RE: Problem embedding fonts in PDF

Posted by Simon Steiner <si...@gmail.com>.
Hi,

What about:
	
        FopConfParser parser = new FopConfParser(configFile, currentDir);
        FopFactoryBuilder fopFactoryBuilder = parser.getFopFactoryBuilder();



Thanks

-----Original Message-----
From: Stefan Radermacher [mailto:stefan@zaister.de] 
Sent: 26 July 2016 16:07
To: fop-users@xmlgraphics.apache.org
Subject: Problem embedding fonts in PDF

Hello, I am looking for some help on embedding fonts with FOP (version 2.1). I am working on program that uses FOP to create PDF files.
Unfortunately the standard fonts included in FOP do not have glyphs for many international character that we would like to be able to include in our generated PDFs. So I have started on looking to embed custom fonts.
I am trying this with a free font called Gandhi Sans for now.

I think I have set up the stuff as the documentation indicates, but my font configuration gets ignored and FOP produces a lot of warnings
listing: "Font "Gandhi Sans,normal,400" not found. Substituting with "any,normal,400""

My fop.xconf file looks as follows (relevant parts only):
-------- snip --------
<fop version="1.0">
  <base>./</base>
  <font-base>fonts/</font-base>
  <renderers>
    <renderer mime="application/pdf">
      <filterList>
        <value>flate</value>
      </filterList>

      <fonts>
        <font kerning="yes" embed-url="Gandhi_Sans_Regular.otf">
          <font-triplet name="Gandhi Sans" style="normal"
            weight="normal" />
        </font>
        <font kerning="yes" embed-url="Gandhi_Sans_Bold.otf">
          <font-triplet name="Gandhi Sans" style="normal"
            weight="bold" />
        </font>
        <font kerning="yes" embed-url="Gandhi_Sans_Italic.otf">
          <font-triplet name="Gandhi Sans" style="italic"
            weight="normal" />
        </font>
        <font kerning="yes" embed-url="Gandhi_Sans_Bold_Italic.otf">
          <font-triplet name="Gandhi Sans" style="italic"
            weight="bold" />
        </font>
      </fonts>
    </renderer>
...
</fop>
-------- snip --------

I do have the weird feeling that the file gets ignored somehow, since even when I modify it to point to a non-existent font file or even to have an invalid xml structure, I'm not getting any errors or exceptions about this. Anyway, the fonts are located in a folder "fonts" that is on the same level as the fop.xconf file. I have tried using full paths or full URIs with file:// prefix to indicate the font files, but no change.
I have also tried with and without trailing slash for the base and font-base properties.

I'm adding the file in my Java code like this:
-------- snip --------
FopFactoryBuilder builder;
File userConfigFile = new
    File(ConfigurationSettings.getOutputSheetsDir()
    + File.separator + "fop.xconf");
try
{
  builder = new FopFactoryBuilder(userConfigFile.toURI());
}
catch (Exception e)
{
  [exception handling]
}

builder.setStrictFOValidation(false);
builder.setStrictUserConfigValidation(true);

FopFactory fopFactory = builder.build(); FOUserAgent userAgent = fopFactory.newFOUserAgent(); userAgent.getEventBroadcaster().addEventListener(
    new FOPEventListener());

[set some userAgent attributes]

try
{
  Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);

  TransformerFactory transFactory = TransformerFactory.newInstance();
  Transformer transformer = transFactory.newTransformer(xsltSource);
  transformer.setErrorListener(new FOPErrorListener());
  transformer.transform(inputSource,
    new SAXResult(fop.getDefaultHandler()));
}
catch (TransformerException | FOPException | IOException e) {
  [exception handling]
}
-------- snip --------

What am I doing wrong?

Kind regards and thanks for any help,
Stefan

---------------------------------------------------------------------
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