A Python script that adds coordinate grid lines to PDF documents, created by kahvecci (22.12.2024).
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
- Python 3.x
- PyMuPDF (fitz)
pip install PyMuPDF
- Place your input PDF in the same directory as the script
- Update the input PDF filename in the script (currently set to "1.pdf")
- 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.
The draw_guide_lines
function accepts the following parameters:
increment
(default: 50): Distance between grid lines in pointscolor
(default: (1, 0, 0)): RGB color tuple for grid lineswidth
(default: 1.4): Line widthopacity
(default: 0.8): Line opacity (0-1)coor
(default: True): Whether to show coordinate labels
# 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)
WIDTH = 595.5
: PDF page width in points (A4)HEIGHT = 842.25
: PDF page height in points (A4)
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"
- 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
MIT LICENSE
kahvecci
07.01.2025
*this readme.md file generated by AI.