PDF CLI is a command-line tool for manipulating PDF documents. It allows you to merge multiple PDF files into one and split a PDF into multiple files based on specified page ranges.
- Merge PDFs: Combine multiple PDF files into a single document.
- Split PDFs: Divide a PDF into several smaller PDFs based on page ranges.
To use PDF CLI, ensure you have Python 3.12 or higher installed. You can install the required dependencies using pip:
pip install pikepdfAlternatively, you can use a tool like Poetry to manage dependencies as specified in the pyproject.toml file:
poetry installTo create a docs directory and include processed PDF documents, you can follow these steps:
-
Create the
docsDirectory:Open your terminal and navigate to the root directory of your project. Then, execute the following command to create the
docsdirectory:mkdir docs
-
Update Your Scripts:
Ensure that the paths in your scripts (
join-page.pyandsplit-page.py) correctly point to thedocsdirectory for both input and output PDF files. For example, theoutput_pdfinjoin-page.pyshould be:output_pdf = 'docs/results.pdf'
Similarly, in
split-page.py, make sure thefilenamevariable points to a PDF within thedocsdirectory:filename = "./docs/xxx.pdf"
-
Place Processed PDF Documents:
After running your scripts, the output PDF files will be saved in the
docsdirectory. This keeps your project organized and makes it easier to locate processed documents.
By following these steps, you ensure that all processed PDF files are stored in the docs directory, maintaining a clean and organized project structure. If you want to include sample PDFs or any initial files, you can manually place them in the docs directory as well.
The join-page.py script merges multiple PDF files. You can specify the input PDF files and the output file path within the script:
# List of PDF files to be merged
input_pdfs = ['0.pdf', '1.pdf', '2.pdf', '3.pdf', '4.pdf']
# Output file name
output_pdf = 'docs/xx/results.pdf'Run the script using Python:
python join-page.pyThe split-page.py script splits a PDF into multiple files. You can configure the page ranges for each split within the script:
# a dictionary mapping PDF file to original PDF's page range
file2pages = {
0: [0, 1], # Pages 0 to 1
1: [2, 3], # Pages 2 to 3
}
# the target PDF document to split
filename = "./docs/xxx.pdf"Run the script using Python:
python split-page.py- Add
main.pyto handle argument CLI
This project is licensed under the MIT License. See the LICENSE file for details.
- Utilizes the pikepdf library for PDF manipulation.