Skip to main content

SimpleDocumentBuilder

Struct SimpleDocumentBuilder 

Source
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

Source

pub fn new(title: impl Into<String>) -> Self

Create a new builder for a document with the given title.

Source

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.

Source

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.

Source

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.

Source

pub fn page_height_mm(&self) -> f32

Returns the page height in millimetres (always 297 mm for A4).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.