pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Max Rietmeijer | Add to Favorites <mrietmei...@addtofavorites.nl>
Subject Re: CMYK images
Date Fri, 24 Feb 2017 18:05:30 GMT
Worked like a charm. Great!

[cid:08F23876-462B-4311-A8FF-1A712E7E4E02@dynamic.ziggo.nl]

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

[cid:F0B38518-875D-433B-BA81-E4EC5DC56B7D@dynamic.ziggo.nl]

We'll try to implement it in the solution.

Thanks again.

Max


On 24 Feb 2017, at 18:52, Max Rietmeijer | Add to Favorites <mrietmeijer@addtofavorites.nl<mailto:mrietmeijer@addtofavorites.nl>>
wrote:

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

Max

On 24 Feb 2017, at 18:48, Tilman Hausherr <THausherr@t-online.de<mailto:THausherr@t-online.de>>
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: users-unsubscribe@pdfbox.apache.org<mailto:users-unsubscribe@pdfbox.apache.org>
For additional commands, e-mail: users-help@pdfbox.apache.org<mailto:users-help@pdfbox.apache.org>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org<mailto:users-unsubscribe@pdfbox.apache.org>
For additional commands, e-mail: users-help@pdfbox.apache.org<mailto:users-help@pdfbox.apache.org>



Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message