Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flexible PDF Layout Options with --layout Parameter #67

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mulla028
Copy link

@mulla028 mulla028 commented Oct 30, 2024

Closes #64

Overview

This PR introduces an optional --layout parameter to the up2 command, allowing users to arrange PDF pages in configurable grid layouts. Supported layouts include:

  • 2x2: 2 columns, 2 rows per page
  • 3x3: 3 columns, 3 rows per page
  • 1x2: 1 column, 2 rows per page
  • 2x1: 2 columns, 1 row per page

If --layout is not specified, the command defaults to the original behavior, ensuring full backward compatibility.

Changes

  1. up2.py:

    • Added a new up2_main function to manage both default behavior and specified layouts.
    • Updated page dimension access to mediabox for compatibility with recent versions of pypdf.
    • Retained the original main function for backward compatibility, though future calls should use up2_main.
  2. cli.py:

    • Modified the up2 command to call up2_main with an optional --layout parameter for layout configurations.
    • Retained all original commands and functionality to ensure no changes to existing CLI behavior.

Testing

To test each layout configuration, run the following commands:

# Default behavior (no layout specified)
python cli.py up2 path/to/input.pdf path/to/output_default.pdf

# 2x2 layout
python cli.py up2 path/to/input.pdf path/to/output_2x2.pdf --layout 2x2

# 3x3 layout
python cli.py up2 path/to/input.pdf path/to/output_3x3.pdf --layout 3x3

# 1x2 layout
python cli.py up2 path/to/input.pdf path/to/output_1x2.pdf --layout 1x2

# 2x1 layout
python cli.py up2 path/to/input.pdf path/to/output_2x1.pdf --layout 2x1

@mulla028
Copy link
Author

@Lucas-C
I have written yesterday a test for --layout feature, but wasn't sure if you need it. According to your recent feedback in Issue #63, I found that you would like to see some tests. Eventually, I just pushed it 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: pdfly x2pdf --layout
1 participant