Skip to content

Commit

Permalink
Add a simple script to test the --layout feature with different confi…
Browse files Browse the repository at this point in the history
…gurations, ensuring basic functionality and output verification.
  • Loading branch information
mulla028 committed Oct 31, 2024
1 parent 2cf9c27 commit e862aae
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_up2_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
from pathlib import Path
from pypdf import PdfReader
from pdfly.up2 import up2_main

# Create a simple 6-page blank PDF for testing
def create_test_pdf(file_path, num_pages=6):
from pypdf import PdfWriter
writer = PdfWriter()
for _ in range(num_pages):
writer.add_blank_page(width=210, height=297) # A4 size in mm
with open(file_path, "wb") as f:
writer.write(f)

# File paths for the input and output PDFs
input_pdf = Path("test_input.pdf")
output_pdf = Path("test_output.pdf")

# Create the test PDF
create_test_pdf(input_pdf)

# List of layouts to test
layouts = ["2x2", "3x3", "1x2", "2x1"]
for layout in layouts:
print(f"\nTesting layout: {layout}")
up2_main(input_pdf, output_pdf, layout=layout)

# Read the output PDF and print the number of pages
reader = PdfReader(str(output_pdf))
print(f"Output PDF for layout {layout} has {len(reader.pages)} pages.")

# Clean up
if output_pdf.exists():
os.remove(output_pdf)
if input_pdf.exists():
os.remove(input_pdf)

0 comments on commit e862aae

Please sign in to comment.