Crates.io | libharu_ng |
lib.rs | libharu_ng |
version | 1.0.9 |
source | src |
created_at | 2024-01-21 08:10:14.17624 |
updated_at | 2024-06-19 09:34:31.93549 |
description | Easily generate PDFs from your Rust app. |
homepage | https://github.com/bastibense/libharu_ng |
repository | https://github.com/bastibense/libharu_ng |
max_upload_size | |
id | 1107418 |
size | 3,945,574 |
Using libharu_ng
, you can easily create PDF documents from Rust code.
libharu_ng
is a modern API wrapper for libharu (GitHub Repository). libharu
is a C library for creating PDF files. This crate provides a modern and safe Rust API for generating PDFs without having to worry about the underlying C code.
So, until there are mature pure-Rust alternatives for generating PDFs, libharu_ng
is a good choice for generating PDFs from Rust code without having to use a headless browser or a commercial solution.
libharu
VersionThis crate uses the latest version of libharu
(2.4.4) and will be updated to the latest version of libharu
as soon as possible.
libharu_ng
)For more information about the features, please see the libharu documentation.
$ apt-get install build-essential cmake libpng-dev libz3-dev
$ brew install cmake libpng zlib
To use libharu
in your Rust project, run the command line, in your Rust project directory:
$ cargo add libharu_ng
// Example is work in progress.
use libharu_ng::prelude::*;
fn main() -> Result<(), HaruError> {
let doc = PdfDocument::new();
let fnt = doc.get_font("Helvetica", None)?;
doc.add_page()?
.begin_text()?
.move_text_pos(220.0, 20.0)?
.set_font_and_size(fnt, 24.0)?
.show_text("Hello World")?
.end_text()?;
doc.save_to_file("./test.pdf")?;
Ok(())
}
The main motivation behind libharu_ng
is to provide a simple and modern API for generating PDFs from Rust code.
One of the requirements was fine-grained control over the content of the PDF document and minimal dependencies and size/performance overhead.
There are a number of alternatives for generating PDFs from Rust code, each with their own advantages and disadvantages:
This crate, as is, will try to compile the libharu
library from source, embedding it into your Rust project. This means that you don't have to install any additional dependencies on your system, and you don't have to worry about the libharu
version on your system. If you have problems with the embedded libharu
version, please open an issue.
Contributions are welcome. Please open an issue before submitting a pull request.