Skip to content

Instantly share code, notes, and snippets.

@michabbb
Created November 2, 2024 20:53
Show Gist options
  • Save michabbb/05bf3f300bc383c888ff5c0bb8574611 to your computer and use it in GitHub Desktop.
Save michabbb/05bf3f300bc383c888ff5c0bb8574611 to your computer and use it in GitHub Desktop.
split a large pdf into individual files
#!/bin/bash
# Input PDF file
input_pdf="sample_document.pdf"
# Output files with dates
insurance_policy="car_insurance_2024-11-05.pdf"
bank_statement="bank_statement_2024-11.pdf"
medical_invoice_oct="medical_invoice_2024-10-21.pdf"
medical_invoice_nov="medical_invoice_2024-11-03.pdf"
utility_bill="electric_bill_2024-11-10.pdf"
investment_report="investment_report_2024-11-15.pdf"
# Splitting PDF pages with pdftk
pdftk "$input_pdf" cat 1-2 output "$insurance_policy"
pdftk "$input_pdf" cat 3-4 output "$bank_statement"
pdftk "$input_pdf" cat 5-6 output "$medical_invoice_oct"
pdftk "$input_pdf" cat 7-8 output "$medical_invoice_nov"
pdftk "$input_pdf" cat 9-12 output "$utility_bill"
pdftk "$input_pdf" cat 13-15 output "$investment_report"
echo "PDFs split successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment