javamavenitextjasper-reportspdfa

PDF/A-1b compliance problem with dc:title


Problem:

I'm trying to create a PDF/A-1b compliant file, starting from java using JasperReports. I'm using Adobe Acrobat Pro DC for checking the file with preflight tool, which is giving me an error regarding the field dc:title , this is the error's screenshot:

Preflight error

I've tried setting the property in any possible way, but I still getting this error and I can't figure why. I've tried reading at http://purl.org/dc/elements/1.1/dc:title , but I didn't find nothing useful. I have a suspicion about this report regarding metadata - > advanced -> http://purl.org/dc/elements/1.1 , where I see there is a dc:title empty, and a dc:title[1] filled, but I don't know how to set the first one.

Code snippet

    Session session = getMyConnection();
    SessionImpl sessionImpl = (SessionImpl) session;
    Connection conn = sessionImpl.connection();
    String title = "Test title";

    Map<String, Object> hm = new HashMap<>();
    hm.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session);
    hm.put("ID", getTestId();
    hm.put("reportTitle", title); //Title here
    hm.put("info.title", title); //Title here

    JasperReport jasperReport = JasperCompileManager
            .compileReport("c:/eglobal/TEST_REPORT.jrxml");
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, hm, conn);
    jasperPrint.setProperty(PdfExporterConfiguration.PROPERTY_METADATA_TITLE, title); //Title here

    JRPdfExporter exporter = new JRPdfExporter();
    SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
    configuration.setPdfaConformance(PdfaConformanceEnum.PDFA_1B);
    configuration.setIccProfilePath("c:/eglobal/AdobeRGB1998.icc");
    configuration.setMetadataTitle(title); //Title here
    configuration.setDisplayMetadataTitle(true);

    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("c:/eglobal/TEST_REPORT.PDF"));
    exporter.setConfiguration(configuration);
    exporter.exportReport();

As you can see the title is setted in every possible way ( see //Title here comment): I've tried with each of them individually, and nothing changes.

Library

These are the libraries I'm using

    <jasperVersion>6.16.0</jasperVersion>

    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports-fonts</artifactId>
        <version>${jasperVersion}</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>${jasperVersion}</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports-metadata</artifactId>
        <version>${jasperVersion}</version>
    </dependency>

Solution

  • While reading code into JRPdfExporter inside JasperReport lib, I've found a comment saying:

    iText 2.1.7 does not properly write localized properties and keywords. XMP metadata might be non conforming, include the Adobe XMP library to correct

    So I've discovered inside of Jasper Report's pom.xml that there is a specific Adobe library (set as optional inside that pom):

        <dependency>
            <groupId>com.adobe.xmp</groupId>
            <artifactId>xmpcore</artifactId>
            <version>5.1.3</version>
        </dependency>
    

    Adding this dependency in my pom solved the problem