Splitting a Single Page into Three Pages Using Google Colab
In January, many businesses file 1099 forms. The payroll program we use generates 1099 forms with three forms printed on a single page, like the image on the left below. However, when emailing these forms to individual contractors, each form must be separated into its own page, as shown on the right.


For companies with over 50 forms, this manual editing process can take a significant amount of time. To address this, I created a solution using Google Colab and a PDF library. The code automatically splits a single page containing three forms into three separate pages, making the process much faster and more efficient.
Colab Code
Below is the Colab code used to accomplish this. Each block of code was executed step by step. You can customize the output file name, as highlighted in red, to suit your needs.
!pip install PyPDF2
!pip install PyMuPDF
from google.colab import files
uploaded = files.upload()
output_interleaved_pdf = "Output_interleaved_pdfs.pdf" #================================== Can change output file name
input_pdf_file = next(iter(uploaded))
with open(input_pdf_file, 'rb') as f:
content = f.read()
import fitz # PyMuPDF
def crop_pdf(input_pdf, output_pdf, box):
# Open the input PDF file
pdf_document = fitz.open(input_pdf)
# Crop each page in the PDF
for page_num in range(pdf_document.page_count):
page = pdf_document.load_page(page_num)
page.set_cropbox(box) # Corrected method name
# Save the modified PDF to a new file
pdf_document.save(output_pdf)
pdf_document.close()
# Example crop box (left, top, right, bottom) - adjust as needed
crop_box = (0, 0, 600, 270)
# Call the function with your PDF file and desired crop box
#input_pdf_file = "PrintForm1099.pdf" # Replace with your input PDF file
output_pdf_file = "output_cropped.pdf" # Replace with the desired output file name
crop_pdf(input_pdf_file, output_pdf_file, crop_box)
crop_box_1 = (0, 270, 600, 540)
# Call the function with your PDF file and desired crop box
#input_pdf_file = "PrintForm1099.pdf" # Replace with your input PDF file
output_pdf_file = "output_cropped_1.pdf" # Replace with the desired output file name
crop_pdf(input_pdf_file, output_pdf_file, crop_box_1)
crop_box_2 = (0,535,600, 780)
# Call the function with your PDF file and desired crop box
#input_pdf_file = "PrintForm1099.pdf" # Replace with your input PDF file
output_pdf_file = "output_cropped_2.pdf" # Replace with the desired output file name
crop_pdf(input_pdf_file, output_pdf_file, crop_box_2)
def interleave_pages(output_pdf, *input_pdfs):
merged_pdf = fitz.open() # Create a new PDF document
page_counts = [fitz.open(pdf).page_count for pdf in input_pdfs]
max_pages = max(page_counts)
for page_num in range(max_pages):
for pdf_path in input_pdfs:
pdf = fitz.open(pdf_path)
if page_num < pdf.page_count:
merged_pdf.insert_pdf(pdf, from_page=page_num, to_page=page_num)
merged_pdf.save(output_pdf) # Save the interleaved PDF
merged_pdf.close()
# Paths to the PDFs to be interleaved
pdf_1 = "output_cropped.pdf"
pdf_2 = "output_cropped_1.pdf"
pdf_3 = "output_cropped_2.pdf"
# Output file name for the interleaved PDF
# Call the function to interleave the pages of the PDFs
interleave_pages(output_interleaved_pdf, pdf_1, pdf_2, pdf_3)
# Trigger the download
files.download(output_interleaved_pdf)
* I want to emphasize that I am not a coding expert, and this code was created specifically to achieve the results I needed. It’s not a professional-level solution, and there may be better methods out there. However, this approach is designed for people who, like me, aren’t well-versed in coding but still want to simplify repetitive tasks.
Youtube Video
You can find a detailed explanation and step-by-step guide in the YouTube video linked below.