-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README.md smaller doc -> letter size conversion CLI Remove ConvertToLetterSize.egg-info directory from repo Update README.md Update README.md Update README.md Update README.md Update git ignore
- Loading branch information
Showing
6 changed files
with
83 additions
and
1 deletion.
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,2 @@ | ||
venv/ | ||
*.egg-info/ |
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 |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# a4tolettersize | ||
Convert A4 document to letter size while maintaining size and proportion | ||
Convert smaller format pdf document to letter size while maintaining size and proportion of content. | ||
|
||
This will resize the pages in the document to letter size and center the existing content. | ||
Content will maintain its absolute size and proportions when printed. | ||
|
||
This tool was created to convert old sewing pattern PDFs to US letter size, allowing me to print them at a US print shop. | ||
|
||
## how to use | ||
To use for yourself, first clone this repository and `cd` to it: | ||
```cmd | ||
git clone https://github.com/cpparnell/converttolettersize.git | ||
cd converttolettersize | ||
``` | ||
Then, install the command line tool: | ||
```cmd | ||
pip install . | ||
``` | ||
Finally, you can convert from smaller formats to letter size using: | ||
```cmd | ||
converttolettersize /path/to/input/file.pdf /path/to/output/file.pdf | ||
``` |
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 @@ | ||
from .convert import convert_to_lettersize |
Binary file not shown.
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,44 @@ | ||
#!/usr/bin/env python3 | ||
import click | ||
import fitz # Import PyMuPDF | ||
|
||
# Define the conversion function with click decorators for CLI integration | ||
@click.command() | ||
@click.argument('input_file', type=click.Path(exists=True)) | ||
@click.argument('output_file', type=click.Path()) | ||
def convert_to_lettersize(input_file: str, output_file: str) -> None: | ||
""" | ||
Converts PDF document to Letter size, preserving the content's size and proportions. | ||
""" | ||
letter_size = [612, 792] # Letter size in points (8.5 x 11 inches) | ||
new_doc = fitz.open() # Create a new empty document | ||
|
||
with fitz.open(input_file) as doc: | ||
for page in doc: | ||
original_rect = page.rect | ||
scale = 1 # Default scale is 1 (no scaling) | ||
|
||
# Calculate the new width and height based on scaling | ||
new_width = original_rect.width * scale | ||
new_height = original_rect.height * scale | ||
|
||
# Calculate translation to center the content | ||
translate_x = (letter_size[0] - new_width) / 2 | ||
translate_y = (letter_size[1] - new_height) / 2 | ||
|
||
# Create a new page with Letter dimensions | ||
new_page = new_doc.new_page(width=letter_size[0], height=letter_size[1]) | ||
|
||
# Define the target rectangle for the scaled and centered content | ||
target_rect = fitz.Rect(translate_x, translate_y, translate_x + new_width, translate_y + new_height) | ||
|
||
# Insert the scaled and centered content of the current page into the new page | ||
new_page.show_pdf_page(target_rect, doc, page.number) | ||
|
||
# Save the new document | ||
new_doc.save(output_file) | ||
click.echo(f"Converted file saved to {output_file}") | ||
|
||
if __name__ == '__main__': | ||
convert_to_lettersize() | ||
|
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,15 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='ConvertToLetterSize', | ||
version='0.1', | ||
py_modules=['converttolettersize'], | ||
install_requires=[ | ||
'Click', | ||
'PyMuPDF', | ||
], | ||
entry_points=''' | ||
[console_scripts] | ||
converttolettersize=convert:convert_to_lettersize | ||
''', | ||
) |