简体   繁体   中英

Improve the quality of an image when I put it into a pdf using reportlab

I'm trying to put an JPG image into a PDF using reportlab like follow, in python language.

p = canvas.Canvas(buffer) p.drawImage(filename_jpg_image,x,y)

The problem here is that the image displayed in the pdf does not have the same quality as the original one. I want to know if there are a way to specify the quality in this context, or improve it anyway. Anybody can help me?

Unfortunately, most tools that put JPEGs into PDFs will uncompress and then (badly) recompress the JPEG.

img2pdf can wrap many (most?) JPEG images into PDFs without changing the compression (without decompressing at all, in fact).

Then you can use pdfrw to pull that PDF onto the reportlab canvas as a form xObject (similar to an image). There are a few examples in the pdfrw/examples/rl1 directory that show how to do this.

Disclaimer: I am the pdfrw author.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM