Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bastibense/libharu_ng
Generate PDFs using libharu from Rust
https://github.com/bastibense/libharu_ng
generator haru libharu pdf rust wrapper
Last synced: about 1 month ago
JSON representation
Generate PDFs using libharu from Rust
- Host: GitHub
- URL: https://github.com/bastibense/libharu_ng
- Owner: bastibense
- License: other
- Created: 2024-01-20T21:26:57.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-19T09:33:55.000Z (6 months ago)
- Last Synced: 2024-10-12T20:30:22.300Z (2 months ago)
- Topics: generator, haru, libharu, pdf, rust, wrapper
- Language: C
- Homepage: https://crates.io/crates/libharu_ng
- Size: 1.03 MB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-rust - bastibense/libharu_ng - Easily generate PDFs from your Rust app. (Libraries / Graphics)
README
# libharu_ng
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/bastibense/libharu_ng/master-build-test.yml)
![Crates.io Downloads](https://img.shields.io/crates/d/libharu_ng)
![GitHub Stars](https://img.shields.io/github/stars/bastibense/libharu_ng)#### ⭐ Support this crate, be cool, [star this repository on GitHub](https://github.com/bastibense/libharu_ng)! :)
## What is it?
Using `libharu_ng`, you can easily create PDF documents from Rust code.
`libharu_ng` is a modern API wrapper for [libharu](http://libaru.org/) ([GitHub Repository](https://github.com/libharu/libharu_ng)). `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` Version
This crate uses the latest version of `libharu` (2.4.4) and will be updated to the latest version of `libharu` as soon as possible.
## Features
### Standard libharu Features
- Create PDF documents.
- Add pages to the document.
- Add text to pages.
- Supporting text-wrapping into a given rectangle.
- Use built-in fonts or load custom fonts (TTF).
- Add images to pages.
- With support for JPEG and PNG images (including transparency).
- Use custom page sizes.
- Save and restore the graphics state.
- Set password protection for the document.
- Add shapes like lines, rectangles, circles, etc. to pages.
- Add annotations to pages.
- Add outlines to the document.
- Add metadata to the document.
- Compiles the libharu library from source, embedding it into your Rust project.### Additional Features (provided by `libharu_ng`)
- Simple functions for CTM transformations.
- Rotate, Translate, Scale, etc.For more information about the features, please see the [libharu documentation](http://libharu.org).
## Requirements
- libz (required at runtime)
- libpng (required at runtime)
- cmake (required for building the C library)### On Ubuntu/Debian
$ apt-get install build-essential cmake libpng-dev libz3-dev
### On macOS (Homebrew)
$ brew install cmake libpng zlib
## Usage
To use `libharu` in your Rust project, run the command line, in your Rust project directory:
```bash
$ cargo add libharu_ng
```## Example
```rust
// 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(())
}
```# Motivation
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.
# Contributing
Contributions are welcome. Please open an issue before submitting a pull request.
# License
- This project is licensed under the MIT license.
- Haru is distributed under the ZLIB/LIBPNG License.