Skip to content

Commit e862aae

Browse files
committed
Add a simple script to test the --layout feature with different configurations, ensuring basic functionality and output verification.
1 parent 2cf9c27 commit e862aae

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_up2_layout.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
from pathlib import Path
3+
from pypdf import PdfReader
4+
from pdfly.up2 import up2_main
5+
6+
# Create a simple 6-page blank PDF for testing
7+
def create_test_pdf(file_path, num_pages=6):
8+
from pypdf import PdfWriter
9+
writer = PdfWriter()
10+
for _ in range(num_pages):
11+
writer.add_blank_page(width=210, height=297) # A4 size in mm
12+
with open(file_path, "wb") as f:
13+
writer.write(f)
14+
15+
# File paths for the input and output PDFs
16+
input_pdf = Path("test_input.pdf")
17+
output_pdf = Path("test_output.pdf")
18+
19+
# Create the test PDF
20+
create_test_pdf(input_pdf)
21+
22+
# List of layouts to test
23+
layouts = ["2x2", "3x3", "1x2", "2x1"]
24+
for layout in layouts:
25+
print(f"\nTesting layout: {layout}")
26+
up2_main(input_pdf, output_pdf, layout=layout)
27+
28+
# Read the output PDF and print the number of pages
29+
reader = PdfReader(str(output_pdf))
30+
print(f"Output PDF for layout {layout} has {len(reader.pages)} pages.")
31+
32+
# Clean up
33+
if output_pdf.exists():
34+
os.remove(output_pdf)
35+
if input_pdf.exists():
36+
os.remove(input_pdf)

0 commit comments

Comments
 (0)