krilla
A high-level, ergonomic Rust library creating PDF documents.
krilla is a high-level Rust crate that allows for the creation of PDF files. It builds on top of the pdf-writer crate, but abstracts away all complexities that are involved in creating a PDF file, instead providing an interface with high-level primitives, such as fills, strokes, gradient, glyphs and images which can be used and combined easily without having to worry about low-level details.
Example
The following example shows some of the features of krilla in action.
The example creates a PDF file with two pages. On the first page, we add two small pieces of text, and on the second page we draw a triangle with a gradient fill.
For more examples, feel free to take a look at the examples directory of the GitHub repository.
use ;
use rgb;
use Font;
use ;
use ;
use TextDirection;
use Fill;
use Document;
use PageSettings;
use NormalizedF32;
// Create a new document.
let mut document = new;
// Load a font.
let font = ;
// Add a new page with dimensions 200x200.
let mut page = document.start_page_with;
// Get the surface of the page.
let mut surface = page.surface;
// Draw some text.
surface.draw_text;
surface.set_fill;
// Draw some more text, in a different color with an opacity and bigger font size.
surface.draw_text;
// Finish the page.
surface.finish;
page.finish;
// Start a new page.
let mut page = document.start_page_with;
// Create the triangle.
let triangle = ;
// Create the linear gradient.
let lg = LinearGradient ;
let mut surface = page.surface;
// Set the fill.
surface.set_fill;
// Fill the path.
surface.draw_path;
// Finish up and write the resulting PDF.
surface.finish;
page.finish;
let pdf = document.finish.unwrap;
let path = absolute.unwrap;
eprintln!;
// Write the PDF to a file.
write.unwrap;
License
This crate is dual-licensed under the MIT and Apache 2.0 licenses.