簡體   English   中英

將 PDF 轉換為 600dpi 和 jpg 96 dpi 的 TIFF

[英]convert PDF into TIFF with 600dpi and jpg 96 dpi

我想使用 ImageMagick 從 Python 腳本將 pdf 轉換為 600 dpi 的 tiff 和 96 dpi 的 jpg。

我使用 (imagemagick) 命令行完成了這項任務,但我想在 python 中使用 Imagemagick 將 pdf 轉換為 tiff 和 jpg,

你能幫我嗎......

首先,您必須在 imagemagick 庫周圍加載一個包裝器

使用PythonMagick

from PythonMagick import Image

或使用pgmagick

from pgmagick import Image

然后,獨立於您加載的庫,以下代碼將轉換和調整圖像大小

img = Image()
img.density('600')  # you have to set this here if the initial dpi are > 72

img.read('test.pdf') # the pdf is rendered at 600 dpi
img.write('test.tif')

img.density('96')  # this has to be lower than the first dpi value (it was 600)
# img.resize('100x100')  # size in px, just in case you need it
img.write('test.jpg')  


# ... same code as with pythonmagick 

可以使用subprocess 模塊執行 imagemagick 命令

import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM