libharu_ng 0.0.13

Generate PDFs with Rust using libharu
Documentation
libharu_ng-0.0.13 has been yanked.

libharu_ng

GitHub Actions Workflow Status

⭐ Support us, be cool, star this repository on GitHub! :)

⚠️ This is Work In Progress. The API might change at any time. ⚠️

What is it?

libharu_ng is a modern API wrapper for libharu (GitHub Repository).

Using libharu_ng, you can create PDF documents from Rust code.

Features

libharu_ng supports most features of libharu:

  • Create PDF documents.
  • Add pages to the document.
  • Add text to the pages.
    • Supporting text-wrapping into a given rectangle.
    • Use built-in fonts or load custom fonts (TTF).
  • Add images to the 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 the pages.
  • Add annotations to the pages.
  • Add outlines to the document.
  • Add metadata to the document.

For more information about the features, please see the libharu documentation.

Requirements

  • Installed libharu (tested with version 2.4).
    • See included Dockerfile for reference.

Usage

To use libharu in your Rust project, run the command line, in your Rust project directory:

$ cargo add libharu_ng

Linking with libharu

The library contains a build.rs file, which will try to find the libharu library on your system.

This is probably not the final solution, but it works for now.

Example

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(())
}

Contributing

Contributions are welcome. Please open an issue before submitting a pull request.

To-Do List

  • Figure out how to handle deployment of the C library (for systems without a package for it).
  • Add more documentation.
  • Better error handling.
  • Add more examples.
  • Add more tests.

About

This is just a wrapper around the C library libharu.

License

This project is licensed under the MIT license.