pdfme / pdfme

A TypeScript based PDF generator library, made with React.
https://pdfme.com
MIT License
2.16k stars 192 forks source link

CMYK option does not apply to QR codes #460

Open nicorsm opened 1 month ago

nicorsm commented 1 month ago

Describe the bug

TL;DR: when rendering documents as CMYK with the colorType: cmyk option, the QR codes inside them are rendered as RGB.

I'm trying to export a series of QR codes by using a template containing placeholders for a QR code, which has been created with the Template Designer at pdfme.com starting from a CMYK file. I'm also setting the colorType option to cmyk. Everything looks good, however, when opening the output PDF file in Illustrator, a popup opens saying that the document has mixed RGB and CMYK content. I dag deeper by opening the document in Acrobat Pro and running the printing Preflight tool, and I found that, while the whole content is correctly rendered as CMYK, the QR code is rendered as RGB.

Screenshot 2024-03-27 at 18 14 33

To Reproduce

Sample code can be found here, together with a sample output.pdf file and the JSON of the template: https://github.com/nicorsm/pdfme-cmyk-issue After installing the dependencies, you can run node index.js.

Expected behavior

I would expect the QR code to be rendered as CMYK, same as the whole document.

Your Environment

- pdfme package(@pdfme/generator or @pdfme/ui): @pdfme/common @pdfme/generator
- pdfme version: 3.4.3
- Operating system: macOS Sonoma 14.0
- Node.js version or Browser name & version: v20.10.0, Safari 17.0

Your Error Log

No error log from pdfme. Error is shown in Adobe Acrobat (see above) and the output report of the Preflight operation is attached to the repo (`output_report.txt`)

Additional context

This issue has to do with the introduction of colorType option described here: https://github.com/pdfme/pdfme/pull/436

hand-dot commented 1 month ago

Upon checking the PR, it became clear that only the text, line, rectangle, and ellipse schemas support CMYK.

To add CMYK support for QR codes as well, modifications to the barcode schema will be necessary.

Ref: https://github.com/pdfme/pdfme/pull/436

peteward commented 1 month ago

Whilst CMYK colours can be passed to bwip-js, apparently it converts to RGB anyway internally. This might be difficult to achieve...

hand-dot commented 1 month ago

@peteward Thank you for investigating

umm... It might be possible to achieve this by adding a process to convert the image data from RGB to CMYK before embedding it into pdf-lib.

peteward commented 1 month ago

The first step would probably be to do the conversion to CMYK for barcode color values as input for bwip to confirm if this does or does not work, then decide if post-conversion of images is something we can or should do

hand-dot commented 1 month ago

@nicorsm Can we assign this task to you? If you have any questions, I'd love to answer and help.

nicorsm commented 1 month ago

Hi @hand-dot, right now I'm not that familiar with the codebase of this library and with React, so I believe it's better to assign the task to someone else. I'll try anyway to look into this issue in the upcoming weeks as I want to understand better how the library works.