Git Product home page Git Product logo

libharu_ng's Introduction

libharu_ng

GitHub Actions Workflow Status Crates.io Downloads GitHub Stars

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

What is it?

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 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.

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:

$ cargo add libharu_ng

Example

// 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.

libharu_ng's People

Contributors

bastibense avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

libharu_ng's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.