Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF/A3-B Export: produces faulty CIDSet #457

Open
JohnHuynh opened this issue Jul 12, 2024 · 3 comments
Open

PDF/A3-B Export: produces faulty CIDSet #457

JohnHuynh opened this issue Jul 12, 2024 · 3 comments

Comments

@JohnHuynh
Copy link

JohnHuynh commented Jul 12, 2024

I am using JasperReports to generate PDF/A-3B documents and attempting to validate them with the Mustang library.

However, I encounter the following error: "A CIDSet entry in the Font descriptor does not correctly identify all glyphs present in the embedded font subset."

I am using the following libraries:

  • JasperReports Version: 6.21.3
  • Mustang Validator Version: 2.11.0
  • PDFBox Version: 3.0.2

Here is the code I use to create pdfs:

generate(JasperReport report, Map<String,Object> data, OutputStream document) {
            [...]
            JasperPrint print = JasperFillManager.fillReport(report, data, new JREmptyDataSource());
            JRPdfExporter exporter = new JRPdfExporter();
            exporter.setExporterInput(new SimpleExporterInput(print));
            exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(document));

            SimplePdfExporterConfiguration exportConfig = new SimplePdfExporterConfiguration();
            exportConfig.setPdfVersion(PdfVersionEnum.VERSION_1_7);
            exportConfig.setPdfaConformance(PdfaConformanceEnum.PDFA_3B);
            exportConfig.setIccProfilePath("AdobeRGB1998.icc");
            exportConfig.setMetadataAuthor("Your Name");
            exportConfig.setTagged(true);
            exportConfig.setTagLanguage("en-us");
            exportConfig.setEmbedIccProfile(true);

            exporter.setConfiguration(exportConfig);
            exporter.exportReport();

            [...]
}

The fonts that I'm using are OpenSans fonts. In my fontsfamily.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
    <fontFamily name="OpenSans">
        <!-- Normal Font -->
        <normal><![CDATA[fonts/OpenSans-Regular.ttf]]></normal>
        <!-- Bold Font -->
        <bold><![CDATA[fonts/OpenSans-Bold.ttf]]></bold>
        <!-- Italic Font -->
        <italic><![CDATA[fonts/OpenSans-Italic.ttf]]></italic>
        <!-- Bolt italic Font -->
        <boldItalic><![CDATA[fonts/OpenSans-BoldItalic.ttf]]></boldItalic>
        <!-- Is font is embedded in PDF -->
        <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
    </fontFamily>
</fontFamilies>

In my jasperreports_extension.properties:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.OpenSans=fonts/fontsfamily.xml

I suspected that there might be an issue with how I embed the font, so here are my attempts:

I have ensured that the fonts are embedded as subsets by using the isPdfEmbedded attribute like this:

<style name="Standard" isDefault="true" pattern="" fontName="OpenSans" fontSize="10" isPdfEmbedded="true"/>

The pdf acrobat reader also shows in the fonts properties that a subset of the font is embedded:

image

The error also occurs when I omit all text from the .jrxml report template, leaving only the font styles embedded. Here is the example .jrxml template:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="name" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="500" leftMargin="64" rightMargin="31" topMargin="0" bottomMargin="0" uuid="redacted">
	<style name="Standard" isDefault="true" pattern="" fontName="OpenSans" fontSize="10" isPdfEmbedded="true" pdfEncoding="Identity-H"/>
</jasperReport>

I tried out another font as well (DejaVu Sans), to see if OpenSans is the problem but it didn't work either.

Here is an example output file that fails to be validated: output.pdf

Here is my related stackoverflow post.

In order to be PDF/A-3 compliant, one could either remove the CIDSet Stream for PDF/A-3 creations or correct the entry creations for the CIDSet to match the entries from the embedded font.

@StevenHachel
Copy link

We are currently facing the same problem and cannot solve it. The goal is to generate a PDF/A-3 in order to be Mustang compliant. However, we did not think that it would be such a challenge with Jasperreport.
Have you @JohnHuynh been able to find a solution yet?

Jasperreport version: 6.21.3

@JohnHuynh
Copy link
Author

We are currently facing the same problem and cannot solve it. The goal is to generate a PDF/A-3 in order to be Mustang compliant. However, we did not think that it would be such a challenge with Jasperreport. Have you @JohnHuynh been able to find a solution yet?

Jasperreport version: 6.21.3

I have an odd solution which works for me for now, but I don't know if this will produce any further problems in the future:

I created a simple PDF (it is not even a PDF/A3 file) with jasperreports. Then I used the Java Mustang library to load the pdf data into the code because I needed to create XML data for it:

            // loads pdf data
            ZUGFeRDExporterFromA3 ze = new ZUGFeRDExporterFromA3();
            ze.load(pdfData);
            ze.setXML(createMyXmlData());
            var output = new ByteArrayOutputStream();
            ze.export(output);
            // pdf data of the new PDF/A-3 byte[]
            return output.toByteArray();

I remember that this code also works for a faulty PDF/A-3 file of jasperreports. Hence, if you run this code with your jasperreports pdf and validate it afterwards, it should be a valid PDF/A-3.

Hope this helps.

Cheers

@StevenHachel
Copy link

StevenHachel commented Jan 9, 2025

Thank you very much for this solution and the super quick reply!
I'll try it that way.

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants