Worked like a charm. Great!

[cid:[email protected]]

Needed the decode array. Without it the image turnes out very dark:

[cid:[email protected]]

We'll try to implement it in the solution.

Thanks again.

Max


On 24 Feb 2017, at 18:52, Max Rietmeijer | Add to Favorites 
<[email protected]<mailto:[email protected]>> wrote:

Thanks for the effort. I'll give it a try!

Max

On 24 Feb 2017, at 18:48, Tilman Hausherr 
<[email protected]<mailto:[email protected]>> wrote:

Am 24.02.2017 um 10:28 schrieb Max Rietmeijer | Add to Favorites:
Hi Tilman,

Thanx for the reaction. Our printing company depends in CMYK colors to make 
offset prints. We create letters for clients who (of course) are very keen on 
company (logo) colors printed in the right tones. These are always delivered to 
us in InDesign/Illustrator/... using CMYK colors.

Converting images to a specific format is no problem for us, but we need a way 
of preserving CMYK colour information in the PDF. When exporting PDF's using 
InDesign this information is preserved. How would we go about using PDFBox?

We tried twelvemonkeys, but their JPG codec either converts CMYK to RGB or 
creates an unusable image format.

The attached image is a CMYK color based JPEG we should be able to include as 
is.

The image didn't get through, but then I remembered I could simply copy a JPEG 
from a PDF from my collection. So here's some quick code, you need the 
twelvemonkeys library for it:

      try (PDDocument doc = new PDDocument())
      {
          PDPage page = new PDPage();
          doc.addPage(page);
          try (PDPageContentStream cs = new PDPageContentStream(doc, page))
          {
              // using Root/Pages/Kids/[1]/Resources/XObject/I2200006 from 
PDFBOX-2128-PORSCHE_CMYK
              File f = new File("cmyk.jpg");

              BufferedImage bim = ImageIO.read(f);

              PDImageXObject img = new PDImageXObject(doc, new 
FileInputStream(f),
                      COSName.DCT_DECODE, bim.getWidth(), bim.getHeight(),
                      8, PDDeviceCMYK.INSTANCE);
              COSArray decode = new COSArray();
              decode.add(COSInteger.ONE);
              decode.add(COSInteger.ZERO);
              decode.add(COSInteger.ONE);
              decode.add(COSInteger.ZERO);
              decode.add(COSInteger.ONE);
              decode.add(COSInteger.ZERO);
              decode.add(COSInteger.ONE);
              decode.add(COSInteger.ZERO);
              img.setDecode(decode);

              cs.drawImage(img, 0, page.getMediaBox().getHeight() - 
img.getHeight()/ 4, img.getWidth() / 4, img.getHeight() / 4);
          }
          doc.save(new File("cmyk.pdf"));
      }

Note that this code will work ONLY for CMYK Jpeg files.

The decode array was in the original PDF, I don't know if this is needed for 
all CMYK files.

Tilman


---------------------------------------------------------------------
To unsubscribe, e-mail: 
[email protected]<mailto:[email protected]>
For additional commands, e-mail: 
[email protected]<mailto:[email protected]>



---------------------------------------------------------------------
To unsubscribe, e-mail: 
[email protected]<mailto:[email protected]>
For additional commands, e-mail: 
[email protected]<mailto:[email protected]>


Reply via email to