Skip to main content

Python bindings for shapdf - Create Shapes into PDF

Project description

pyshapdf

Python bindings for shapdf - Create Shapes into PDF

Efficient programmable generation of shapes in PDF using Rust and Python.

Installation

pip install pyshapdf

Quick Start

import pyshapdf

script = """
page letter
circle 100mm 150mm 20mm color=blue
rectangle 50mm 50mm 40mm 30mm color=green angle=45deg anchor=center
line 50mm 200mm 150mm 250mm width=2mm color=red cap=round
"""

pyshapdf.render_script(script, "output.pdf")

Script Syntax

The .shapdf script language supports:

Page Commands

page default                    # Default page size
page letter                     # US Letter (8.5" × 11")
page letter-landscape           # US Letter landscape
page a4                         # A4 (210mm × 297mm)
page a4-landscape               # A4 landscape
page size 200mm 300mm           # Custom size

Shape Commands

# Circle
circle <x> <y> <radius> [color=...]

# Rectangle
rectangle <x> <y> <width> <height> [color=...] [anchor=...] [angle=...]

# Line
line <x1> <y1> <x2> <y2> [width=...] [color=...] [cap=...]

Settings

set default_page_size 200mm 300mm
set default_width 2mm
set default_color blue
set default_cap round           # butt | round | square
set default_angle 45deg         # or 0.785rad

Units

  • mm - millimeters
  • cm - centimeters
  • in - inches
  • pt - points (1/72 inch)
  • deg - degrees (default for angles)
  • rad - radians

Colors

  • Named colors: red, green, blue, yellow, black, white, gray
  • Hex: #RRGGBB (e.g., #ff0000)
  • RGB: rgb(255, 0, 0)
  • Grayscale: gray(0.5)

Anchor Points (for rectangles)

  • bottomleft (default)
  • center
  • topleft, topright, bottomright
  • midleft, midright, midbottom, midtop

API Reference

render_script(script: str, output_path: str) -> None

Render a .shapdf script to a PDF file.

Parameters:

  • script (str): The .shapdf script content
  • output_path (str): Path to write the output PDF file

Raises:

  • RuntimeError: If PDF generation fails

Examples

Multi-page Document

import pyshapdf

script = """
# Page 1 - Circles
page letter
circle 100mm 150mm 30mm color=blue
circle 150mm 150mm 30mm color=red

# Page 2 - Rectangles
page a4
rectangle 105mm 148.5mm 50mm 40mm color=green anchor=center angle=30deg
"""

pyshapdf.render_script(script, "multi_page.pdf")

Technical Drawing

import pyshapdf

script = """
page size 200mm 150mm
set default_width 0.5mm
set default_color black

# Grid lines
line 20mm 20mm 180mm 20mm
line 20mm 50mm 180mm 50mm
line 20mm 80mm 180mm 80mm
line 20mm 110mm 180mm 110mm

line 20mm 20mm 20mm 110mm
line 50mm 20mm 50mm 110mm
line 100mm 20mm 100mm 110mm
line 150mm 20mm 150mm 110mm
line 180mm 20mm 180mm 110mm

# Highlight
circle 100mm 65mm 2mm color=red
rectangle 85mm 50mm 30mm 30mm color=#0066ff anchor=center angle=0deg
"""

pyshapdf.render_script(script, "technical.pdf")

Links

License

GPL-3.0-or-later

© 2025 Teddy van Jerry (Wuqiong Zhao)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyshapdf-0.2.1.tar.gz (89.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyshapdf-0.2.1-cp312-cp312-win_amd64.whl (175.7 kB view details)

Uploaded CPython 3.12Windows x86-64

pyshapdf-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl (316.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pyshapdf-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (274.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file pyshapdf-0.2.1.tar.gz.

File metadata

  • Download URL: pyshapdf-0.2.1.tar.gz
  • Upload date:
  • Size: 89.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyshapdf-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5bb7c9f9dd20243738162600a240383e109be9fdc3ef6c040d0f1e6b9940dd1b
MD5 46277f48dd72b32b244fff475afee508
BLAKE2b-256 18377bcda1fc8fbd18774f516c55c02514ceeeadecbc298f985eaaac07c09d10

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyshapdf-0.2.1.tar.gz:

Publisher: python-publish.yml on Teddy-van-Jerry/shapdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyshapdf-0.2.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyshapdf-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 175.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyshapdf-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 083dbd14081fad52bcd369efe81c9de617277577e37caf97b946a306b0913894
MD5 147a8304acfd90de7d49637b214907b9
BLAKE2b-256 7abaccb72cb4ed5eac8ec5fd94dac6fe1667706c80427b6f984949560a693934

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyshapdf-0.2.1-cp312-cp312-win_amd64.whl:

Publisher: python-publish.yml on Teddy-van-Jerry/shapdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyshapdf-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyshapdf-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e6db5bdc0b48cefd622a4b77bf89f2cd89811caa501bc64ba6d354f1258ff8ab
MD5 19590d37df67d81b038c33a80d0d8b36
BLAKE2b-256 8b8c83f208dfaafe2b4dc15ab2464d6fbad49d2df79282b539397a807127d732

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyshapdf-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: python-publish.yml on Teddy-van-Jerry/shapdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyshapdf-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyshapdf-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9acd7aebeb42fe74fbade2ab43c3a9f70ce76b8cdecfc790be10409ff1765911
MD5 f6e6f430fda8fdce5517ffa2e422592b
BLAKE2b-256 ea218e3b37f598c3e151ea4a912cd4fc18ce9dc0ce029bdf535f9c37a2ac80a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyshapdf-0.2.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on Teddy-van-Jerry/shapdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page