One of the great benefits of using Linux is that you can have a variety of software, which is free and convenient to implement various functions. Today, let's talk about how to convert PDF to IMG.
1. Operating System
- Operating system:
debian 12
2. PDF to IMG
2.1 Software name
pdftoppm
2.2 Software installation
- Open the terminal and enter the following command
sudo apt install poppler-utils
2.3 Software use
- Convert
test.pdf
file: Open the terminal and enter the following command, and finally get the picturestest-1.png
andtest-2.png
, where 1 and 2 are the page numbers of the test.pdf file.
pdftoppm test.pdf test -png
- If you want to use python to batch convert all pdf files in the
/tmp/test/
directory, the entire code is as follows:
#!/usr/bin/python3
import os
os.chdir('/tmp/test/')
hehe = os.popen('ls').readlines()
for pdf in hehe:
pdf = pdf.rstrip('\n')
print(pdf)
os.system(f'pdftoppm {pdf} {pdf} -png')