Python進行PDF轉圖片
![Python—PDF轉圖片](http://p2.ttnews.xyz/loading.gif)
pdfplumber的可視化調試
使用pdfplumber這個Python工具庫,pdfplumber基於pdfminer.six。
使用pdfplumber進行PDF轉圖片,簡單快捷。同時pdfplumber還提供可視化的PDF內容提取調試支持,如上圖。
<code>import pdfplumber
pdf = pdfplumber.open("ccf-2019.pdf")
for i, page in enumerate(pdf.pages):
page.to_image(resolution=150).save('{}.png'.format(i))/<code>
Linux上進行PDF轉圖片
Linux上使用pdftoppm命令行工具可以方便進行PDF轉圖片,pdftoppm屬於poppler-utils包。
安裝:
<code>sudo apt install poppler-utils/<code>
使用:
<code>pdftoppm -png demo.pdf /<code>
pdftoppm提供許多配置選項,比如crop剪切圖片、縮放、分辨率、打印頁數等等。
<code>Usage: pdftoppm [options] [PDF-file [PPM-file-prefix]]
-f: first page to print /<code>
-l: last page to print
-o : print only odd pages
-e : print only even pages
-singlefile : write only the first page and do not add digits
-r: resolution, in DPI (default is 150)
-rx: X resolution, in DPI (default is 150)
-ry: Y resolution, in DPI (default is 150)
-scale-to: scales each page to fit within scale-to*scale-to pixel box
-scale-to-x: scales each page horizontally to fit in scale-to-x pixels
-scale-to-y: scales each page vertically to fit in scale-to-y pixels
-x: x-coordinate of the crop area top left corner
-y: y-coordinate of the crop area top left corner
-W: width of crop area in pixels (default is 0)
-H: height of crop area in pixels (default is 0)
-sz: size of crop square in pixels (sets W and H)
-cropbox : use the crop box rather than media box
-mono : generate a monochrome PBM file
-gray : generate a grayscale PGM file
-png : generate a PNG file
-jpeg : generate a JPEG file
-jpegopt <string> : jpeg options, with format <opt1>=<val1>[,<optn>=<valn>]*
-tiff : generate a TIFF file
-tiffcompression <string>: set TIFF compression: none, packbits, jpeg, lzw, deflate
-freetype <string> : enable FreeType font rasterizer: yes, no
-thinlinemode <string> : set thin line mode: none, solid, shape. Default: none
-aa <string> : enable font anti-aliasing: yes, no
-aaVector <string> : enable vector anti-aliasing: yes, no
-opw <string> : owner password (for encrypted files)
-upw <string> : user password (for encrypted files)
-q : don't print any messages or errors/<string>/<string>/<string>/<string>/<string>/<string>/<string>/<valn>/<optn>/<val1>/<opt1>/<string>
閱讀更多 IT充電寶 的文章