pdf crate root#
/// A4 portrait in points
A4: (f64, f64) = (595.275_590_551_181_1, 841.889_763_779_527_6)
/// A3 portrait in points
A3: (f64, f64) = (841.889_763_779_527_6, 1_190.551_181_102_362_2)
/// A5 portrait in points
A5: (f64, f64) = (419.527_559_055_118_1, 595.275_590_551_181_1)
/// US Letter portrait in points
LETTER: (f64, f64) = (612.0, 792.0)
/// US Legal portrait in points
LEGAL: (f64, f64) = (612.0, 1008.0)
fn mm(v: f64) -> f64millimetres in pointsfn inch(v: f64) -> f64inches in points
/// the smallest and largest page side PDF readers take (ISO 32000-1, Annex C)
PAGE_MIN: f64 = 3.0
PAGE_MAX: f64 = 14_400.0
enum ErrorFont(&'static str)-- the font file cannot be used: damaged, or a kind not takenFontLicense(&'static str)-- the font's licence (OS/2 fsType) does not allow embeddingImage(&'static str)-- image data that does not fit what it claimsUnsupported(&'static str)-- valid input this writer does not handle (CFF2 fonts, arithmetic-coded JPEG, ...)Invalid(&'static str)-- the document cannot be written as it is (no pages, a link to a page it lacks, ...)
struct Glypha shaped glyph for Canvas::glyphs: Document::shape gives them, a text layout that shaped its lines already builds its ownfont: usize-- which of the fonts passed along (0: the first)id: u32-- the glyph id in that fontadvance: i32-- how far the pen moves after the glyph, in font unitsx: i32-- the glyph's offset from the pen in font units (y up)y: i32cluster: usize-- the byte range of the text the glyph stands for (its cluster): cluster..endend: usize
struct PageId(pub u32)a page of a document (Document::add_page), counted from 0struct FontId(u32)a font of a document (Document::add_font)struct ImageId(u32)an image of a document (Document::add_image)struct OutlineId(u32)an outline item (Document::add_outline)enum Desta place in the document for links and outline itemsFit(PageId)-- the whole page in the windowXyz { page: PageId, left: f64, top: f64, zoom: Option<f64> }-- the point (left, top) of PDF page space (points from the bottom left, y up) at the top left of the window; zoom None keeps the reader's (Canvas::dest builds one from a canvas's own coordinates)
struct Datea date of the document information: local time and its offset from UTCyear: u16month: u8day: u8hour: u8minute: u8second: u8offset_minutes: i16-- minutes east of UTC (+60: Central European Time), -1439 to 1439
struct Infothe document information (the Info dictionary and the same in XMP metadata); unset fields are left outtitle: Option<String>author: Option<String>subject: Option<String>keywords: Option<String>creator: Option<String>-- the program the document was made withproducer: Option<String>-- the program that wrote the PDF (None: "JFLib")created: Option<Date>modified: Option<Date>
struct Documenta PDF document being built: its pages, fonts, images, outlines and information
impl Document
fn new() -> Documentfn add_page(&mut self, width: f64, height: f64) -> PageIda new page at the end, width and height in points (clamped to PAGE_MIN .. PAGE_MAX)fn page_count(&self) -> usizefn page_size(&self, page: PageId) -> Option<(f64, f64)>width and height in pointsfn canvas(&mut self, page: PageId, origin: Origin) -> Canvas<'_>drawing on a page (panics for a page this document does not have)fn add_font(&mut self, data: Vec<u8>, face: u32) -> Result<FontId, Error>a TrueType or OpenType font (glyf or CFF outlines;face: of a collection, else 0)fn font_metrics(&self, font: FontId) -> Option<FontMetrics>fn shape(&self, fonts: &[FontId], text: &str) -> Vec<Glyph>one line shaped with the fonts (the first, then fallbacks per script run); empty for an unknown font or a line beyond 64 KiBfn text_width(&self, fonts: &[FontId], size: f64, text: &str) -> f64the advance of one shaped line atsizepointsfn add_image(&mut self, img: Image) -> ImageIdfn add_outline(&mut self, parent: Option<OutlineId>, title: &str, dest: Dest) -> OutlineIdan outline item (bookmark) underparent(None: at the top), after its siblings; open (its children shown) until set_outline_open says otherwisefn set_outline_open(&mut self, item: OutlineId, open: bool)fn set_info(&mut self, info: Info)fn set_language(&mut self, lang: &str)the document's language (BCP 47, e.g. "de-DE")fn set_compression(&mut self, level: u8)DEFLATE level 0 (streams uncompressed, for reading the file) to 9; default 6fn set_encryption(&mut self, e: Option<Encryption>)encrypt the file (None: not, the default); see Encryptionfn write(&self) -> Result<Vec<u8>, Error>the PDF file