This Python script extracts the first page of one or more PDF files and saves it as a PNG image file with the same name as the input PDF file.
- You need Python 3.x
sudo apt-get install poppler-utils
- If you want to use a virtual environment (optional):
python3 -m venv venv
andsource venv/bin/activate
pip install -r requirements.txt
To extract the cover photo from a PDF file, run the script with the file name as an argument:
python PDF_cover_extractor.py input_file.pdf
To extract the cover photos from multiple PDF files, provide the file names as multiple arguments:
python PDF_cover_extractor.py input_file1.pdf input_file2.pdf input_file3.pdf
The script will extract the first page of each PDF file and save it as a PNG image file with the same name as the input PDF file, but with the .png
file extension.
This script uses the pdf2image
package to convert PDF pages to images and the PyPDF2
package to read input PDF files and write output PDF files. It also uses the argparse
module to parse command-line arguments.
This script is released under the MIT License. Feel free to use, modify, and distribute it as needed.