Hi,
What about:
FopConfParser parser = new FopConfParser(configFile, currentDir);
FopFactoryBuilder fopFactoryBuilder = parser.getFopFactoryBuilder();
Thanks
-----Original Message-----
From: Stefan Radermacher [mailto:[email protected]]
Sent: 26 July 2016 16:07
To: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]