简体   繁体   English

使用reportlab将图像放入pdf时提高图像的质量

[英]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. 我正在尝试使用reportlab(例如,follow)以python语言将JPG图像转换为PDF。

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. 这里的问题是,以pdf显示的图像与原始图像质量不同。 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. 不幸的是,大多数将JPEG转换为PDF的工具都将解压缩,然后(严重)重新压缩JPEG。

img2pdf can wrap many (most?) JPEG images into PDFs without changing the compression (without decompressing at all, in fact). img2pdf可以将许多(大多数?)JPEG图像包装为PDF,而无需更改压缩率(实际上完全不进行解压缩)。

Then you can use pdfrw to pull that PDF onto the reportlab canvas as a form xObject (similar to an image). 然后,您可以使用pdfrw将PDF作为xObject形式(类似于图像)将PDF拉到reportlab画布上。 There are a few examples in the pdfrw/examples/rl1 directory that show how to do this. pdfrw / examples / rl1目录中有一些示例说明了如何执行此操作。

Disclaimer: I am the pdfrw author. 免责声明:我是pdfrw的作者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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