Search code examples
pdfpdfboxpdfa

PDFBox - include multiple color profiles during conversion to PDF/A


We are currently trying to merge multiple PDFs and create a PDF/A (1B) out of it.

Currently we face a problem when we want to fix the color profiles. The PDF we receive has no embedded color profiles, so during the merge functionality of PDFBox, no OutputIntents are merged. So in the last step we try to add the color profiles.

If we do not add any color profile, we get validation issues for RGB and CMYK. If we add both color profiles to the PDDocumentCatalog, then only the validation issues for the first one are gone. So if we add RGB first, we only get CMYK validation issues and vice versa.

Here is a part of the code when we add the color profiles:

      public void convertToPDFA(PDDocument doc, String file){

              PDMetadata metadata = new PDMetadata(doc);
              PDDocumentCatalog cat = doc.getDocumentCatalog();
              cat.setMetadata(metadata);

              // do metadata stuff, just removed it for now

              InputStream colorProfile = PDFService.class.getResourceAsStream("/pdfa/sRGB Color Space Profile.icm");
              PDOutputIntent oi = new PDOutputIntent(doc, colorProfile);
              oi.setInfo("sRGB IEC61966-2.1");
              oi.setOutputCondition("sRGB IEC61966-2.1");
              oi.setOutputConditionIdentifier("sRGB IEC61966-2.1");
              oi.setRegistryName("http://www.color.org");
              cat.addOutputIntent(oi); 

This is the code for RGB, we also add another *.icm color profile for CMYK. So the color profiles seem to be fine, because dependent on the one we add first, the validation issues are gone.

For me it feels like we are just missing a small thing that both color profiles will be accepted, or could it be that only one color profile can be used for the creation of a PDF/A?

Thanks in advance and kind regards


Solution

  • Only a single output intent is allowed, see here. An alternative is also mentioned there, which would be to use only ICC based colorspaces.

    What should be possible (although beyond the scope of the question), would be to assign ICC profiles to /DeviceGray, /DeviceRGB, or /DeviceCMYK, by adding DefaultGray, DefaultRGB, or DefaultCMYK entries the ColorSpaces in the resource dictionary, as explained in section 8.6.5.6 of the PDF specification:

    When a device colour space is selected, the ColorSpace subdictionary of the current resource dictionary (see 7.8.3, "Resource Dictionaries") is checked for the presence of an entry designating a corresponding default colour space (DefaultGray, DefaultRGB, or DefaultCMYK, corresponding to DeviceGray, DeviceRGB, or DeviceCMYK, respectively). If such an entry is present, its value shall be used as the colour space for the operation currently being performed.

    Be aware that making PDF file PDF/A-1b conformant is often more trickier than just adding output intents - check your file with PDFBox preflight or with the online validator from PDF Tools, there are many possible errors. Which is why there are products from Callas Software or PDF Tools that convert PDF files to PDF/A.