Skip to content

feat(pdf): CMYK pictures stay CMYK in PDFs - #1059

Merged
KnifeLemon merged 2 commits into
mainfrom
feat/cmyk-pdf-pictures
Nov 3, 2026
Merged

KnifeLemon merged 2 commits into
mainfrom
feat/cmyk-pdf-pictures

Conversation

@KnifeLemon

Copy link
Copy Markdown
Owner

Part of #1027. A print user's CMYK PSD β†’ PDF came out RGB, and a CMYK JPEG β†’ PDF failed (fixed in #1057 by making it RGB). Print work needs its CMYK kept.

PDFsharp's image import takes grey and RGB only, so Pdf/CmykPictures.cs writes the image XObject itself for CMYK pictures:

  • Colour space: the picture's own CMYK ICC profile as ICCBased (N=4, alternate DeviceCMYK), or DeviceCMYK without one. A PSD with Japan Color 2001 Coated keeps it.
  • Data: a JPEG source as JPEG again (DCTDecode, the preset's quality, at least 85 as before). ImageMagick writes CMYK JPEGs inverted with Adobe's APP14 marker, as Photoshop does, so a Decode [1 0 …] array undoes it. Anything else (PSD, TIFF, …) as its CMYK samples, losslessly (FlateDecode).
  • Transparency: a soft mask (SMask).
  • Placement: the same page size, margins and centring as before, drawn with cm … Do in the page's content.

Grey and RGB pictures still go through PDFsharp unchanged.

Tested

New CmykPdfTests, each read back with PDFsharp and drawn back with PDFium:

  • CMYK JPG, TIFF and PSD with the SWOP profile β†’ the PDF image is ICCBased N=4 (DCT for JPG, Flate for the others), and the rendered page shows orange and navy where they are;
  • without a profile β†’ DeviceCMYK, colours right;
  • the lossless samples in the PDF are byte for byte the picture's CMYK;
  • a transparent half shows the white page; an RGB PNG is still DeviceRGB;
  • the Adobe-marker reader.

Engines PDF/image tests 249 pass (26 skipped for engines not installed here); dotnet format --verify-no-changes clean.

The other half of #1027 (a CMYK AI / PDF β†’ JPG keeps CMYK) comes in its own PR.

πŸ€– Generated with Claude Code

KnifeLemon and others added 2 commits November 3, 2026 21:35
A CMYK PSD, TIFF or JPEG β†’ PDF came out RGB (or failed, for JPEG): PDFsharp's image import takes grey and RGB only.
Print work needs its CMYK (#1027), so CmykPictures writes the image XObject itself: DeviceCMYK, or the picture's own
profile as an ICCBased colour space; a JPEG source as JPEG data (ImageMagick's CMYK JPEGs are inverted with Adobe's
APP14 marker, which a Decode array undoes), anything else as its samples, losslessly; transparency as a soft mask.
Grey and RGB pictures go in through PDFsharp as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the feature New features label Nov 3, 2026
@KnifeLemon
KnifeLemon merged commit ad8ff93 into main Nov 3, 2026
10 checks passed
@KnifeLemon KnifeLemon mentioned this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant