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

How to set text color using CMYK colors? #1181

Closed
swasher opened this issue May 24, 2024 · 5 comments
Closed

How to set text color using CMYK colors? #1181

swasher opened this issue May 24, 2024 · 5 comments
Assignees

Comments

@swasher
Copy link

swasher commented May 24, 2024

I want to use CMYK color space for object creation. But FPDF.set_text_color() method accept only RGB values:

def set_text_color(self, r, g=-1, b=-1):
    ...

I found DeviceCMYK class in drawing.py, but have no imagine how apply it to set_text_color and similar functions.

So, is there a way for assign CMYK color for object?

@Lucas-C
Copy link
Member

Lucas-C commented May 24, 2024

Hi @swasher

Good question.
You SHOULD be able to do this:

from fpdf import FPDF
from fpdf.drawing import DeviceCMYK

pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=40)
pdf.set_text_color(DeviceCMYK(.32, 0, .1, .59))
pdf.cell(text="Hello world!")
pdf.output("repro.pdf")

But currently, with fpdf2 version 2.7.9, you will get this error:
ValueError: too many values to unpack (expected 3)

I have just fixed that bug, and the fix will be included in the next version.

For now, you can simply do this instead:

from fpdf import FPDF
from fpdf.drawing import DeviceCMYK

pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=40)
pdf.text_color = DeviceCMYK(.32, 0, .1, .59)
pdf.cell(text="Hello world!")
pdf.output("repro.pdf")

Does this answer your question @swasher? 🙂

@Lucas-C Lucas-C self-assigned this May 24, 2024
@Lucas-C Lucas-C changed the title Is there a way for assign CMYK color for object? How to set text color using CMYK colors? May 24, 2024
@Lucas-C
Copy link
Member

Lucas-C commented May 24, 2024

@allcontributors please add @Lucas-C for bug

Copy link

@Lucas-C

I've put up a pull request to add @Lucas-C! 🎉

@swasher
Copy link
Author

swasher commented May 25, 2024

Does this answer your question @swasher? 🙂

Hi Lucas! Thank you for your support, now I can use CMYK color without any problem!)

@Lucas-C
Copy link
Member

Lucas-C commented May 26, 2024

Great! Closing this then 🙂

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

No branches or pull requests

2 participants