2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonでPDFを画像(JPEG/PNG)化

Last updated at Posted at 2020-02-06

PDFの全ページを1枚ずつPNG画像にしてoutputフォルダ(作成済み)に入れたい。

sample.py

from pdf2image import convert_from_path

convert_from_path(
    'sample.pdf',            #入力PDF
    dpi=300,                 #解像度
    output_folder='output',  #出力フォルダ
    output_file='out',       #出力ファイルprefix
    fmt='png'                #フォーマット
)

これでoutputフォルダにout0001-01.png ... out0001-16.pngのようなファイルができる。pdf2image 1.11.0

メモ

  • grayscale=True指定でグレースケールにもできる
  • size=400指定すると、縦横比を保ったまま長いほうの辺を400ピクセルにしてくれる
  • PNG出力は結構時間がかかる。JPEGなら速い。
  • SSDを使ってる場合はoutput_folder指定により高速化を期待できる
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?