pub struct SimpleDocumentBuilder { /* private fields */ }Expand description
High-level builder for simple text-only A4 PDF documents.
Does NOT require an area tree or FO pipeline — suitable for reports generated programmatically (audit logs, verification reports, etc.).
§Example
use fop_render::pdf::simple::{BuiltinFont, SimpleDocumentBuilder};
let mut builder = SimpleDocumentBuilder::new("My Report");
builder.text("Hello, world!", 12.0, 20.0, 280.0, BuiltinFont::Helvetica);
let bytes = builder.save();
assert!(bytes.starts_with(b"%PDF-"));Implementations§
Source§impl SimpleDocumentBuilder
impl SimpleDocumentBuilder
Sourcepub fn new(title: impl Into<String>) -> Self
pub fn new(title: impl Into<String>) -> Self
Create a new builder for a document with the given title.
Set the document author.
Sourcepub fn set_subject(&mut self, s: impl Into<String>) -> &mut Self
pub fn set_subject(&mut self, s: impl Into<String>) -> &mut Self
Set the document subject.
Sourcepub fn set_creation_date(&mut self, s: impl Into<String>) -> &mut Self
pub fn set_creation_date(&mut self, s: impl Into<String>) -> &mut Self
Set the document creation date (PDF date format, e.g. D:20260515120000).
Sourcepub fn set_lang(&mut self, s: impl Into<String>) -> &mut Self
pub fn set_lang(&mut self, s: impl Into<String>) -> &mut Self
Set the document language tag (BCP 47, e.g. en-US).
Sourcepub fn set_xmp_metadata(&mut self, s: impl Into<String>) -> &mut Self
pub fn set_xmp_metadata(&mut self, s: impl Into<String>) -> &mut Self
Set a raw XMP metadata packet to embed in the PDF /Metadata stream.
Dublin Core fields (dc:title, dc:creator, dc:description) are
extracted and merged into the /Info dict if the corresponding builder
field is not already set. Caller-set values always win.
Sourcepub fn text(
&mut self,
text: &str,
size_pt: f32,
x_mm: f32,
y_mm: f32,
font: BuiltinFont,
)
pub fn text( &mut self, text: &str, size_pt: f32, x_mm: f32, y_mm: f32, font: BuiltinFont, )
Write text at an absolute position on the current page.
Coordinates are in millimetres from the bottom-left corner of the page (standard PDF coordinate system). The font size is in PDF points.
Sourcepub fn new_page(&mut self)
pub fn new_page(&mut self)
Finalise the current page and start a new blank page.
The current page is preserved even if it is empty, matching the behaviour expected by callers that create explicit page-break points.
Sourcepub fn save(self) -> Vec<u8> ⓘ
pub fn save(self) -> Vec<u8> ⓘ
Serialise all pages to a minimal valid PDF 1.4 byte stream.
The current (last) page is automatically finalised. If no calls to
text() or new_page() have been made the resulting PDF will contain
a single empty page, which is valid.
Sourcepub fn page_height_mm(&self) -> f32
pub fn page_height_mm(&self) -> f32
Returns the page height in millimetres (always 297 mm for A4).
Auto Trait Implementations§
impl Freeze for SimpleDocumentBuilder
impl RefUnwindSafe for SimpleDocumentBuilder
impl Send for SimpleDocumentBuilder
impl Sync for SimpleDocumentBuilder
impl Unpin for SimpleDocumentBuilder
impl UnsafeUnpin for SimpleDocumentBuilder
impl UnwindSafe for SimpleDocumentBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more