Skip to content

added pdf_border_frame #1019

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Updated pdf_border_frame.py
  • Loading branch information
sk5268 authored May 5, 2025
commit dba41685d22197f4f23de50c75b8bb963f2ec0aa
18 changes: 11 additions & 7 deletions pdf_border_frame/pdf_border_frame.py
Original file line number Diff line number Diff line change
@@ -4,9 +4,11 @@
import os

def add_frame(input_pdf_path, left=20, right=20, top=20, bottom=20, thickness=2):


try:
doc = fitz.open(input_pdf_path)

for page_num in range(len(doc)):
page = doc[page_num]
page_rect = page.rect
@@ -17,21 +19,21 @@ def add_frame(input_pdf_path, left=20, right=20, top=20, bottom=20, thickness=2)
page_rect.width - right, # right
page_rect.height - bottom # bottom
)

page.draw_rect(
frame_rect, # rectangle coordinates
width=thickness # frame thickness
)

# Set output filename if not provided

base, ext = os.path.splitext(input_pdf_path)
output_pdf_path = f"{base}_framed.pdf"

doc.save(output_pdf_path)
print(f"PDF with rectangle frame saved to {output_pdf_path}")
except UnicodeDecodeError as e:

except UnicodeDecodeError:
print("Error: Input file path encoding issue. Please ensure the file path is UTF-8 encoded.")
except Exception as e:
print(f"An error occurred: {e}")
@@ -40,6 +42,8 @@ def add_frame(input_pdf_path, left=20, right=20, top=20, bottom=20, thickness=2)
doc.close()

if __name__ == "__main__":


parser = argparse.ArgumentParser(
description="Add a rectangle frame to each page of a PDF document.\n"
"Flags: --l (left), --r (right), --t (top), --b (bottom), --th (thickness)",
@@ -64,4 +68,4 @@ def add_frame(input_pdf_path, left=20, right=20, top=20, bottom=20, thickness=2)
except Exception as e:
print(f"Error: {e}\n")
parser.print_usage()
sys.exit(1)
sys.exit(1)
Loading
Oops, something went wrong.