How can I export report to PDF/A-1a, PDF/A-1b?
JasperReports Library 4.1.2.3 or higher is needed (with discontinued support in 6.0.0 see NullPointerException
at the end).
These steps are need to generate a PDF/A, they can be achieved both by java code or by setting jrxml property
to root tag (jasper-server support). I will show both but only one method is necessary.
#Set PDF/A Conformance
java
configuration.setPdfaConformance(PdfaConformanceEnum.PDFA_1A); // or PdfaConformanceEnum.PDFA_1B
jrxml
<property name="net.sf.jasperreports.export.pdfa.conformance" value="pdfa1a" />
#Set ICC Profile
to avoid
JRPdfaIccProfileNotFoundException: The ICC profile is not available to the JVM
java
configuration.setIccProfilePath("srgb.icc");
jrxml
<property name="net.sf.jasperreports.export.pdfa.icc.profile.path" value="srgb.icc" />
#Embed all font used in reports, using font-extensions
If you still have error
com.lowagie.text.pdf.PdfXConformanceException: All the fonts must be embedded. This one isn't: Helvetica
include a default style in the jrxml indicating fontName
that is included in font extension, example
<style name="default" isDefault="true" fontName="DejaVu Sans"/>
#Remove transparent objects and layers (Optional Content Groups) they are not allowed
to avoid
PdfXConformanceException: Transparency is not allowed
In example the chart element must be Opaque
and to avoid transparency on the labels you can implement a JRChartCustomizer
public class NoTransparencyCustomizer implements JRChartCustomizer{
@Override
public void customize(JFreeChart chart, JRChart jrchart) {
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelShadowPaint(Color.GRAY);
}
}
#Set Tagged and tag language (unnecessary for PDF/A-1b)
java
configuration.setTagged(true);
configuration.setTagLanguage("en-us");
jrxml
<property name="net.sf.jasperreports.export.pdf.tagged" value="true" />
<property name="net.sf.jasperreports.export.pdf.tag.language" value="en-us"/>
#Result
This is the result implementing the above, switching fontName
to DejaVu Sans
and using the bundled jasperreports-fonts.jar
as font-extension. It has been validated successfully on pdf-tools for both PDF/A-1a and PDF/A-1b
No piece of the cake for me
XMP property is not synchronized with the document information
Validating file "reputation.pdf" for conformance level pdfa-1a
dc:description/*[0] :: Missing language qualifier.
dc:title/*[0] :: Missing language qualifier.
The XMP property 'dc:title' is not synchronized with the document information entry 'Title'.
The XMP property 'dc:description' is not synchronized with the document information entry 'Subject'.
This error comes from using older jasper-reports library <6.2.0 when you set metadata title or subject in configuration.
configuration.setMetadataTitle("Title");
configuration.setMetadataSubject("Subject");
The solution is to remove these or update jasper-reports to versione 6.2.0 or above see PDF/A_1A XMP Metadata validation fails if title and/or subject are set for more information
Discontinued support
In jasper report version 6.0.0 a NullPointerException at com.itextpdf.text.pdf.internal.PdfA1Checker.checkPdfObject
was always thrown. This has been solved in 6.0.4 and above see Jasper report tracker.