3
votes

I have a PDF document which is accessible (tagged), I want to add it PDF/A 2-a compliance with Itext 5.4.5.

I can open a PDFAWriter with PDF/A 2-b compliance (note the b), import each of the pages, copy them. The output document complies with PDF/A 2-b compliance (I checked with two validators), but then I'm losing the accessibility (the structure tags).

I then tried to open a PDFAWriter with PDF/A 2-a compliance (note the a), use writer.setTagged(), import each of the pages and copy them like this:

    Document document = new Document();
    PdfAWriter writer = PdfAWriter.getInstance(document,
        new FileOutputStream(output), PdfAConformanceLevel.PDF_A_2A);

    PdfReader pdfReader = new PdfReader(input);
    writer.setTagged();
    writer.setLanguage("en");
    writer.setLinearPageMode();
    writer.createXmpMetadata();

    document.open();
    ICC_Profile icc = ICC_Profile.getInstance(new FileInputStream(PROFILE));
    writer.setOutputIntents("Custom", "", "http://www.color.org",
            "sRGB IEC61966-2.1", icc);

    PdfContentByte cb = writer.getDirectContent();

    int n1 = pdfReader.getNumberOfPages();
    for (int i = 1; i <= n1; i++) {
        document.newPage();
        PdfImportedPage page = writer.getImportedPage(pdfReader, i);
        cb.addTemplate(page, 0, 0);
    }
    document.close();

But this generates this error

Exception in thread "main" com.itextpdf.text.pdf.PdfAConformanceException: Alt entry should specify alternate description for /Figure element. at com.itextpdf.text.pdf.internal.PdfA2Checker.checkStructElem(PdfA2Checker.java:822) at com.itextpdf.text.pdf.internal.PdfAChecker.checkPdfAConformance(PdfAChecker.java:222) at com.itextpdf.text.pdf.internal.PdfAConformanceImp.checkPdfIsoConformance(PdfAConformanceImp.java:70)

Any workaround? Solution to this problem?

(I know that PDFCopy would preserve tagging, but then how do I specify the PDF/A 2-a bit...?)

1

1 Answers

0
votes

I was easily able to do this in 3‑Heights, but I would like an IText Solution to this problem.

(Personally, I am a bit disappointed by the interface offered. For instance, PDFCopy extends PdfWriter, but not PdfAWriter).