Generate Tianzige (田字格) writing grid PDFs for Chinese character practice
Project description
Tianzige (田字格)
A Python tool to generate Tianzige (田字格) writing grid PDFs for Chinese character practice.
Installation
pip install tianzige
Usage
Basic usage:
tianzige output.pdf
This will create a PDF file with default settings (A4 size, auto-calculated square size ensuring at least 10 boxes in each direction, gray lines, optimized margins).
Options
-c, --color: Line color in hex format (default: #808080)-p, --page-size: Page size (choices: a4, a5, a6, a3, b4, b5, letter, legal) (default: a4)-s, --size: Size of each square in mm (default: auto-calculated to ensure minimum boxes)--min-horizontal: Minimum number of horizontal boxes (default: 10 if size not specified)--min-vertical: Minimum number of vertical boxes (default: 10 if size not specified)--margin-top: Top margin in mm (default: 15)--margin-bottom: Bottom margin in mm (default: 15)--margin-left: Left margin in mm (default: 20)--margin-right: Right margin in mm (default: 10)--no-inner-grid: Disable inner grid lines-v, --version: Show version information
Square Size and Box Count Behavior
-
When no size or minimum boxes specified:
- Automatically calculates square size to fit at least 10 boxes in both directions
-
When only size specified:
- Uses the exact size specified
- No minimum box requirements enforced
-
When size and minimum boxes specified:
- Uses specified size
- Validates that minimum box requirements can be met
- Provides detailed error message if requirements cannot be met, showing:
- How many boxes would fit with the specified size
- What maximum size would allow the minimum box count
Examples
Generate grid with black lines:
tianzige -c "#000000" output.pdf
Generate A5-sized grid:
tianzige -p a5 output.pdf
Generate grid with custom square size (no minimum box requirement):
tianzige -s 25 output.pdf
Generate grid with at least 12 horizontal boxes:
tianzige --min-horizontal 12 output.pdf
Generate grid with specific requirements:
tianzige --min-horizontal 12 --min-vertical 15 -p a4 output.pdf
Generate grid without inner lines:
tianzige --no-inner-grid output.pdf
Generate A3-sized grid with black lines:
tianzige -p a3 -c "#000000" output.pdf
Python API
You can also use Tianzige in your Python code:
from tianzige import create_tianzige
create_tianzige(
"output.pdf",
line_color="#808080",
square_size=None, # Auto-calculated based on page size and minimum boxes
margin_top=15,
margin_bottom=15,
margin_left=20,
margin_right=10,
show_inner_grid=True,
page_size='a4', # Options: 'a4', 'a5', 'a6', 'a3', 'b4', 'b5', 'letter', 'legal'
min_horizontal=None, # Default: 10 if square_size is None
min_vertical=None # Default: 10 if square_size is None
)
Sample PDFs
The sample_pdf directory contains example outputs:
a5_example.pdf: A5-sized grid with default settingsblack_20mm.pdf: Grid with 20mm squares and black lines15x15_boxes.pdf: Grid with minimum 15 boxes in both directions
Development
Git Configuration
The repository includes a .gitignore file configured for Python development with specific rules for PDF files:
- Ignores all PDF files by default (
*.pdf) - Allows sample PDFs in the
sample_pdfdirectory (!sample_pdf/*.pdf) - Includes standard Python, virtual environment, and IDE ignores
License
MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tianzige-0.3.0.tar.gz.
File metadata
- Download URL: tianzige-0.3.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39b31a07c2b24c7ebcad7092978bf544db8aff17cd461f9e947373df66a3c3b6
|
|
| MD5 |
d0a158cd2d58e658ce95b14ff90f0baa
|
|
| BLAKE2b-256 |
968164b54f661457333a1cbf63a60a19aa62284188f177fa3532401f9f97bb3c
|
File details
Details for the file tianzige-0.3.0-py3-none-any.whl.
File metadata
- Download URL: tianzige-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff117f4d685fc9e9d8d0fd40eb1fd903a2e44f659c969448b2ee77ee87356769
|
|
| MD5 |
42d23b5fd00682bb0311c26bc3fa3ad4
|
|
| BLAKE2b-256 |
d26f8b691796a71197a2a5b37020da40e0b7a50a1e2b86d04878373c24f50317
|