Crate pdf_canvas[][src]

A library for creating pdf files.

Currently, simple vector graphics and text set in the 14 built-in fonts are supported. The main entry point of the crate is the struct Pdf, representing a PDF file being written.

Example

use pdf_canvas::{Pdf, BuiltinFont, FontSource};
use pdf_canvas::graphicsstate::Color;

let mut document = Pdf::create("example.pdf")
    .expect("Create pdf file");
// The 14 builtin fonts are available
let font = BuiltinFont::Times_Roman;

// Add a page to the document.  This page will be 180 by 240 pt large.
document.render_page(180.0, 240.0, |canvas| {
    // This closure defines the content of the page
    let hello = "Hello World!";
    let w = font.get_width(24.0, hello) + 8.0;

    // Some simple graphics
    canvas.set_stroke_color(Color::rgb(0, 0, 248))?;
    canvas.rectangle(90.0 - w / 2.0, 194.0, w, 26.0)?;
    canvas.stroke()?;

    // Some text
    canvas.center_text(90.0, 200.0, font, 24.0, hello)
}).expect("Write page");
// Write all pending content, including the trailer and index
document.finish().expect("Finish pdf document");

To use this library you need to add it as a dependency in your Cargo.toml:

[dependencies]
pdf-canvas = "*"

Some more working usage examples exists in [the examples directory] (https://github.com/kaj/rust-pdf/tree/master/examples).

Modules

graphicsstate

Types for representing details in the graphics state.

Structs

Canvas

A visual area where content can be drawn (a page).

Encoding

Represent a text encoding used in PDF. An encoding maintains the connection between unicode code points, bytes in PDF strings, and glyph names.

FontMetrics

Relevant data that can be loaded from an AFM (Adobe Font Metrics) file. A FontMetrics object is specific to a given encoding.

FontRef

A font ready to be used in a TextObject.

Pdf

The top-level object for writing a PDF.

TextObject

A text object is where text is put on the canvas.

Enums

BuiltinFont

The "Base14" built-in fonts in PDF. Underscores in these names are hyphens in the real names.

Traits

FontSource

This trait is implemented by any kind of font that the pdf library supports.