Struct genpdf::Document [−][src]
pub struct Document { /* fields omitted */ }
Expand description
A PDF document.
This struct is the entry point for the high-level genpdf
API. It stores a set of elements
and default style and layout settings. Add elements to the document by calling the push
method and then render them to a PDF file using the render
and render_to_file
methods.
The root element of the document is a LinearLayout
that vertically arranges all elements.
For details on the rendering process, see the Rendering Process section of the crate
documentation.
You can add a PageDecorator
to this document by calling set_page_decorator
. This
page decorator will be called for every new page and can add a margin, a header or other
elements to the page before it is filled with the actual document content. See the
SimplePageDecorator
for a basic implementation.
If the hyphenation
feature is enabled, users can activate hyphenation with the
[set_hyphenator
][] method.
Example
// Load a font from the file system let font_family = genpdf::fonts::from_files("./fonts", "LiberationSans", None) .expect("Failed to load font family"); // Create a document and set the default font family let mut doc = genpdf::Document::new(font_family); doc.push(genpdf::elements::Paragraph::new("Document content")); doc.render_to_file("output.pdf").expect("Failed to render document");
Implementations
Creates a new document with the given default font family.
Adds the given font family to the font cache for this document and returns a reference to it.
Note that the returned font reference may only be used for this document. It cannot be
shared with other Document
or FontCache
instances.
Returns the font cache used by this document.
You can use the font cache to get the default font and to query glyph metrics for a font.
Use the load_font_family
method instead if you want to add fonts to this document.
Activates hyphenation and sets the hyphentor to use.
Only available if the hyphenation
feature is enabled.
Sets the title of the PDF document.
If this method is not called, the PDF title will be empty.
Sets the default font size in points for this document.
If this method is not called, the default value of 12 points is used.
Sets the default line spacing factor for this document.
If this method is not called, the default value of 1 is used.
Sets the paper size for all pages of this document.
If this method is not called, the default size A4
is used.
Sets the page decorator for this document.
The page decorator is called for every page before it is filled with the document content. It can add margins, headers or other elements.
See the SimplePageDecorator
for an example implementation.
Sets the PDF conformance settings for this document.
Sets the minimal PDF conformance settings for this document.
If this method is called, the generation of ICC profiles and XMP metadata is deactivated, leading to a smaller file size.
Adds the given element to the document.
The given element is appended to the list of elements that is rendered by the root
LinearLayout
once render
or render_to_file
is called.
Renders this document into a PDF file and writes it to the given writer.
The given writer is always wrapped in a buffered writer. For details on the rendering process, see the Rendering Process section of the crate documentation.
Renders this document into a PDF file at the given path.
If the given file does not exist, it is created. If it exists, it is overwritten.
For details on the rendering process, see the Rendering Process section of the crate documentation.
Auto Trait Implementations
impl !RefUnwindSafe for Document
impl !UnwindSafe for Document