Open
Conversation
…or flexible page layouts.
… 1x2, 2x1) without impacting default behavior.
…gurations, ensuring basic functionality and output verification.
Author
Merged
--layout Parameter--layout Parameter
MartinThoma
reviewed
Dec 8, 2024
Comment on lines
+15
to
+36
| # 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) |
Member
There was a problem hiding this comment.
We use pytest as a test suite to automatically run the tests and check if they succeeded.
Pytest looks for functions starting with "test_"
Suggested change
| # 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) | |
| def test_layout_option(): | |
| # 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) |
MartinThoma
reviewed
Dec 8, 2024
| writer.add_page(page) | ||
|
|
||
| with open(output, "wb") as f_out: | ||
| writer.write(f_out) No newline at end of file |
Member
There was a problem hiding this comment.
Suggested change
| writer.write(f_out) | |
| writer.write(f_out) | |
MartinThoma
reviewed
Dec 8, 2024
Comment on lines
+38
to
+44
| # Define layout configurations (columns, rows) for each grid type | ||
| layout_options = { | ||
| "2x2": (2, 2), | ||
| "3x3": (3, 3), | ||
| "1x2": (1, 2), | ||
| "2x1": (2, 1) | ||
| } |
Member
There was a problem hiding this comment.
What is the reason to restrict the layout options? Wouldn't any XxY with X and Y being positive integers work?
--layout Parameter--layout parameter to up2
Member
|
Thank you for your contribution! |
Member
|
Could you please run |
MartinThoma
reviewed
Dec 8, 2024
Member
There was a problem hiding this comment.
You could add this test to test_up2.py
Member
|
@mulla028 Sorry that it took me a month to review 🙈 If you want, I would clean-up the remaining parts. Just let me know if you want to finish it yourself or not :-) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #64
Overview
This PR introduces an optional
--layoutparameter to theup2command, allowing users to arrange PDF pages in configurable grid layouts. Supported layouts include:If
--layoutis not specified, the command defaults to the original behavior, ensuring full backward compatibility.Changes
up2.py:up2_mainfunction to manage both default behavior and specified layouts.mediaboxfor compatibility with recent versions ofpypdf.mainfunction for backward compatibility, though future calls should useup2_main.cli.py:up2command to callup2_mainwith an optional--layoutparameter for layout configurations.Testing
To test each layout configuration, run the following commands: