Struct pdf_writer::PdfWriter
source · [−]pub struct PdfWriter { /* private fields */ }
Expand description
The root writer.
Implementations
sourceimpl PdfWriter
impl PdfWriter
Core methods.
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new PDF writer with the default buffer capacity (currently 8 KB).
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new PDF writer with the specified initial buffer capacity.
sourcepub fn set_version(&mut self, major: u8, minor: u8)
pub fn set_version(&mut self, major: u8, minor: u8)
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.
sourceimpl PdfWriter
impl PdfWriter
Indirect objects and streams.
sourcepub fn indirect(&mut self, id: Ref) -> Obj<'_>
pub fn indirect(&mut self, id: Ref) -> Obj<'_>
Start writing an indirectly referenceable object.
sourcepub fn stream<'a>(&'a mut self, id: Ref, data: &'a [u8]) -> Stream<'a>
pub fn stream<'a>(&'a mut self, id: Ref, data: &'a [u8]) -> Stream<'a>
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
.
sourceimpl PdfWriter
impl PdfWriter
Document structure.
sourcepub fn catalog(&mut self, id: Ref) -> Catalog<'_>
pub fn catalog(&mut self, id: Ref) -> Catalog<'_>
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.
sourcepub fn document_info(&mut self, id: Ref) -> DocumentInfo<'_>
pub fn document_info(&mut self, id: Ref) -> DocumentInfo<'_>
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.
sourcepub fn outline_item(&mut self, id: Ref) -> OutlineItem<'_>
pub fn outline_item(&mut self, id: Ref) -> OutlineItem<'_>
Start writing an outline item.
sourcepub fn destinations(&mut self, id: Ref) -> Destinations<'_>
pub fn destinations(&mut self, id: Ref) -> Destinations<'_>
Start writing a named destination dictionary.
sourcepub fn file_spec(&mut self, id: Ref) -> FileSpec<'_>
pub fn file_spec(&mut self, id: Ref) -> FileSpec<'_>
Start writing a file specification dictionary.
sourcepub fn embedded_file<'a>(
&'a mut self,
id: Ref,
bytes: &'a [u8]
) -> EmbeddedFile<'a>
pub fn embedded_file<'a>(
&'a mut self,
id: Ref,
bytes: &'a [u8]
) -> EmbeddedFile<'a>
Start writing an embedded file stream.
sourceimpl PdfWriter
impl PdfWriter
Graphics and content.
sourcepub fn image_xobject<'a>(
&'a mut self,
id: Ref,
samples: &'a [u8]
) -> ImageXObject<'a>
pub fn image_xobject<'a>(
&'a mut self,
id: Ref,
samples: &'a [u8]
) -> ImageXObject<'a>
Start writing an image XObject stream.
The samples should be encoded according to the stream’s filter, color space and bits per component.
sourcepub fn form_xobject<'a>(
&'a mut self,
id: Ref,
content: &'a [u8]
) -> FormXObject<'a>
pub fn form_xobject<'a>(
&'a mut self,
id: Ref,
content: &'a [u8]
) -> FormXObject<'a>
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.
sourcepub fn ext_graphics(&mut self, id: Ref) -> ExtGraphicsState<'_>
pub fn ext_graphics(&mut self, id: Ref) -> ExtGraphicsState<'_>
Start writing an external graphics state dictionary.
sourceimpl PdfWriter
impl PdfWriter
Fonts.
sourcepub fn type1_font(&mut self, id: Ref) -> Type1Font<'_>
pub fn type1_font(&mut self, id: Ref) -> Type1Font<'_>
Start writing a Type-1 font.
sourcepub fn type3_font(&mut self, id: Ref) -> Type3Font<'_>
pub fn type3_font(&mut self, id: Ref) -> Type3Font<'_>
Start writing a Type-3 font.
sourcepub fn type0_font(&mut self, id: Ref) -> Type0Font<'_>
pub fn type0_font(&mut self, id: Ref) -> Type0Font<'_>
Start writing a Type-0 font.
sourcepub fn font_descriptor(&mut self, id: Ref) -> FontDescriptor<'_>
pub fn font_descriptor(&mut self, id: Ref) -> FontDescriptor<'_>
Start writing a font descriptor.
sourceimpl PdfWriter
impl PdfWriter
Color spaces, shadings and patterns.
sourcepub fn color_space(&mut self, id: Ref) -> ColorSpace<'_>
pub fn color_space(&mut self, id: Ref) -> ColorSpace<'_>
Start writing a color space.
sourcepub fn tiling_pattern<'a>(
&'a mut self,
id: Ref,
content: &'a [u8]
) -> TilingPattern<'a>
pub fn tiling_pattern<'a>(
&'a mut self,
id: Ref,
content: &'a [u8]
) -> TilingPattern<'a>
Start writing a tiling pattern stream.
You can create the content bytes using a Content
builder.
sourcepub fn shading_pattern(&mut self, id: Ref) -> ShadingPattern<'_>
pub fn shading_pattern(&mut self, id: Ref) -> ShadingPattern<'_>
Start writing a shading pattern.
sourceimpl PdfWriter
impl PdfWriter
Functions.
sourcepub fn sampled_function<'a>(
&'a mut self,
id: Ref,
samples: &'a [u8]
) -> SampledFunction<'a>
pub fn sampled_function<'a>(
&'a mut self,
id: Ref,
samples: &'a [u8]
) -> SampledFunction<'a>
Start writing a sampled function stream.
sourcepub fn exponential_function(&mut self, id: Ref) -> ExponentialFunction<'_>
pub fn exponential_function(&mut self, id: Ref) -> ExponentialFunction<'_>
Start writing an exponential function.
sourcepub fn stitching_function(&mut self, id: Ref) -> StitchingFunction<'_>
pub fn stitching_function(&mut self, id: Ref) -> StitchingFunction<'_>
Start writing a stitching function.
sourcepub 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
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for PdfWriter
impl Send for PdfWriter
impl Sync for PdfWriter
impl Unpin for PdfWriter
impl UnwindSafe for PdfWriter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more