Skip to main content

Crate pdfboss_write

Crate pdfboss_write 

Source
Expand description

PDF creation for pdfboss: the write-side twin of pdfboss-core.

Three altitudes, each complete on its own and lowering into the one beneath:

  • documentPdf and Page: plain structs whose fields are the composition, saved with Pdf::save.
  • canvasCanvas: an imperative painter accumulating pdfboss_core::content::Op, the same IR the reader parses, so every generated content stream round-trips through parse_content.
  • cosWriter: numbered objects in, finished file bytes out, with stream compression, object streams, both cross-reference styles and a deterministic /ID.

Determinism is a feature: the same input produces byte-identical output. The crate never reads clocks or randomness — dates appear only when callers supply them.

Re-exports§

pub use canvas::BlendMode;
pub use canvas::Canvas;
pub use canvas::CanvasParts;
pub use canvas::GroupHandle;
pub use canvas::ImageHandle;
pub use canvas::LineCap;
pub use canvas::LineJoin;
pub use color::Color;
pub use content::serialize_ops;
pub use element::Content;
pub use element::Draw;
pub use element::Image;
pub use element::Paragraph;
pub use element::ParagraphAlign;
pub use element::Text;
pub use error::Error;
pub use error::Result;
pub use font::Standard14;
pub use image::ImageData;
pub use pdf::Attachment;
pub use pdf::Bookmark;
pub use pdf::Date;
pub use pdf::LabelStyle;
pub use pdf::LinkAnnotation;
pub use pdf::LinkTarget;
pub use pdf::Metadata;
pub use pdf::Outline;
pub use pdf::Page;
pub use pdf::PageLabel;
pub use pdf::PageLayout;
pub use pdf::PageMode;
pub use pdf::PageSize;
pub use pdf::Pdf;
pub use pdf::Viewer;
pub use sink::AsyncByteSink;
pub use sink::Immediate;
pub use update::watermark;
pub use update::watermark_with;
pub use writer::WriteOptions;
pub use writer::Writer;
pub use writer::XrefStyle;

Modules§

canvas
The imperative painting surface. A Canvas accumulates pdfboss_core::content::Op values — the exact IR the reader parses — plus the fonts and images those operators reference. Nothing here serializes; finish hands the parts to document assembly.
color
Device color values for content generation. The first public color vocabulary in the workspace — the render crate keeps its own private read-side ColorSpace.
content
Content-stream serialization: pdfboss_core::content::Op values back to operator syntax. The writer emits from the same IR the reader parses into, so parse_content(serialize_ops(ops)) == ops is the module’s defining property — every variant of Op must round-trip.
element
The compose element vocabulary: painted content one step above raw canvas operators. A Content value sits in crate::pdf::Page::content and lowers onto the page’s Canvas at assemble time, after any operators the caller already painted there directly — elements paint over manual canvas work, never under it.
error
Error type for PDF creation. Writing is strict where reading is lenient: a writer that silently drops or corrupts content is worse than one that refuses, so every lossy situation is an error, never a skip.
font
The fourteen standard fonts (ISO 32000 §9.6.2.2), with WinAnsi text encoding and AFM metrics from pdfboss-encoding. Text in these faces needs no embedded font program — every conforming reader carries them.
image
Image import for document creation. JPEG passes through untouched as /DCTDecode (dimensions sniffed from its SOF marker); PNG is decoded to a raster with its alpha split into an /SMask; raw rasters cover generated content. No encode-side JPX/JBIG2/CCITT — by design.
pdf
Document assembly: pages of canvas content, document metadata, and the save path. Pdf is a plain struct — the fields are the composition, and Default fills everything optional.
ser
COS object serialization: Object values to PDF syntax bytes (ISO 32000 §7.3). Output is deterministic — dictionary keys are emitted in sorted order regardless of insertion order.
sink
The byte-sink abstraction shared by the synchronous and asynchronous write APIs.
update
Incremental updates to an existing file (ISO 32000-1 §7.5.6): the base bytes stay in place and an update section appends new and replaced objects plus a cross-reference section chained to the base’s by /Prev, in the base’s own cross-reference style.
writer
The object-level PDF writer: numbered objects in, finished file bytes out. Handles the header, stream /Length bookkeeping, optional Flate compression, object streams, both cross-reference styles, the trailer and a deterministic /ID.