Struct pdf_writer::PdfWriter [−][src]
pub struct PdfWriter { /* fields omitted */ }
Expand description
The root writer.
Implementations
Core methods.
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.
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.
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 an outline item.
Start writing a named destination 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 font descriptor.
Color spaces, shadings and patterns.
Start writing a color space.
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.
pub fn post_script_function<'a>(
&'a mut self,
id: Ref,
code: &'a [u8]
) -> PostScriptFunction<'a>
pub fn post_script_function<'a>(
&'a mut self,
id: Ref,
code: &'a [u8]
) -> PostScriptFunction<'a>
Start writing a PostScript function stream.
You can create the code bytes using PostScriptOp::encode
.