pdfcrate 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8895658522be956bec8bc47ab1e8116564bb96d265319c3b45b9b067aeac5a32
4
+ data.tar.gz: e29951729a289b339a23d45620ea6048ca584663fc4664f5dfe8b22dbebbd9c8
5
+ SHA512:
6
+ metadata.gz: 58b64f6606cf2c17933dd79515d6f22e9755910bac69751757b40dbec437251e0a59204094eb7d2bd6318828484d6b00efc230929c3ad622dd72cbb83f0fb6ce
7
+ data.tar.gz: 3fcba47bff5c6b599e337baf7970d0973bcbe31fa2482821a0967707a4def84faf30d4147cd83469b4627718bc5cbf778f0f9d64339fe0bccd71ae2199e15203
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake-compiler", "~> 1.2"
8
+ gem "rake-compiler-dock", "~> 1.3"
9
+ gem "rb_sys", "~> 0.9.124"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 pdfcrate contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # pdfcrate
2
+
3
+ > **Warning**: This project is under active development. The API is unstable and subject to breaking changes. **Do not use in production environments.**
4
+
5
+ A Rust library for creating and manipulating PDF documents with a focus on ease of use and comprehensive text layout support.
6
+
7
+ ## Features
8
+
9
+ - **Layout-based document creation** - Cursor-based layout with automatic text flow, margins, and bounding boxes
10
+ - **Rich text formatting** - Bold, italic, colors, alignment (left/center/right/justify)
11
+ - **Font support** - 14 standard PDF fonts + TrueType/OpenType embedding with text shaping
12
+ - **Font fallback** - Automatic fallback for mixed-language text (CJK, emoji, etc.)
13
+ - **Tables** - Full-featured tables with borders, cell styles, column spans, and overflow handling
14
+ - **Images** - PNG and JPEG embedding with fit/fill modes
15
+ - **SVG rendering** - Embed SVG graphics directly
16
+ - **Links and outlines** - Hyperlinks, internal links, and document bookmarks
17
+ - **Forms** - Interactive form fields (text, checkbox, radio, dropdown)
18
+ - **WASM support** - Works in WebAssembly environments (tested with Cloudflare Workers)
19
+ - **Python bindings** - Use pdfcrate from Python via PyO3
20
+
21
+ ## Installation
22
+
23
+ Add to your `Cargo.toml`:
24
+
25
+ ```toml
26
+ [dependencies]
27
+ pdfcrate = "0.1"
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```rust
33
+ use pdfcrate::prelude::*;
34
+
35
+ fn main() -> Result<(), Box<dyn std::error::Error>> {
36
+ Document::generate("hello.pdf", |doc| {
37
+ doc.title("Hello PDF").author("pdfcrate");
38
+
39
+ doc.font("Helvetica-Bold").size(24.0);
40
+ doc.text("Hello, World!");
41
+
42
+ doc.move_down(20.0);
43
+
44
+ doc.font("Helvetica").size(12.0);
45
+ doc.text_wrap("This is a simple PDF document created with pdfcrate. \
46
+ Text automatically wraps within the page margins.");
47
+
48
+ Ok(())
49
+ })?;
50
+
51
+ Ok(())
52
+ }
53
+ ```
54
+
55
+ ## Examples
56
+
57
+ ### Custom Fonts
58
+
59
+ ```rust
60
+ use pdfcrate::prelude::*;
61
+
62
+ Document::generate("custom_font.pdf", |doc| {
63
+ // Embed a TrueType font
64
+ let font = doc.embed_font_file("fonts/MyFont.ttf")?;
65
+
66
+ doc.font(&font).size(16.0);
67
+ doc.text("Text with custom font!");
68
+
69
+ Ok(())
70
+ })?;
71
+ ```
72
+
73
+ ### Font Fallback for CJK
74
+
75
+ ```rust
76
+ use pdfcrate::prelude::*;
77
+
78
+ Document::generate("multilingual.pdf", |doc| {
79
+ let cjk_font = doc.embed_font_file("fonts/NotoSansCJK.ttf")?;
80
+
81
+ // Configure fallback fonts
82
+ doc.fallback_fonts(vec![cjk_font]);
83
+
84
+ doc.font("Helvetica").size(14.0);
85
+ doc.text_wrap("English text mixed with 中文 and 日本語");
86
+
87
+ Ok(())
88
+ })?;
89
+ ```
90
+
91
+ ### Tables
92
+
93
+ ```rust
94
+ use pdfcrate::prelude::*;
95
+
96
+ Document::generate("table.pdf", |doc| {
97
+ let table = Table::new(&[100.0, 150.0, 100.0])
98
+ .header(&["Name", "Description", "Price"])
99
+ .row(&["Item 1", "First item", "$10.00"])
100
+ .row(&["Item 2", "Second item", "$20.00"])
101
+ .borders(BorderStyle::all(0.5, Color::BLACK));
102
+
103
+ doc.table(&table);
104
+
105
+ Ok(())
106
+ })?;
107
+ ```
108
+
109
+ ### Images
110
+
111
+ ```rust
112
+ use pdfcrate::prelude::*;
113
+
114
+ Document::generate("with_image.pdf", |doc| {
115
+ // Embed and draw image
116
+ doc.image_fit("photo.png", [0.0, 0.0], 200.0, 150.0)?;
117
+
118
+ Ok(())
119
+ })?;
120
+ ```
121
+
122
+ ## Python
123
+
124
+ pdfcrate provides Python bindings via [PyO3](https://pyo3.rs/) and [maturin](https://www.maturin.rs/).
125
+
126
+ ```bash
127
+ # Install in development mode
128
+ uv run maturin develop --features python
129
+
130
+ # Run the showcase
131
+ uv run python examples/showcase.py
132
+ ```
133
+
134
+ ```python
135
+ from pdfcrate import Document, Margin, Color, TextFragment
136
+
137
+ doc = Document(margin=Margin(36, 36, 36, 36))
138
+ doc.title("Hello from Python")
139
+
140
+ doc.font("Helvetica", 24)
141
+ doc.text("Hello, World!")
142
+
143
+ doc.move_down(20)
144
+ doc.font("Helvetica", 12)
145
+ doc.text("Created with pdfcrate Python bindings.")
146
+
147
+ doc.save("hello.pdf")
148
+ ```
149
+
150
+ ## Feature Flags
151
+
152
+ All features are pure Rust and WASM-compatible.
153
+
154
+ | Feature | Default | Description |
155
+ |---------|---------|-------------|
156
+ | `std` | Yes | Standard library support (file I/O) |
157
+ | `png` | Yes | PNG image support (JPEG is always supported) |
158
+ | `fonts` | Yes | TrueType/OpenType font embedding |
159
+ | `text-shaping` | Yes | Complex text shaping via rustybuzz |
160
+ | `svg` | Yes | SVG rendering support |
161
+ | `barcode` | Yes | QR code and barcode generation |
162
+ | `python` | No | Python bindings (PyO3) |
163
+
164
+ To use minimal features:
165
+
166
+ ```toml
167
+ [dependencies]
168
+ pdfcrate = { version = "0.1", default-features = false }
169
+ ```
170
+
171
+ ## Minimum Supported Rust Version (MSRV)
172
+
173
+ Rust 1.87 or later.
174
+
175
+ ## License
176
+
177
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "pdfcrate-ruby"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ name = "pdfcrate"
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ magnus = "0.7"
12
+ rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
13
+ pdfcrate = { path = "../..", features = ["full"] }
14
+
15
+ [build-dependencies]
16
+ rb-sys = "0.9.124"
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+ require "rb_sys/mkmf"
3
+ create_rust_makefile("pdfcrate/pdfcrate")