pub struct PdfWriter { /* private fields */ }
Expand description

The root writer.

Implementations

Core methods.

Create a new PDF writer with the default buffer capacity (currently 8 KB).

Create a new PDF writer with the specified initial buffer capacity.

Set the PDF version.

The version is not semantically important to the writer, but must be present in the output document.

Default value: 1.7.

The number of bytes that were written so far.

Write the cross-reference table and file trailer and return the underlying buffer.

Panics if any indirect reference id was used twice.

Indirect objects and streams.

Start writing an indirectly referenceable object.

Start writing an indirectly referenceable stream.

The stream data and the /Length field are written automatically. You can add additional key-value pairs to the stream dictionary with the returned stream writer.

You can use this function together with a Content stream builder to provide a page’s contents.

use pdf_writer::{PdfWriter, Content, Ref};

// Create a simple content stream.
let mut content = Content::new();
content.rect(50.0, 50.0, 50.0, 50.0);
content.stroke();

// Create a writer and write the stream.
let mut writer = PdfWriter::new();
writer.stream(Ref::new(1), &content.finish());

This crate does not do any compression for you. If you want to compress a stream, you have to pass already compressed data into this function and specify the appropriate filter in the stream dictionary.

For example, if you want to compress your content stream with DEFLATE, you could do something like this:

use pdf_writer::{PdfWriter, Content, Ref, Filter};
use miniz_oxide::deflate::{compress_to_vec_zlib, CompressionLevel};

// Create a simple content stream.
let mut content = Content::new();
content.rect(50.0, 50.0, 50.0, 50.0);
content.stroke();

// Compress the stream.
let level = CompressionLevel::DefaultLevel as u8;
let compressed = compress_to_vec_zlib(&content.finish(), level);

// Create a writer, write the compressed stream and specify that it
// needs to be decoded with a FLATE filter.
let mut writer = PdfWriter::new();
writer.stream(Ref::new(1), &compressed).filter(Filter::FlateDecode);

For all the specialized stream functions below, it works the same way: You can pass compressed data and specify a filter.

Panics if the stream length exceeds i32::MAX.

Document structure.

Start writing the document catalog. Required.

This will also register the document catalog with the file trailer, meaning that you don’t need to provide the given id anywhere else.

Start writing the document information.

This will also register the document information dictionary with the file trailer, meaning that you don’t need to provide the given id anywhere else.

Start writing a page tree.

Start writing a page.

Start writing an outline.

Start writing an outline item.

Start writing a named destination dictionary.

Start writing a file specification dictionary.

Start writing an embedded file stream.

Graphics and content.

Start writing an image XObject stream.

The samples should be encoded according to the stream’s filter, color space and bits per component.

Start writing a form XObject stream.

These can be used as transparency groups.

Note that these have nothing to do with forms that have fields to fill out. Rather, they are a way to encapsulate and reuse content across the file.

You can create the content bytes using a Content builder.

Start writing an external graphics state dictionary.

Fonts.

Start writing a Type-1 font.

Start writing a Type-3 font.

Start writing a Type-0 font.

Start writing a CID font.

Start writing a font descriptor.

Start writing a character map stream.

If you want to use this for a /ToUnicode CMap, you can create the bytes using a UnicodeCmap builder.

Color spaces, shadings and patterns.

Start writing a color space.

Start writing a shading.

Start writing a tiling pattern stream.

You can create the content bytes using a Content builder.

Start writing a shading pattern.

Functions.

Start writing a sampled function stream.

Start writing an exponential function.

Start writing a stitching function.

Start writing a PostScript function stream.

You can create the code bytes using PostScriptOp::encode.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.