1 unstable release
0.1.0 | Jan 21, 2025 |
---|
#200 in Compression
105 downloads per month
32KB
719 lines
shapdf
= shape
+ pdf
Create Shapes into PDF
GitHub: Teddy-van-Jerry/shapdf
Motivation
- Efficient programmable generation of shapes in PDF (rather than slow compilation of LaTeX TikZ or Typst CeTZ);
- Minimal dependencies in Rust, relying mostly on PDF primitives.
Capabilities
- Shapes
- Line
- Circle (filled)
- Rectangle (filled)
- Polygon
- Text
- Color
- Opacity
- Rotation & Anchor
- PDF Stream Compression (feature
compress
)
More features are coming soon!
Example
The usage of this library is quite simple:
use shapdf::*;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let mut generator = Generator::new("output/shapes.pdf".into());
generator.add_page(); // use the default page size (US letter)
generator
.circle(Mm(20.), Mm(20.), Mm(10.))
.with_color(NamedColor("blue"))
.draw();
generator
.line(Pt(500.), Pt(600.), Pt(300.), Pt(400.))
.with_width(Mm(10.))
.with_cap_type(CapType::Round)
.with_color(NamedColor("red"))
.draw();
generator.add_page_letter();
generator
.rectangle(Mm(80.), Mm(180.), Mm(50.), Mm(30.))
.with_anchor(Anchor::Center)
.with_angle(Degree(30.))
.draw();
generator
.circle(Mm(80.), Mm(180.), Mm(1.))
.with_color(NamedColor("green"))
.draw();
generator.add_page_a4();
generator.write_pdf()?;
println!("PDF generated successfully!");
Ok(())
}
More examples are available in the examples
directory.
Implementation Facts
- Filled circle is actually implemented using a zero-length line with the rounded line cap.
License
This project is distributed under the GPL-3.0 License.
© 2025 Teddy van Jerry (Wuqiong Zhao)
Dependencies
~140KB