Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: include ICC profile in documents #697

Closed
eroux opened this issue Feb 17, 2023 · 4 comments · Fixed by #709
Closed

Feature request: include ICC profile in documents #697

eroux opened this issue Feb 17, 2023 · 4 comments · Fixed by #709

Comments

@eroux
Copy link

eroux commented Feb 17, 2023

PDFs have a special way to indicate the ICC profile of an image that overrides the one potentially embedded in an image. This means that PDF viewers will ignore the ICC profile embedded in an image. Currently fpdf never writes the ICC profile so that they are consistently ignored.

Here's a sample image with an ICC profile:

icc-embedded

Here's a PDF embedding this image through img2pdf (which writes the ICC profile in the PDF):

test-icc-img2pdf.pdf

the code I'm using to test this is:

import fpdf

def test_insert_jpg_with_icc():
    pdf = fpdf.FPDF()
    pdf.compress = False
    pdf.add_page(format=(448,498))
    pdf.set_margin(0)
    pdf.image("icc-embedded.jpg", x=0, y=0, h=498)
    pdf.output("image_types_insert_jpg_with_icc.pdf")

test_insert_jpg_with_icc()

which produces the following PDF:

image_types_insert_jpg_with_icc.pdf

The two PDFs look different in a a PDF viewer (the correct one is more red).

@eroux eroux added the bug label Feb 17, 2023
@Lucas-C Lucas-C changed the title ICC profile missing in the PDF Feature request: include ICC profile in documents Feb 17, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Feb 20, 2023

Thank you for the feature suggestion @eroux 😊
This feature would sure make a great addition to fpdf2!
Any willing contributor is welcome to submit a PR implementing this,
and inspiration could be taken from img2pdf source code.

This was referenced Feb 23, 2023
@Lucas-C Lucas-C reopened this Feb 27, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Feb 27, 2023

Reopening as VeraPDF checker spotted a couple of issues with our current implementation:

All ICCBased colour spaces shall be embedded as ICC profile streams as described in PDF Reference 4.5

All ICCBased colour spaces shall be embedded as ICC profile streams as described in PDF Reference 4.5. The number of color components in the color space described by the ICC profile data must match the number of components actually in the ICC profile. As of PDF 1.4, N must be 1, 3, or 4.

Both checks failed for file test/image/png_images/image_png_insert_png_files.pdf

@Lucas-C
Copy link
Member

Lucas-C commented Feb 27, 2023

The 1st check seems like a false positive, as fpdf2 does not currently produce any ICCInputProfile object.

The 2nd one seems legit, I am creating a PR to fix it.

@eroux
Copy link
Author

eroux commented Feb 27, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants