1 unstable release

0.1.0 Jun 20, 2022

#292 in Multimedia

MIT/Apache

16KB
352 lines

json2pdf-client

Rust Client library for the json2pdf server. Json2pdf is a server which takes a JSON description of a PDF, and converts it to a PDF document.

Usage

use json2pdf_client::*;

/// Generate a PDF document containing a paragraph and an image
async fn generate_pdf() {
    let spec = DocumentSpecification::new()
        .add_element(Element::paragraph(Paragraph::new("Hello world!"))
            .border(BorderSettings::new()
                .bottom(BorderSpecification::new(4f32))))
        // Make sure you add the actual image bytes, rather than an empty Vec
        .add_element(Element::image(Image::new_bytes(&Vec::new(), 400f32, 400f32)));
    let data = pdf("http://localhost:8080", &spec).await.unwrap();
}

License

json2pdf-client is licensed under the Apache-2.0 license, or the MIT license. At your discretion. Both licenses can be found at the root of this repository.


lib.rs:

json2pdf Client library

This library is a client library for the json2pdf server. json2pdf is a Java webserver that generates PDF documents from a JSON model.

Example

Generate a PDF documentation with some text and an image

use json2pdf_client::*;

async fn generate_pdf() {
    let spec = DocumentSpecification::new()
        .add_element(Element::paragraph(Paragraph::new("Hello world!"))
            .border(BorderSettings::new()
                .bottom(BorderSpecification::new(4f32))))
        .add_element(Element::image(Image::new_bytes(&Vec::new(), 400f32, 400f32)));

    let data = pdf("http://localhost:8080", &spec).await.unwrap();
}

Dependencies

~4–16MB
~213K SLoC