Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.22k stars 686 forks source link

Support color profiles #844

Open LukasKlement opened 5 years ago

LukasKlement commented 5 years ago

Is there a way to change the colour profile to CMYK? Whilst it's easy to use PIL for jpgs, I haven't found a way to do it for entire PDFs.

There will be cmyk() support in CSS4, but that's still some time to go: https://www.w3.org/TR/css-color-4/#cmyk-colors

liZe commented 5 years ago

Is there a way to change the colour profile to CMYK? Whilst it's easy to use PIL for jpgs, I haven't found a way to do it for entire PDFs.

Cairo (the library used in WeasyPrint to generate PDF and PNG files) doesn't support CMYK. Here's a sad post about it, it's old but still relevant.

LukasKlement commented 5 years ago

Perhaps we could tackle this by converting the colour space after generating PDFs? I've seen an approach on this here: https://github.com/johndoe31415/pdfminify/blob/master/llpdf/filters/PDFAFilter.py

This might help us making some progress on this ticket as well: https://github.com/Kozea/WeasyPrint/issues/630

liZe commented 5 years ago

Perhaps we could tackle this by converting the colour space after generating PDFs?

Yes, we can do that, but only if we use colors that can have a RGB representation in a bijective way (as we'll have to use cairo at one moment, and cairo can only store RGB colors).

I've seen an approach on this here This might help us making some progress on this ticket as well: #630

pdfminify? What an interesting project, wow. You're right, it may be really helpful.

liZe commented 4 years ago

Related to #1091.

dominikhuetter commented 2 years ago

Is there any update on this issue?

liZe commented 2 years ago

Is there any update on this issue?

Now that we use our own PDF generator, it could be possible to support more features about color profiles. That’s not planned for the next milestones, but it may be in the future.

hejsan commented 2 years ago

Could you point to the relevant code sections where CMYK support would fit?

liZe commented 2 years ago

Could you point to the relevant code sections where CMYK support would fit?

That’s a very good question. I don’t know the PDF specification well enough to know how to generate a PDF with color profiles, so it’s pretty hard to tell where the relevant code is…

grewn0uille commented 2 years ago

Hello!

As it’s soon our 2-year anniversary as CourtBouillon, we opened a short survey to know more about your expectations. Don’t hesitate to support this feature and give it a boost 🚀!

The survey will be opened until October 10th.

Update: the survey is now closed. You can find the results here.

TellersFella commented 2 years ago

Hey, I just looked at the survey results and color profiles seem relevant, but not at the absolute top of the list. So my question is, is there anything planned regarding this?

liZe commented 2 years ago

Hi @TellersFella!

As you have seen with the survey results, color profiles are not our top priority. However, there has been two interesting steps recently:

When Color 4 is fully implemented, we will be able to work on the next step: support ICC-based colors in WeasyPrint for CSS (and for images…). With that, we should be able to handle everything that can be done with color profiles in PDF files.

Note that supporting naive CMYK colors directly in CSS will require to support CSS Color Module Level 5.

davidmarogy commented 1 year ago

Hello @liZe,

i just wanted to ask if there is any new updates regarding implementation of ICC-based colors or any CMYK conversion in Weasyprint?

Best regards, David

liZe commented 1 year ago

i just wanted to ask if there is any new updates regarding implementation of ICC-based colors or any CMYK conversion in Weasyprint?

Yes, some work has been done, but we’re not close to a proper CMYK support in WeasyPrint yet.

What we’ve been working on is the support of CSS color level 4 in tinycss2. This feature will enable the possibility to define non-RGB colors using CSS. The work is not merged yet (mainly because we’ve got a lot of work on other parts of WeasyPrint), but hopefully most of the code is already written. Tests and ideas to solve the latest missing features are welcome!

The next step is to include this support in WeasyPrint. It means that we’ll have to manipulate abstract colors instead of RGB colors everywhere, and that we’ll have to write the correct PDF data according to the space of the color. Images are another topic we have to take care of. That’s not done at all.

And we didn’t even talk of ICC and CMYK yet!

These features are possible with CSS color level 5, thanks to @color-profile. We need to add the support of level 4 in tinycss2, and then in WeasyPrint. It should be easier than adding level 4 support though, because we’ll already have done the work to support different color spaces.

grewn0uille commented 1 year ago

Hello!

As you may know, two weeks ago was CourtBouillon 3-year anniversary 🎉.

For this occasion, we prepared a short survey to have your opinion on this year’s features and to know what you’d like to see in the future! Don’t hesitate to give a boost to this feature ✨️

The survey is opened until November 19.