Python棒调整质量差
我有以下代码将PDF提取到JPG。我不得不调整img的大小,因为它太大了,我没有使用PDF原始格式(A4、A3等): 因此,对于每一页,我读取PDF大小,并调整用魔杖输出的大小。但我的问题是jpg的质量太差了 我的分辨率是300(我尝试使用上限值,但不连续),压缩质量是100 有什么想法吗Python棒调整质量差,python,pdf,wand,Python,Pdf,Wand,我有以下代码将PDF提取到JPG。我不得不调整img的大小,因为它太大了,我没有使用PDF原始格式(A4、A3等): 因此,对于每一页,我读取PDF大小,并调整用魔杖输出的大小。但我的问题是jpg的质量太差了 我的分辨率是300(我尝试使用上限值,但不连续),压缩质量是100 有什么想法吗 谢谢我相信PDF的mediabox是用户定义的点,而不是像素。因此,直接从我的点调整尺寸会导致质量差。我如何才能做得不同? with Img(filename=pdfName, resolution=self
谢谢我相信PDF的mediabox是用户定义的点,而不是像素。因此,直接从我的点调整尺寸会导致质量差。我如何才能做得不同?
with Img(filename=pdfName, resolution=self.resolution) as document:
reader = PyPDF2.PdfFileReader(pdfName.replace('[0]', ''))
for page_number, page in enumerate(document.sequence):
pdfSize = reader.getPage(page_number).mediaBox
width = pdfSize[2]
height = pdfSize[3]
with Img(page, resolution=self.resolution) as img:
# Do not resize first page, which used to find useful informations
if not get_first_page:
img.resize(int(width), int(height))
img.compression_quality = self.compressionQuality
img.background_color = Color("white")
img.alpha_channel = 'remove'
if get_first_page:
filename = output
else:
filename = tmpPath + '/' + 'tmp-' + str(page_number) + '.jpg'
img.save(filename=filename)