-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple script to test the --layout feature with different confi…
…gurations, ensuring basic functionality and output verification.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |