[reportlab-users] embedded png image quality

Robin Becker robin at reportlab.com
Thu Jan 10 13:39:30 EST 2008


James Crone wrote:

> Hi,

>

> I`m embedding a PNG image (a map rendered from MapServer) into a pdf

> using reportlab with:

>

> import Image

> from reportlab.pdfgen import canvas

> from reportlab.lib.pagesizes import portrait,A4

>

> myImage = Image.open("C:/input_map_image.png")

> bgsMapCanvas = canvas.Canvas("C:/output_map_doc.pdf",pagesize=portrait(A4))

> bgsMapCanvas.setPageCompression(0)

> bgsMapCanvas.drawInlineImage(myImage,0,0,myImage.size)

> bgsMapCanvas.showPage()

> bgsMapCanvas.save()

>

>

> in the resulting pdf the embedded PNG image has been compressed

> resulting in a loss of image quality and a fuzzy map document :-( . Is

> it possible to prevent (PNG) images from being compressed when I add

> them to a document?

>

> Thanks in advance,

>

> James

>


I'm not exactly sure what you mean here. PDF natively supports jpeg which has an
internal notion of quality. For other formats including opened PIL images we
attempt to convert directly to 8bit rgb and pass that to PDF. As part of the PDF
streaming process we apply some data filters to compress the size of the stream,
but that shouldn't affect quality in any way. The compression that's controlled
by setPageCompression is completely lossless and only attempts to reduce the
final document size(not quality). However, there may be some other kind of bug
which means we're doing the wrong thing. I'm quite happy to look at your example
if you send me the image. Don't reply here if the image is large just email me
direct.
--
Robin Becker


More information about the reportlab-users mailing list