[−][src]Struct genpdf::Document
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.
Example
let mut doc = genpdf::Document::new("./fonts", "Liberation") .expect("Failed to create document"); doc.push(genpdf::elements::Paragraph::new("Document content")); doc.render_to_file("output.pdf").expect("Failed to render document");
Implementations
impl Document
[src]
pub fn new(
font_dir: impl AsRef<Path>,
font_name: impl AsRef<str>
) -> Result<Document, Error>
[src]
font_dir: impl AsRef<Path>,
font_name: impl AsRef<str>
) -> Result<Document, Error>
Creates a new document with the font family with the given name in the given directory as the default font.
See the documentation of the load_font_family
method for details on the font loading.
pub fn load_font_family(
&mut self,
dir: impl AsRef<Path>,
name: &str
) -> Result<FontFamily, Error>
[src]
&mut self,
dir: impl AsRef<Path>,
name: &str
) -> Result<FontFamily, Error>
Loads the font family with the given name from the given directory, adds them to the font cache and returns a reference to the loaded font family.
The font is loaded from TTF files in the given directory. It assumes that the following files exist and are valid font files:
{dir}/{name}-Regular.ttf
{dir}/{name}-Bold.ttf
{dir}/{name}-Italic.ttf
{dir}/{name}-BoldItalic.ttf
Note that the returned font reference may only be used for this document. It cannot be
shared with other Document
or FontCache
instances.
pub fn font_cache(&self) -> &FontCache
[src]
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.
pub fn set_title(&mut self, title: impl Into<String>)
[src]
Sets the title of the PDF document.
If this method is not called, the PDF title will be empty.
pub fn set_font_size(&mut self, font_size: u8)
[src]
Sets the default font size in points for this document.
If this method is not called, the default value of 12 points is used.
pub fn set_line_spacing(&mut self, line_spacing: f64)
[src]
Sets the default line spacing factor for this document.
If this method is not called, the default value of 1 is used.
pub fn set_paper_size(&mut self, paper_size: impl Into<Size>)
[src]
Sets the paper size for all pages of this document.
If this method is not called, the default size A4
is used.
pub fn set_margins(&mut self, margins: impl Into<Margins>)
[src]
Sets the margins for all pages of this document.
If this method is not called, the full page is used.
pub fn set_conformance(&mut self, conformance: PdfConformance)
[src]
Sets the PDF conformance settings for this document.
pub fn set_minimal_conformance(&mut self)
[src]
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.
pub fn push<E: Element + 'static>(&mut self, element: E)
[src]
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.
pub fn render(self, w: impl Write) -> Result<(), Error>
[src]
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.
pub fn render_to_file(self, path: impl AsRef<Path>) -> Result<(), Error>
[src]
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 !Send for Document
impl !Sync for Document
impl Unpin for Document
impl !UnwindSafe for Document
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,