[reportlab-users] How can I insert CMYK JPG in CMYK pdf document ?
Robin Becker
robin at reportlab.com
Mon Jul 20 12:31:07 EDT 2009
KLEIN Stéphane wrote:
> Hi,
>
> I produce CMYK PDF document and I need to insert CMYK JPG file in my
> document.
>
> I've one simple example :
>
> ::
>
> from reportlab.pdfgen import canvas
> from reportlab.lib.units import cm, mm
> from reportlab.lib.pagesizes import A4
> from reportlab.pdfgen.pdfimages import PDFImage
>
> c = canvas.Canvas( "test.pdf", pagesize = A4)
> c.drawString(200, 100, "hello.pdf")
>
> img = PDFImage("image_test_cmjn.jpg", 100, 500, 300, 300)
> img.drawInlineImage(c, preserveAspectRatio = True)
>
> c.showPage()
> c.save()
>
> "image_test_cmjn.jpg" is a CMYK image.
> When I look test.pdf, this image appear converted in RGB.
>
> How can I fix this issue ?
>
> Do you have one example ?
>
> Thanks for your help,
> Stephane
.........
We do try to use jpegs natively so something else must be causing this problem.
However, the normal way to draw an image is to use the canvas interface directly
so that may be part of the problem. In stead of
> img = PDFImage("image_test_cmjn.jpg", 100, 500, 300, 300)
> img.drawInlineImage(c, preserveAspectRatio = True)
we would normally use
c.drawInlineImage("image_test_cmjn.jpg", 100, 500, 300, 300,
preserveAspectRatio=True)
or the alternative
c.drawImage("image_test_cmjn.jpg", 100, 500, 300, 300, preserveAspectRatio=True)
the latter is the preferred interface lately so may be kinder.
Looking in the code it seems your sequence was correct for the drawInline case.
--
Robin Becker
More information about the reportlab-users
mailing list