Reputation: 869
I'm using Apache FOP v2.6 & trying to generate a PDF/A-2b with one of the Base-14 Fonts Embedded.
I'm getting an org.apache.fop.pdf.PDFConformanceException:
"For PDF/A-2b, all fonts, even the base 14 fonts, have to be embedded! Offending font: /Helvetica"
Here's what I think is the relevant snippet of Code:
Any ideas what might be missing?
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import javax.xml.transform.TransformerException;
import org.apache.fop.Version;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.fop.configuration.ConfigurationException;
import org.apache.fop.configuration.DefaultConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PdfBuilder {
private static final Logger LOG = LoggerFactory.getLogger(PdfBuilder.class);
private static final FopFactory FOP_FACTORY;
/**/ static {
final var fopConfigXml =
"""
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
""";
final var fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI());
try {
final var fopConfigStream = new ByteArrayInputStream(fopConfigXml.getBytes());
final var fopConfig = new DefaultConfigurationBuilder().build(fopConfigStream);
fopFactoryBuilder.setConfiguration(fopConfig);
LOG.info ("FOP Config.:" + " fopVersion={} xml.:{}{}", Version.getVersion(), "\n", fopConfigXml);
}
catch (final ConfigurationException e) {
LOG.error("FOP Config Error.:" + " fopVersion={} xml.:{}{}", Version.getVersion(), "\n", fopConfigXml, e);
}
FOP_FACTORY = fopFactoryBuilder.build();
}
public byte[] generatePDFfromFO(final byte[] bytesFO) throws IOException, FOPException, TransformerException {
final var foUserAgent = FOP_FACTORY.newFOUserAgent();
/**/ foUserAgent.getRendererOptions().put("pdf-a-mode", "PDF/A-2b");
:
:
:
:
return pdfBytes;
}
}
Upvotes: 1
Views: 668
Reputation: 869
Hitherto, I had assumed the Fonts were somehow included in Apache FOP.
That is not the case
Apache FOP contains Metadata, describing the Fonts, which is used to Layout the PDF.
To include Fonts, as mandated for PDF/A, you have to supply them. See example, below.
But that still doesn't solve the problem:
even though all Fonts were explicitly mapped to one of the configured Fonts, the
"For PDF/A-2b, all fonts, even the base 14 fonts, have to be embedded! Offending font: /Helvetica"
error still occurs.
It is necessary to explicitly configure the default Font at the root of the Stylesheet.
I believe that is a Bug in Apache FOP, but never mind, I now have a workaround.
The FOP Config looked something like this:
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="path/Helvetica-Regular.ttf" ><font-triplet name="Helvetica" style="normal" weight="normal"/></font>
<font kerning="yes" embed-url="path/Helvetica-Italic.ttf" ><font-triplet name="Helvetica" style="italic" weight="normal"/></font>
<font kerning="yes" embed-url="path/Helvetica-Bold.ttf" ><font-triplet name="Helvetica" style="normal" weight="bold" /></font>
<font kerning="yes" embed-url="path/Helvetica-BoldItalic.ttf"><font-triplet name="Helvetica" style="italic" weight="bold" /></font>
<font kerning="yes" embed-url="path/Times-Regular.ttf" ><font-triplet name="Times" style="normal" weight="normal"/></font>
<font kerning="yes" embed-url="path/Times-Italic.ttf" ><font-triplet name="Times" style="italic" weight="normal"/></font>
<font kerning="yes" embed-url="path/Times-Bold.ttf" ><font-triplet name="Times" style="normal" weight="bold" /></font>
<font kerning="yes" embed-url="path/Times-BoldItalic.ttf" ><font-triplet name="Times" style="italic" weight="bold" /></font>
<font kerning="yes" embed-url="path/Courier-Regular.ttf" ><font-triplet name="Courier" style="normal" weight="normal"/></font>
<font kerning="yes" embed-url="path/Courier-Italic.ttf" ><font-triplet name="Courier" style="italic" weight="normal"/></font>
<font kerning="yes" embed-url="path/Courier-Bold.ttf" ><font-triplet name="Courier" style="normal" weight="bold" /></font>
<font kerning="yes" embed-url="path/Courier-BoldItalic.ttf" ><font-triplet name="Courier" style="italic" weight="bold" /></font>
<font kerning="yes" embed-url="path/Symbol.ttf" ><font-triplet name="Symbol" style="normal" weight="normal"/></font>
<font kerning="yes" embed-url="path/ZapfDingbats.ttf" ><font-triplet name="ZapfDingbats" style="normal" weight="normal"/></font>
</fonts>
</renderer>
</renderers>
</fop>
Upvotes: 0