Skip to content

kahvecci/rect-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

PDF Grid Guide Generator

A Python script that adds coordinate grid lines to PDF documents, created by kahvecci (22.12.2024).

Description

This script overlays a coordinate grid system on PDF pages, featuring:

  • Primary grid lines with coordinate labels at intersections
  • Optional secondary grid lines for more precise measurements
  • Customizable grid spacing, colors, and opacity
  • Coordinate labels at intersection points

Requirements

  • Python 3.x
  • PyMuPDF (fitz)
pip install PyMuPDF

Usage

  1. Place your input PDF in the same directory as the script
  2. Update the input PDF filename in the script (currently set to "1.pdf")
  3. Run the script:
python grid_guide.py <pdf_file>
python grid_guide.py example.pdf

The script will generate a new PDF named "output_grid.pdf" with the grid overlay.

Parameters

The draw_guide_lines function accepts the following parameters:

  • increment (default: 50): Distance between grid lines in points
  • color (default: (1, 0, 0)): RGB color tuple for grid lines
  • width (default: 1.4): Line width
  • opacity (default: 0.8): Line opacity (0-1)
  • coor (default: True): Whether to show coordinate labels

Example

# Draw main grid lines with coordinates
draw_guide_lines()

# Draw secondary grid lines without coordinates
draw_guide_lines(increment=10, color=(0, 0, 0), width=0.5, opacity=0.5, coor=False)

Constants

  • WIDTH = 595.5: PDF page width in points (A4)
  • HEIGHT = 842.25: PDF page height in points (A4)

Output

The script generates:

  • Primary grid lines (red by default) with 50-point spacing
  • Secondary grid lines (black by default) with 10-point spacing
  • Coordinate labels at primary grid intersections
  • A new PDF file named "output_grid.pdf"

Notes

  • Coordinates are displayed in the format (x,y)
  • Coordinate labels are offset slightly from intersection points for better visibility
  • The script is configured for A4 page size by default

License

MIT LICENSE

Author

kahvecci

Last Updated

07.01.2025

*this readme.md file generated by AI.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages