Skip to main content

Split SVG files to multiple pages, with margins and guides

Project description

SVGraft

SVGraft splits a large SVG file into a multipage PDF, tiling it across standard print pages with configurable margins and alignment corner marks. It is designed for printing oversized vector graphics — such as posters, banners, or blueprints — on ordinary home or office printers.


Features

  • Splits any SVG into a grid of tiles that each fit on a single page
  • Outputs a single merged PDF ready to print and assemble
  • Configurable page size, margins, and tile orientation
  • Automatic orientation optimization — chooses portrait or landscape to minimize page count
  • Corner alignment marks on every tile to aid physical assembly
  • Progress display and tile summary table via rich

Requirements

  • Python 3.9+
  • CairoSVG and its native Cairo library
  • See requirements.txt for the full list of Python dependencies

Install system dependencies (Debian/Ubuntu):

sudo apt-get install libcairo2-dev

Installation

pip install SVGraft

Or install it from source:

git clone https://github.com/deekb/SVGraft
cd SVGraft
pip install .

Usage

Command Line

svgraft [input_file] [options]
Argument Default Description
input_file ./input.svg Path to the input SVG file
-o, --output ./output_merged.pdf Path for the output PDF file
--page-width 8.5 Page width in inches
--page-height 11.0 Page height in inches
--margin 5.0 Margin on each page in millimeters

Examples:

Split a poster onto US Letter pages with default settings:

svgraft my_poster.svg

Use A4 pages with a 10 mm margin and a custom output path:

svgraft my_poster.svg --page-width 8.27 --page-height 11.69 --margin 10 -o poster_tiled.pdf

Python API

from svgraft.cli import split_svg

split_svg(
    input_file="my_poster.svg",
    page_width_in=8.5,
    page_height_in=11.0,
    margin_mm=6.35,
    output_file="output.pdf",
    optimize_tile_orientation=True,
)

SVG Requirements

The input SVG must have:

  • A viewBox attribute (e.g. viewBox="0 0 1200 900")
  • A width attribute defined in inches (in) or millimeters (mm)

Example SVG header:

<svg xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 2400 1800"
     width="24in" height="18in"/>

How It Works

  1. Parse the SVG and read its viewBox and physical dimensions to determine the internal units-per-inch scale.
  2. Compute tiles — calculate the grid of columns and rows needed so each tile fits within the usable page area (page size minus margins).
  3. Optimize orientation — if rotating tiles from portrait to landscape (or vice versa) produces fewer total pages, SVGraft automatically swaps the dimensions and re-tiles.
  4. Render tiles — for each grid cell, clip and translate the SVG, add corner alignment triangles and a dashed border, then render to PDF via CairoSVG.
  5. Merge — all per-tile PDFs are merged into a single output PDF using pypdf.

Assembly

Each page includes:

  • Corner triangles at the four content corners for precise cut-and-align assembly
  • A dashed border showing the exact content boundary

To assemble a print: trim half of the pages to their dashed border, then align them to the corner marks of the adjacent tiles.


Configuration Defaults

Defaults are defined in src/svgraft/config.py:

Setting Default Description
DEFAULT_PAGE_WIDTH_IN 8.5 Page width (inches)
DEFAULT_PAGE_HEIGHT_IN 11.0 Page height (inches)
DEFAULT_MARGIN_MM 5.0 Per-page margin
DEFAULT_CORNER_TRIANGLE_MM 5 Size of corner alignment triangles
DEFAULT_CORNER_STROKE_MM 0.1 Stroke width of corner marks
OPTIMIZE_TILE_ORIENTATION True Auto-flip orientation for fewer pages

Running Tests

pip install pdf2image
python -m unittest tests/testSVGraft.py

The test is currently quite simple and splits tests/input/test_poster.svg onto US Letter pages and verifies the output PDF is created.


Project Structure

SVGraft/
├── src/svgraft/
│   ├── cli.py          # Entry point: argument parsing and split_svg()
│   ├── config.py       # Default settings
│   ├── tiling.py       # Tile grid computation
│   ├── rendering.py    # Per-tile SVG manipulation and PDF rendering
│   ├── pdf.py          # In-memory PDF merging
│   ├── svg_io.py       # SVG unit parsing
│   ├── geometry.py     # Unit conversion utilities
│   └── debug.py        # Debug/console helpers
├── tests/
│   ├── input/test_poster.svg
│   ├── output/
│   └── testSVGraft.py
├── pyproject.toml
└── requirements.txt

License

This project is licensed under the GNU General Public License v3.0 or later. See LICENSE for details.


Author

Derek Baier — derek.m.baier@gmail.com

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

svgraft-0.0.2.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

svgraft-0.0.2-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file svgraft-0.0.2.tar.gz.

File metadata

  • Download URL: svgraft-0.0.2.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for svgraft-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c55ba18adcc0c54648be13d97b89f0e93e9c9d8ddfcac30416e329385348524b
MD5 215b2c213bfcb9b34b9ee1cd6c87208b
BLAKE2b-256 13a79671e6186a4863c633de995f41ede1112ae23f9d979aeb7f0353f8cd5a5f

See more details on using hashes here.

File details

Details for the file svgraft-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: svgraft-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for svgraft-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 72a371233f6310a8dddf5c89b6b775218c87422cd145569c63e6ced4e0359b28
MD5 985eb1c2069b32b4404f41111dec2fbc
BLAKE2b-256 a685afbb60d3f321fca1c05650a3bb627106831f22b155499abcd5de1e26453d

See more details on using hashes here.

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