pdf转图片再转pdf

PDF转图片

from wand.image import Image,Color
        with Image(filename=file_path + '.pdf', resolution=300,background=Color('White')) as img:
            img.format = 'png'
            img.save(filename=file_path+'.png' )
        return    file_path+'.png'

用到了wand这个包
filename:图片地址
resolution:像素大小
background:背景色
format:要转换的图片格式

图片转PDF

img = Image.open(file_path+'.png')
img = img.convert("RGBA")
transparent = Image.new('RGB', img.size, (255, 255, 255, 255))
transparent.paste(img, (0, 0), img)
transparent.save(file_path+'.pdf')

因为转换的是PNG,所以先转换色彩空间rgba,再生成pdf

猜你喜欢

转载自blog.csdn.net/makegame88/article/details/88552783
今日推荐