I want to convert all pages of PDF into PNG images one by one and put them in the ʻoutput` folder (created).
sample.py
from pdf2image import convert_from_path
convert_from_path(
'sample.pdf', #Input PDF
dpi=300, #resolution
output_folder='output', #Output folder
output_file='out', #Output file prefix
fmt='png' #format
)
This will create a file like ʻout0001-01.png ... ʻout0001-16.png
in the ʻoutput` folder. pdf2image 1.11.0
Note
--Can be grayscale by specifying grayscale = True
--If you specify size = 400
, the longer side will be 400 pixels while maintaining the aspect ratio.
--PNG output takes a long time. JPEG is fast.
--If you are using SSD, you can expect speedup by specifying ʻoutput_folder`.
Recommended Posts