javaandroiditextpdfa

itext PDF/A load OutputIntents


I would like to create a PDF/A(Archive) with Itext 5 on Android. I get the error:

com.itextpdf.text.pdf.PdfAConformanceException: If an uncalibrated colour space(DeviceRGB/DeviceCMYK/DeviceGray) is used in a file, then that file shall contain a PDF/A OutputIntent.

Not sure(didn't find any other solution), but I think I need to add output intents from file:

File file = new File("resources/data/sRGB_CS_profile.icm");
ICC_Profile icc = ICC_Profile.getInstance(new FileInputStream(file));
writer.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

But I just can't get it from project resources. Any idea how to make that?


Solution

  • InputStream ins = context.getResources().openRawResource(
                        context.getResources().getIdentifier(
                          "icc_profile", "raw", context.getPackageName()));
    ICC_Profile icc = ICC_Profile.getInstance(ins);
    if (icc != null) {
        writer.setOutputIntents("Custom", "", "http://www.color.org", 
                                "sRGB IEC61966-2.1", icc);
    }
    

    And call pdfDocument.open(); before that.