Fpdf

Struct Fpdf 

Source
pub struct Fpdf<'a> { /* private fields */ }
Expand description

Fpdf is the principal structure for creating a single PDF document.

It holds all the neccessary information for constructing a PDF document, with all images, attachments, bookmarks etc.

§Example

use fpdf::Fpdf;

let mut pdf = Fpdf::default();

Implementations§

Source§

impl<'a> Fpdf<'a>

Source

pub fn new( orientation: Orientation, page_size: PageSize, font_dir: &str, size_v: UnitVec2, ) -> Self

Examples found in repository?
examples/example_set_line_join_style.rs (line 5)
3fn main() {
4    const OFFSET: Unit = Unit::mm(75.0);
5    let mut pdf = Fpdf::new(Orientation::Landscape, PageSize::A4, "", UnitVec2::default());
6    pdf.add_page();
7    let draw = |pdf: &mut Fpdf, cap: &str, join: &str, x0: f64, y0: f64, x1: f64, y1: f64| {
8        let x0 = Unit::mm(x0);
9        let y0 = Unit::mm(y0);
10        let x1 = Unit::mm(x1);
11        let y1 = Unit::mm(y1);
12
13        pdf.set_line_cap_style(cap);
14        pdf.set_line_join_style(join);
15
16        pdf.set_draw_color(RGB::new(0x33, 0x33, 0x33));
17        pdf.set_line_width(Unit::mm(30.0));
18        pdf.move_to(x0, y0);
19        pdf.line_to((x0+x1) / 2.0 + OFFSET, (y0+y1)/2.0);
20        pdf.line_to(x1, y1);
21        pdf.draw_path("D");
22
23        pdf.set_draw_color(RGB::new(0xFF, 0x33, 0x33));
24        pdf.set_line_width(Unit::mm(2.56));
25        pdf.move_to(x0, y0);
26        pdf.line_to((x0+x1)/2.0+OFFSET, (y0+y1)/2.0);
27        pdf.line_to(x1, y1);
28        pdf.draw_path("D");
29    };
30    let mut x = 35.0;
31    let caps = ["butt", "square", "round"];
32    let joins = ["bevel", "miter", "round"];
33    for i in 0..3 {
34        draw(&mut pdf, caps[i], joins[i], x, 50.0, x, 160.0);
35        x += OFFSET.to_mm();
36    }
37    pdf.output_file_and_close("example_set_line_join_style.pdf").unwrap();
38}
More examples
Hide additional examples
examples/example_page_size.rs (lines 4-9)
3fn main() {
4    let mut pdf = Fpdf::new(
5        Orientation::Portrait,
6        PageSize::A4,
7        "",
8        UnitVec2::inch(6.0, 6.0),
9    );
10    pdf.set_margins(Unit::inch(0.5), Unit::inch(1.0), Unit::inch(0.5));
11    pdf.set_font("Times", "", Unit::pt(14.0));
12    pdf.add_page_format(Orientation::Landscape, UnitVec2::inch(3.0, 12.0));
13    pdf.set_xy(Unit::inch(0.5), Unit::inch(1.5));
14    pdf.cell_format(
15        Unit::inch(11.0),
16        Unit::inch(0.2),
17        "12 in times 3 in",
18        "",
19        0,
20        "C",
21        false,
22        0,
23        "",
24    );
25    pdf.add_page();
26    pdf.set_xy(Unit::inch(0.5), Unit::inch(3.0));
27    pdf.cell_format(
28        Unit::inch(5.0),
29        Unit::inch(0.2),
30        "6 in times 6 in",
31        "",
32        0,
33        "C",
34        false,
35        0,
36        "",
37    );
38    pdf.add_page_format(Orientation::Portrait, UnitVec2::inch(3.0, 12.0));
39    pdf.set_xy(Unit::inch(0.5), Unit::inch(6.0));
40    pdf.cell_format(
41        Unit::inch(2.0),
42        Unit::inch(0.2),
43        "3 in times 12 in",
44        "",
45        0,
46        "C",
47        false,
48        0,
49        "",
50    );
51    for i in 0..3 {
52        let page_size = pdf.page_size(i);
53        println!(
54            "{} in times {} in",
55            page_size.width().to_inch(),
56            page_size.height().to_inch()
57        );
58    }
59    pdf.output_file_and_close("example_page_size.pdf").unwrap();
60}
examples/example_set_accept_page_break_fn.rs (lines 36-41)
14fn main() {
15    const WIDTH: Unit = Unit::mm(297.0);
16    const GUTTER: usize = 4;
17    const COLS: usize = 3;
18
19    let current_col = Rc::new(RefCell::new(0usize));
20    let y0 = Rc::new(RefCell::new(Unit::mm(0.0)));
21    let col_width: Unit =
22        (WIDTH - MARGIN.mul_untouched(2.0) - Unit::mm(((COLS - 1) * GUTTER) as f64))
23            .div_untouched(COLS as f64);
24    let lorem = LOREM_PARTS.join(" ");
25
26    let set_col = |pdf: &mut Fpdf, col: usize| {
27        let mut current_col = current_col.borrow_mut();
28        *current_col = col;
29        let x = MARGIN
30            + col_width
31                .add_untouched(GUTTER as f64)
32                .mul_untouched(col as f64);
33        pdf.set_left_margin(x);
34        pdf.set_x(x);
35    };
36    let mut pdf = Fpdf::new(
37        Orientation::Landscape,
38        PageSize::A4,
39        "",
40        UnitVec2::default(),
41    );
42    pdf.set_catalog_sort(true);
43    pdf.set_compression(false);
44    pdf.set_header_fn(|pdf| {
45        let title = "fpdf-rs";
46        pdf.set_font("Helvetica", "B", Unit::pt(48.0));
47        let width = pdf.get_string_width(title).add_untouched(6.0);
48        pdf.set_x((WIDTH - width).div_untouched(2.0));
49        pdf.set_text_color(RGB::new(128, 128, 160));
50        pdf.write(Unit::mm(12.0), &title[..4]);
51        pdf.set_text_color(RGB::new(128, 128, 128));
52        pdf.write(Unit::mm(12.0), &title[4..5]);
53        pdf.set_text_color(RGB::new(170, 39, 4));
54        pdf.write(Unit::mm(12.0), &title[5..]);
55        pdf.ln(Unit::mm(20.0));
56        let mut y0 = y0.borrow_mut();
57        *y0 = pdf.get_y();
58    });
59    pdf.set_accept_page_break_fn(|pdf| -> bool {
60        let current_col = {
61            let cc = current_col.borrow();
62            *cc
63        };
64        if current_col < COLS - 1 {
65            set_col(pdf, current_col + 1);
66            let y0 = {
67                let y0 = y0.borrow();
68                *y0
69            };
70            pdf.set_y(y0);
71            false
72        } else {
73            set_col(pdf, 0);
74            true
75        }
76    });
77    pdf.add_page();
78    pdf.set_font("Times", "", Unit::pt(12.0));
79    for i in 0..20 {
80        if i == 1 {
81            pdf.image(
82                "examples/resources/fpdf.png",
83                Unit::negative(),
84                Unit::mm(0.0),
85                UnitVec2::mm(col_width.to_mm(), 0.0),
86                true,
87                ImageOptions::default_png(),
88                0,
89                "",
90            );
91        } else if i == 5 {
92            pdf.image(
93                "examples/resources/rust-ferris.png",
94                Unit::negative(),
95                Unit::mm(0.0),
96                UnitVec2::mm(col_width.to_mm(), 0.0),
97                true,
98                ImageOptions::default_png(),
99                0,
100                "",
101            );
102        }
103        pdf.multi_cell(col_width, Unit::mm(5.0), lorem.as_str(), "", "", false);
104        pdf.ln(Unit::negative());
105    }
106    pdf.output_file_and_close("example_set_accept_page_break_fn.pdf")
107        .unwrap();
108}
Source

pub fn svg_basic_file_parse(svg_file: &str) -> Result<SVGBasic>

Examples found in repository?
examples/example_svg_basic_write.rs (line 23)
13fn main() {
14    const FONT_SIZE: Unit = Unit::pt(16.0);
15    const WIDTH: Unit = Unit::mm(100.0);
16    const SVG_FILE_PATH: &'static str = "examples/resources/drawing.svg";
17
18    let mut pdf = Fpdf::default();
19    pdf.set_font("Times", "", FONT_SIZE);
20    pdf.add_page();
21    pdf.set_margins(Unit::mm(10.0), Unit::mm(10.0), Unit::mm(10.0));
22    pdf.write_basic_html(FONT_SIZE, HTML);
23    let svg_file = Fpdf::svg_basic_file_parse(SVG_FILE_PATH).unwrap();
24    let mut scale = 100.0 / svg_file.width;
25    let scale_y = 30.0 / svg_file.height;
26    if scale > scale_y {
27        scale = scale_y;
28    }
29    pdf.set_line_cap_style("round");
30    pdf.set_line_width(Unit::mm(0.25));
31    pdf.set_draw_color(RGB::new(0, 0, 128));
32    let y = pdf.get_y();
33    pdf.set_xy(Unit::mm(210.0 - scale * svg_file.width) / 2.0, y + 10.0);
34    pdf.svg_basic_write(&svg_file, Unit::mm(scale));
35    pdf.output_file_and_close("example_svg_basic_write.pdf")
36        .unwrap();
37}
Source

pub fn deserialize_template(b: Vec<u8>) -> Result<impl Template>

Trait Implementations§

Source§

impl<'a> Clone for Fpdf<'a>

Source§

fn clone(&self) -> Fpdf<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Fpdf<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Pdf<'a> for Fpdf<'a>

Source§

fn add_attachment_annotation( &mut self, a: Rc<RefCell<Attachment>>, x: Unit, y: Unit, w: Unit, h: Unit, )

Puts a link on the current page, on the rectangle defined by x, y, w and h. This link points towards the content defined in a, which is embedded in the document. Note that no drawing is done by this method: a method like Pdf::cell or Pdf::rect should be called to indicate to the reader, that there is a link. Attachment pointing to the same data will have their content only be included once, and shared amongst all links. Read more
Source§

fn add_font( &mut self, family: &str, style: &str, file: &str, is_utf8: bool, ) -> Result<()>

Imports a TrueType, OpenType or Type1 font and makes it available. It is neccessary to generate a font definition file first with the Makefont utility. It is not necessary to call this function for the core PDF fonts (courier, helvetica, times, zapfdingbats). Read more
Source§

fn add_font_from_bytes( &mut self, family: &str, style: &str, json_file_bytes: Vec<u8>, z_file_bytes: Vec<u8>, )

Imports a TrueType, OpenType or Type1 font from static bytes within the static executable and makes it available. Read more
Source§

fn add_font_from_reader(&mut self, family: &str, style: &str, r: Box<dyn Read>)

Source§

fn add_layer(&mut self, name: &str, visible: bool) -> usize

Defines a layer that can be shown of hidden when the document is displayed. Read more
Creates a new internal link and returns its ID. An internal link is a clickable area which directs to another place within the document. The ID can then be passed to Pdf::cell, Pdf::write, Pdf::image, or Pdf::link. The destination can be defined with Pdf::set_link.
Source§

fn add_page(&mut self)

Adds a new page to the PDF document. If a page is already present, the footer (see Pdf::set_footer_fn) callback function is called first to output the footer. Then the page is added, the current position is set to the top-left corner according to the left and top margins, and the header (see Pdf::set_header_fn) callback function is called to display the header. Read more
Source§

fn add_page_format(&mut self, orientation: Orientation, size: UnitVec2)

Adds a new page with non-default page size and orientation. See Pdf::add_page for more details.
Source§

fn add_spot_color(&mut self, name: &str, c: u8, m: u8, y: u8, k: u8)

Adds an ink-based CMYK color to the current Pdf instance and associates it with the specified name. The individual components specify percentages ranging from 0 to 100. Values above are quietly capped to 100. Read more
Source§

fn alias_nb_pages(&mut self, alias: &str)

Defines an alias for the total number of pages. It will be substituted as the document is closed. An empty string is replaced with the string “{nb}”.
Source§

fn arc_to( &mut self, x: Unit, y: Unit, rx: Unit, ry: Unit, deg_rotate: f64, deg_start: f64, deg_end: f64, )

Draws an elliptical arc centered at point (x, y). rx and ry specify its horizontal and vertical radii. If the start of the arc is not at the current position, a connection line will be drawn. Read more
Source§

fn arc( &mut self, x: Unit, y: Unit, rx: Unit, ry: Unit, deg_rotate: f64, deg_start: f64, deg_end: f64, style: &str, )

Draws an elliptical arc centered at point (x, y). rx and ry specify its horizontal and vertical radii. Read more
Source§

fn begin_layer(&mut self, id: usize)

Add content to the specified layer. All content added to the page between a call to Pdf::begin_layer and Pdf::end_layer is added to the layer specified by id. See Pdf::add_layer for more details.
Source§

fn beziergon(&mut self, points: &[UnitVec2], style: &str)

Draws a closed figure defined by a series of cubic Bézier curve segments. The first point in the slice defines the starting point of the figure. Each three following points p1, p2, p3 represent a curve segment of the point p3 using p1 and p2 as the Bézier control points. Read more
Source§

fn bookmark(&mut self, y: Option<Unit>, text: &str, level: usize)

Set a bookmark that will be displayed in a sidebar outline. Read more
Source§

fn cell_format( &mut self, w: Unit, h: Unit, text: &str, border: &str, ln: isize, align: &str, fill: bool, link: usize, link_str: &str, )

Prints a rectangular cell with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or the next line. It is possible to put a link on the text. Read more
Source§

fn cell(&mut self, w: Unit, h: Unit, text: &str)

A simpler version of Pdf::cell_format with no fill, border, links or special alignment. Read more
Source§

fn circle(&mut self, x: Unit, y: Unit, r: Unit, style: &str)

Draws a circle centered on point (x, y) with radius r. Read more
Source§

fn clear_error(&mut self)

Unsets the internal FPDF error. This method should be used with care, as an internal error condition usually indicates an unrecoverable problem with the generation of a document. It is intended to deal with cases in which an error is used to select an alternate form of the document.
Source§

fn clip_circle(&mut self, x: Unit, y: Unit, r: Unit, outline: bool)

Begins a circular clipping operation. The circle is centered at (x, y) and has radius r. Read more
Source§

fn clip_ellipse(&mut self, x: Unit, y: Unit, rx: Unit, ry: Unit, outline: bool)

Begins an elliptical clipping operation. The ellipse is centered at (x, y). Read more
Source§

fn clip_end(&mut self)

Ends a clipping operation that was previously started with a call to Pdf::clip_rect, Pdf::clip_rounded_rect, Pdf::clip_text, Pdf::clip_ellipse, Pdf::clip_circle or Pdf::clip_polygon. Read more
Source§

fn clip_polygon(&mut self, points: &[UnitVec2], outline: bool)

Begins a clipped operation within a polygon. The figure is defined by a series of vertices specified by points. The last point in the slice will be implicitly joined to the first to close the polygon. Read more
Source§

fn clip_rect(&mut self, x: Unit, y: Unit, w: Unit, h: Unit, outline: bool)

Begins a rectangular clipping operation. Read more
Source§

fn clip_rounded_rect( &mut self, x: Unit, y: Unit, w: Unit, h: Unit, r: Unit, outline: bool, )

Begins a rectangular clipping operation. Read more
Source§

fn clip_rounded_rect_ext( &mut self, x: Unit, y: Unit, w: Unit, h: Unit, rtl: Unit, rtr: Unit, rbr: Unit, rbl: Unit, outline: bool, )

This method behaves the same as Pdf::clip_rounded_rect, but supports a different radius for each corner, given by the arguments rtl (top-left), rtr (top-right), rbr (bottom-right), and rbl (bottom-left). See Pdf::clip_rounded_rect for more details. Read more
Source§

fn clip_text(&mut self, x: Unit, y: Unit, text: &str, outline: bool)

Begins a clipping operations in which rendering is confined to the character string specified by text. Read more
Source§

fn close(&mut self)

Terminate the PDF document. It is not necessary to call this method explicitly, because Pdf::output, Pdf::output_and_close and Pdf::output_file_and_close do it automatically. If the document contains no page, Pdf::add_page is called to prevent the generation of an invalid document.
Source§

fn close_path(&mut self)

Creates a line from the current location to the last Pdf::move_to location (if not the same) and mark the path as closed, so the first and last lines join nicely. Read more
Source§

fn create_template_custom( &mut self, corner: Vec2, size: UnitVec2, cb: impl FnMut(&mut Self, &mut Tpl<'_>) + 'a, ) -> impl Template

Starts a template, using the given bounds.
Source§

fn create_template( &mut self, cb: impl FnMut(&mut Tpl<'_>) + 'a, ) -> impl Template

Defines a new template using the current page size.
Source§

fn curve_bezier_cubic_to( &mut self, x: Unit, y: Unit, cx0: Unit, cy0: Unit, cx1: Unit, cy1: Unit, )

Creates a single-segment cubic Bézier curve. The curve starts at the current stylus location and ends at the point (x, y). The control points (cx0, cy0) and (cx1, cy1) specify the curvature. Read more
Source§

fn curve_bezier_cubic( &mut self, x0: Unit, y0: Unit, cx0: Unit, cy0: Unit, x1: Unit, y1: Unit, cx1: Unit, cy1: Unit, style: &str, )

Creates a single-segment cubic Bézier curve. The curve starts at the point (x0, y0) and ends at the point (x1, y1). The control points (cx0, cy0) and (cx1, cy1) specify the curvature. Read more
Source§

fn curve_to(&mut self, x: Unit, y: Unit, cx: Unit, cy: Unit)

Creates a single-segment quadratic Bézier curve. The curve starts at the current stylus location and ends at the point (x, y). The control point (cx, cy) specifies the curvature. Read more
Source§

fn curve( &mut self, x0: Unit, y0: Unit, x1: Unit, y1: Unit, cx: Unit, cy: Unit, style: &str, )

Draws a single-segment quadratic Bézier curve. The curve starts at point (x0, y0) and ends at the point (x1, y1). The control point (cx0, cy0) specifies the curvature. At the start point, the curve is tangent to the straight line between the start point and the control point. At the end point, the curve is tangent to the straight line between the end point and the control point. Read more
Source§

fn draw_path(&mut self, style: &str)

Draws the path on the page.
Source§

fn ellipse( &mut self, x: Unit, y: Unit, rx: Unit, ry: Unit, deg_rotate: f64, style: &str, )

Draws an ellipse centered at point (x, y). Read more
Source§

fn end_layer(&mut self)

Is called to stop adding content to the currently active layer. See Pdf::begin_layer for more details.
Source§

fn err(&self) -> bool

Returns true if a processing error has occured.
Source§

fn error(&self) -> Result<()>

Returns the internal FPDF error; it is of value Ok if no error has occured.
Source§

fn get_alpha(&self) -> (f64, Blend)

Returns the alpha blending channel, which consists of the alpha transparency value and the blend mode. See Pdf::set_alpha for more details.
Source§

fn get_auto_page_break(&mut self) -> (bool, Unit)

Returns true if automatic page breaks are enabled, false otherwise. This is followed by the triggering limit from the bottom of the page. This value applies only if automatic page break are enabled.
Source§

fn get_cell_margin(&mut self) -> Unit

Returns the cell margin. This is the amount of space before and after a text within a cell that’s left blank. It defaults to [Unit::Millimeter(1.0)].
Source§

fn get_draw_color(&mut self) -> RGB

Returns the most recently set draw color as RGB components (0 - 255). This will not be the current value if a draw color of some other type (e.g. spot) has been more recently set.
Source§

fn get_draw_spot_color(&mut self) -> CMYKColorName

Returns the most recently used spot color information for drawing. This will not be the current drawing color if some other color type, such as RGB is active. If no spot has been set for drawing, then all values are set to [0].
Source§

fn get_fill_color(&mut self) -> RGB

Returns the most recently set fill color as RGB components (0 - 255). This will not be the current value if a draw color of some other type (e.g. spot) has been more recently set.
Source§

fn get_fill_spot_color(&mut self) -> CMYKColorName

Returns the most recently used spot color information for fill output. This will not be the current drawing color if some other color type, such as RGB is active. If no fill spot color has been set, then all values are set to [0].
Source§

fn get_font_desc(&mut self, family: &str, style: &str) -> FontDesc

Returns the font descriptor, which can be used for example to find the baseline of a font. If family is empty, the current font descriptor will be returned. See FontDesc for documentation about the font descriptor. See Pdf::add_font for details about family and style.
Source§

fn get_font_size(&mut self) -> Unit

Returns the size of the current font.
Source§

fn get_image_info(&mut self, image: &str) -> Option<ImageInfo>

Returns information about the registered image specified by image. If the image has not been registered, None is returned. The internal error is not modified by this method.
Source§

fn get_line_width(&mut self) -> Unit

Returns the current line thickness.
Source§

fn get_margins(&self) -> Margin

Returns the page margins.
Source§

fn get_page_size_str(&mut self, size: &str) -> UnitVec2

Returns the current page’s width x and height y in points. This is the paper’s size. To compute the size of the area being used, subtract the margins (see Pdf::get_margins).
Source§

fn get_page_size(&self) -> UnitVec2

Returns the current page’s width x and height y. This is the paper’s size. To compute the size of the area being used, subtract the margins (see Pdf::get_margins).
Source§

fn get_string_symbol_width(&self, s: &str) -> Unit

Returns the length of a string in glyf units. A font must be currently selected.
Source§

fn get_string_width(&self, s: &str) -> Unit

Returns the length of a string in user units. A font must be currently selected.
Source§

fn get_text_color(&mut self) -> RGB

Returns the most recently set text color as RGB components (0 - 255). This will not be the current value if a text color of some other type (e.g. spot) has been more recently set.
Source§

fn get_text_spot_color(&mut self) -> CMYKColorName

Returns the most recently used spot color information for text output. This will not be the current text color if some other color type such as RGB is active. If no spot color has been set for text, then all values are set to [0].
Source§

fn get_x(&mut self) -> Unit

Returns the abscissa of the current position. Read more
Source§

fn get_xy(&mut self) -> (Unit, Unit)

Returns the abscissa and ordinate of the current position. Read more
Source§

fn get_y(&mut self) -> Unit

Returns the ordinate of the current position.
Source§

fn image( &mut self, image_name: &str, x: Unit, y: Unit, dimensions: UnitVec2, flow: bool, options: ImageOptions, link: usize, link_str: &str, )

Puts a JPEG, PNG or GIF image in the current page. Read more
Source§

fn image_type_from_mime(&mut self, mime: &str) -> Result<ImageType>

Returns the image type used in various image-related functions (e.g. Pdf::image) that is associated with the specified MIME type. For example, [Ok(ImageType::JPG)] is returned if mime is “image/jpeg”. An error is set if the specified MIME type is not supported.
Source§

fn linear_gradient( &mut self, x: Unit, y: Unit, w: Unit, h: Unit, x1: f64, y1: f64, x2: f64, y2: f64, rgb_from: RGB, rgb_to: RGB, )

Draws a rectangular area with a blending of one color to another. The rectangle is of width w and height h. Its upper left corner is positioned at point (x, y). Read more
Source§

fn line_to(&mut self, x: Unit, y: Unit)

Creates a line from the current stylus location to (x, y), which becomes the new stylus location. Read more
Source§

fn line(&mut self, x1: Unit, y1: Unit, x2: Unit, y2: Unit)

Draws a line between points (x1, y1) and (x2, y2) using the current draw color, line width and cap style.
Puts a link on a rectangular area of the page. Text or image links are generally put via Pdf::cell, Pdf::write or Pdf::image, but this method can be useful, for instance, to define a clickable area inside an image. link_str is the target URL.
Puts a link on a rectangular area of the page. Text or image links are generally put via Pdf::cell, Pdf::write or Pdf::image, but this method can be useful, for instance, to define a clickable area inside an image. link is the value returned by Pdf::add_link.
Source§

fn ln(&mut self, h: Unit)

Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in the parameter. A negative value for h indicates the height of the last printed cell. Read more
Source§

fn ltr(&mut self)

Disables right-to-left mode.
Source§

fn move_to(&mut self, x: Unit, y: Unit)

Moves the stylus to (x, y) without drawing the path from the previous point. Paths must start with a Pdf::move_to to set the original stylus location or the result is undefined. Read more
Source§

fn multi_cell( &mut self, w: Unit, h: Unit, text: &str, border: &str, align: &str, fill: bool, )

Print text with line breaks. The line breaks can be automatic, by reaching the right border of the cell, or explicit by using the \n character. As many cells as necessary are output, one below the other. Read more
Source§

fn ok(&self) -> bool

Returns true if no processing errors have occured.
Source§

fn open_layer_pane(&mut self)

Advises the document reader to open the layer pane when the document is initially displayed.
Source§

fn output_and_close(&mut self, w: Box<dyn Write>) -> Result<()>

Sends the PDF document to the writer specified by w. This method will close the PDF document writer, even if an error is returned and no document is produced.
Source§

fn output_file_and_close(&mut self, file: &str) -> Result<()>

Creates or truncates the file specified by file and writes the PDF document to it. This method will close the PDF document writer, even if an error is returned and no document is produced.
Source§

fn output(&mut self, w: Box<dyn Write>) -> Result<()>

Output sends the PDF document to the writer specified by w. No output will take place if an error has occured in the document generation process. w remains open after this function returns. After returning, the PDF document writer is in a closed state and its methods should not be called.
Source§

fn page_count(&mut self) -> usize

Returns the number of pages currently in the document. Since page numbers in FPDF are one-based, the page count is the same as the page number of the current last page.
Source§

fn page_no(&self) -> usize

Returns the current page number. Read more
Source§

fn page_size(&mut self, page_num: usize) -> UnitVec2

Returns the width x and height y of the specified page in Unit::Point. If page_num is [0] or otherwise out of bounds, it returns the default page size.
Source§

fn polygon(&mut self, points: &[UnitVec2], style: &str)

Draws a closed figure defined by a series of vertices specified by points. The last point in the slice will be implicitly joined with the first to close the polygon. Read more
Source§

fn radial_gradient( &mut self, x: Unit, y: Unit, w: Unit, h: Unit, x1: f64, y1: f64, x2: f64, y2: f64, r: f64, rgb_from: RGB, rgb_to: RGB, )

Draws a rectangular area with a blending of one color to another. The rectangle is of width w and height h. Its upper left corner is positioned at point (x, y). Read more
Source§

fn raw_write_buf(&mut self, r: impl Read)

Writes the contents of the specified reader r directly to the PDF generation buffer. This is a low-level function that is not required for normal PDF construction. An understanding of the PDF specification is needed to use this method correctly.
Source§

fn raw_write_str(&mut self, s: &str)

Writes the string s directly to the PDF generation buffer. This is a low-level function that is not required for normal PDF construction. An understanding of the PDF specification is needed to use this method correctly.
Source§

fn rect(&mut self, x: Unit, y: Unit, w: Unit, h: Unit, style: &str)

Outputs a rectangle of width w and height h with the upper left corner positioned at point (x, y). Read more
Source§

fn register_alias(&mut self, alias: &str, replacement: &str)

Adds an (alias, replacement) pair to the document, such that all occurrences of alias will be replaced with replacement after writing, but before closing the document. Read more
Source§

fn register_image( &mut self, file: &str, options: ImageOptions, ) -> Result<ImageInfo>

Registers an image, adding it to the PDF file, but not adding it to the page. Use Pdf::image with the same file name to add the image to the page. Read more
Source§

fn register_image_reader( &mut self, file: &str, options: ImageOptions, r: impl Read, ) -> Result<ImageInfo>

Registers an image, reading it from r, adding it to the PDF file but not adding it to the page. Use Pdf::image with the same file name to add the image to the page. Read more
Source§

fn rounded_rect( &mut self, x: Unit, y: Unit, w: Unit, h: Unit, r: Unit, corners: &str, style: &str, )

Outputs a rectangle of width w and height h with the upper left corner positioned at point (x, y). It can be drawn (border only), filled (with no border), or both. Read more
Source§

fn rounded_rect_ext( &mut self, x: Unit, y: Unit, w: Unit, h: Unit, rtl: Unit, rtr: Unit, rbr: Unit, rbl: Unit, style: &str, )

Behaves the same as Pdf::rounded_rect but supports a different radius for each corner. A radius of [0] means squared corner. See Pdf::rounded_rect for more details.
Source§

fn rtl(&mut self)

Enables right-to-left mode.
Source§

fn set_accept_page_break_fn(&mut self, cb: impl FnMut(&mut Self) -> bool + 'a)

Allows the library to control where page breaks occur. Read more
Source§

fn set_alpha(&mut self, alpha: f64, blend_mode: Blend)

Sets the alpha blending channel. The blending effect applies to text, drawings and images. Read more
Source§

fn set_attachments(&mut self, attachments: Vec<Attachment>)

Writes attachments as embedded files (document attachments). These attachments are global, see Pdf::add_attachment_annotation for a link anchored in a page. Read more
Source§

fn set_author(&mut self, author: &str, is_utf8: bool)

Defines the author of the document. Read more
Source§

fn set_auto_page_break(&mut self, auto: bool, margin: Unit)

Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defined the triggering limit. By default, the mode is on and the margin is 2cm.
Source§

fn set_catalog_sort(&mut self, flag: bool)

Sets a flag that will be used, if true, to consistently order the document’s internal resource catalogs. This method is typically only used for testing purposes to facilitate PDF comparison.
Source§

fn set_cell_margin(&mut self, margin: Unit)

Sets the cell margin. This is the amount of space before and after the text within a cell, that is left blank.
Source§

fn set_compression(&mut self, compress: bool)

Activates or deactivates page compression with zlib. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 (untested) for the resulting document. Compression is on by default.
Source§

fn set_creation_date(&mut self, datetime: DateTime)

Fixes the document’s internal creation date value. By default, the time when the document is generated is used for this value. This method is typically only used for testing purposes to facilitate PDF comparison. Specify a zero-value time to revert to the default behavior.
Source§

fn set_creator(&mut self, creator: &str, is_utf8: bool)

Defines the creator of the document. Read more
Source§

fn set_dash_pattern(&mut self, dashes: Vec<Unit>, phase: Unit)

Sets the dash pattern that is used to draw lines. Read more
Source§

fn set_display_mode(&mut self, zoom: ZoomMode, layout: Layout)

Sets the advisory display directives for the document viewer. Pages can be displayed entirely on screen, occupy the full width of the window, use real size, be scaled by a specific zoom factor or use viewer default. The page layout can be specified, so that pages are displayed individually or in pairs. Read more
Source§

fn set_lang(&mut self, lang: &str)

Set the natural language of the document (e.g. “de-DE”).
Source§

fn set_draw_color(&mut self, rgb: RGB)

Defines the color used for all drawing operations (lines, rectangles and cell borders). It is expressed in RGB components (0 - 255). The method can be called before the first page is created. The value is retained from page to page.
Source§

fn set_draw_spot_color(&mut self, name: &str, tint: u8)

Sets the current draw color to the spot color associated with name. An error occurs if the name is not associated with a color. The value for tint ranges from 0 (no intensity) to 100 (full intensity). It is quietly bound to this range.
Source§

fn set_error(&mut self, err: FpdfError)

Sets an error to halt PDF generation. This may facilitate error handling by application. See also Pdf::ok, Pdf::err and Pdf::error.
Source§

fn set_fill_color(&mut self, rgb: RGB)

Defines the color used for all filling operations (filled rectangles and cell backgrounds). It is expressed in RGB components (0 - 255). The method can be called before the first page is created and the value is retained from page to page.
Source§

fn set_fill_spot_color(&mut self, name: &str, tint: u8)

Sets the current fill color to the spot color associated with name. An error occurs if the name is not associated with a color. The value for tint ranges from 0 (no intensity) to 100 (full intensity). It is quietly bound to this range.
Source§

fn set_font(&mut self, family: &str, style: &str, size: Unit)

Sets the fonts used print character strings. It is mandatory to call this method at least once before printing text or the resulting document will not be valid. Read more
Source§

fn set_font_loader(&mut self, loader: Option<Rc<dyn FontLoader>>)

Sets a loader to read font files (.json and .z) from an arbitrary source. If a font loader has been specified, it is used to load the names font resource when Pdf::add_font is called. If this operation fails, an attempt is made to load the resources from the configured font directory (see Pdf::set_font_location).
Source§

fn set_font_location(&mut self, font_dir: &str)

Sets the location in the file stystem of the font and font definition files.
Source§

fn set_font_size(&mut self, size: Unit)

Defines the size of the current font. It is usually provided in Unit::Point.
Source§

fn set_font_style(&mut self, style: &str)

Sets the style of the current font. See also Pdf::set_font.
Sets the function that lets the library render the page footer. The specified function is automatically called by Pdf::add_page and Pdf::close and should not be called directly by the application. Read more
Sets the function thats lets the library render the page footer. The specified function is automatically called by Pdf::add_page and Pdf::close and should not be called directly by the application. Read more
Source§

fn set_header_fn(&mut self, cb: impl FnMut(&mut Self) + 'a)

Sets the function that lets the library render the page header. The specified function is automatically called by Pdf::add_page and Pdf::close and should not be called directly by the application. Read more
Source§

fn set_header_fn_mode( &mut self, cb: impl FnMut(&mut Self) + 'a, home_mode: bool, )

Sets the function that lets the library render the page header. See Pdf::set_header_fn for more details. Read more
Source§

fn set_home_xy(&mut self)

Is a convenience method that sets the current position to the left and top margins.
Source§

fn set_javascript(&mut self, script: &str)

Adds Adobe JavaScript to the document. Read more
Source§

fn set_keywords(&mut self, keywords: &str, is_utf8: bool)

Defines the keywords of the document. Read more
Source§

fn set_left_margin(&mut self, margin: Unit)

Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin. Read more
Source§

fn set_line_cap_style(&mut self, style: &str)

Defines the line cap style. Read more
Source§

fn set_line_join_style(&mut self, style: &str)

Defines the line cap style. Read more
Source§

fn set_line_width(&mut self, width: Unit)

Defines the line width. By default, the value equals [Unit::Millimeter(0.2)]. The method can be called before the first page is created. The value is retained from page to page.
Defines the page and position a link points to. See Pdf::add_link.
Source§

fn set_margins(&mut self, left: Unit, top: Unit, right: Unit)

Defines the left, top and right margins. By default, they equal [Unit::Centimeter(1.0)]. Call this method to change them. If the value of the right margin is less than [0.0], it is set to the same as the left margin.
Source§

fn set_modification_date(&mut self, tm: DateTime)

Fixes the document’s internal modification date value. See Pdf::set_creation_date for more details. Read more
Source§

fn set_page_box_rec(&mut self, t: &str, pb: PageBox)

Sets the page box for the current page, and any following pages. Read more
Source§

fn set_page_box(&mut self, x: Unit, y: Unit, width: Unit, height: Unit, t: &str)

Sets the page box for the current page, and any following pages. Read more
Source§

fn set_page(&mut self, page_num: usize)

Sets the current page to that of a valid page in the PDF document. Read more
Source§

fn set_producer(&mut self, producer: &str, is_utf8: bool)

Defines the producer of the document. Read more
Source§

fn set_protection( &mut self, action_flag: u8, user_password: &str, owner_password: &str, )

Applies certain constrains on the finished PDF document. Read more
Source§

fn set_right_margin(&mut self, margin: Unit)

Defines the right margin. The method can be called before creating the first page.
Source§

fn set_subject(&mut self, subject: &str, is_utf8: bool)

Defines the subject of the document. Read more
Source§

fn set_text_color(&mut self, rgb: RGB)

Defines the color used for text. It is expressed in RGB components (0 - 255). The method can be called before the first page is created. The value is retained from page to page. Read more
Source§

fn set_text_spot_color(&mut self, name: &str, tint: u8)

Sets the current text color to the spot color associated with name. An error occurs if the name is not associated with a color. The value for tint ranges from 0 (no intensity) to 100 (full intensity). It is quietly bound to this range.
Source§

fn set_title(&mut self, title: &str, is_utf8: bool)

Defines the title of the document. Read more
Source§

fn set_top_margin(&mut self, margin: Unit)

Defines the top margin. The method can be called before creating the first page.
Source§

fn set_underline_thickness(&mut self, thickness: f64)

Accepts a multiplier for adjusting the text underline thickness, defaulting to [1.0]. Read more
Source§

fn set_word_spacing(&mut self, space: Unit)

Sets spacing between words of following text. See Pdf::write_aligned example for a demonstration of its use.
Source§

fn set_text_rendering_mode(&mut self, mode: u8)

Sets the rendering mode of following text. The mode can be as follows: Read more
Source§

fn set_xmp_metadata(&mut self, xmp_stream: Vec<u8>)

Defines the XMP metadata that will be embedded with the document.
Source§

fn set_x(&mut self, x: Unit)

Defines the abscissa of the current position. If the passed value is negative, it is relative to the right of the page.
Source§

fn set_xy(&mut self, x: Unit, y: Unit)

Defined the abscissa and ordinate of the current position. If the passed values are negative, they are relative respectively to the right and bottom of the page.
Source§

fn set_y(&mut self, y: Unit)

Moves the current abscissa back to the left margin and sets the ordinate. If the passed value is negative, it is relative to the bottom of the page.
Source§

fn split_lines(&mut self, text: &[u8], width: Unit) -> Vec<Vec<u8>>

Splits text into several lines using the current font. Each line has its length limited to a maximum width. This function can be used to determine the total height of wrapped text for vertical placement purposes. Read more
Source§

fn split_text(&mut self, text: &str, width: Unit) -> Vec<String>

Splits UTF-8 encoded text into several lines using the current font. Each line has its length limited to a maximum width. This function can be used to determine the total height of wrapped text for vertical placement purposes.
Source§

fn string(&self) -> &'static str

Summarized the PDF instance.
Source§

fn svg_basic_write(&mut self, sb: &SVGBasic, scale: Unit)

Renders the paths encoded in the basic SVH image specified by sb. Read more
Source§

fn sub_write( &mut self, height: Unit, text: &str, sub_font_size: Unit, sub_offset: Unit, link: usize, link_str: &str, )

Prints text from the current position in the same way as Pdf::write. Read more
Source§

fn text(&mut self, x: Unit, y: Unit, text: &str)

Prints a character string. The origin (x, y) is on the left of the first character at the baseline. This method permits a string to be placed precisely on the page, but it is usually easier to use Pdf::cell, Pdf::multi_cell or Pdf::write which are the standard methods to print text.
Source§

fn transform_begin(&mut self)

Sets up a transformation context for subsequent text, drawings and images. The typical usage is to immediately follow a call to this method with a call to one or more of the transformation methods, such as Pdf::transform_scale, Pdf::transform_skew, etc. This is followed by text, drawing or image output and finally a call to Pdf::transform_end. All transformation contexts must be properly ended prior to outputting the document. Read more
Source§

fn transform_end(&mut self)

Applies a transformation that was begun with a call to Pdf::transform_begin. Read more
Source§

fn transform_mirror_horizontal(&mut self, x: Unit)

Horizontally mirrors the following text, drawings and images. Read more
Source§

fn transform_mirror_line(&mut self, x: Unit, y: Unit, angle: f64)

Symmetrically mirrors the following text, drawings and images on the line defined by angle and the point (x, y). Read more
Source§

fn transform_mirror_point(&mut self, x: Unit, y: Unit)

Symmetrically mirrors the following text, drawings and images on the point specified by (x, y). Read more
Source§

fn transform_mirror_vertical(&mut self, y: Unit)

Vertically mirrors the following text, drawings and images. y is the axis of reflection. Read more
Source§

fn transform_rotate(&mut self, x: Unit, y: Unit, angle: f64)

Rotates the following text, drawings and images around the center point (x, y). Read more
Source§

fn transform_scale( &mut self, x: Unit, y: Unit, scale_width: f64, scale_height: f64, )

Generally scales the following text, drawings and images. Read more
Source§

fn transform_scale_x(&mut self, x: Unit, y: Unit, scale_width: f64)

Scales the width of the following text, drawings and images. Read more
Source§

fn transform_scale_xy(&mut self, x: Unit, y: Unit, s: f64)

Uniformly scales the width and height of the following text, drawings and images. Read more
Source§

fn transform_scale_y(&mut self, x: Unit, y: Unit, scale_height: f64)

Scales the height of the following text, drawings and images. Read more
Source§

fn transform_skew(&mut self, x: Unit, y: Unit, angle_x: f64, angle_y: f64)

Generally skews the following text, drawings and images keeping the point (x, y) stationary. Read more
Source§

fn transform_skew_x(&mut self, x: Unit, y: Unit, angle_x: f64)

Horizontally skews the following text, drawings and images keeping the point (x, y) stationary. Read more
Source§

fn transform_skew_y(&mut self, x: Unit, y: Unit, angle_y: f64)

Vertically skews the following text, drawings and images keeping the point (x, y) stationary. Read more
Source§

fn transform(&mut self, tm: &TransformMatrix)

Generally transforms the following text, drawings and images according to the specified matrix tm. It is typically easier to use the various methods, such as Pdf::transform_rotate and Pdf::transform_mirror_vertical instead.
Source§

fn transform_translate(&mut self, tx: Unit, ty: Unit)

Moves the following text, drawings and images horizontally and vertically by the amounts specified by tx and ty. Read more
Source§

fn transform_translate_x(&mut self, tx: Unit)

Moves the following text, drawings and images horizontally by the amount specified by tx. Read more
Source§

fn transform_translate_y(&mut self, ty: Unit)

Moves the following text, drawings and images vertically by the amount specified by ty. Read more
Source§

fn unicode_translator_from_descriptor( &mut self, cp: &str, ) -> Rc<dyn Fn(String) -> String>

Returns a function, that can be used to translate, where possible, UTF-8 string to a form that is compatible with the specified code page. See [Pdf::unicode_translator] for more details. Read more
Source§

fn use_imported_template( &mut self, t: &str, scale_x: Unit, scale_y: Unit, tx: Unit, ty: Unit, )

Uses imported template. It draws imported PDF page ontp page.
Source§

fn use_template_scaled( &mut self, t: Rc<dyn Template>, corner: Vec2, size: UnitVec2, )

Adds a template to the current page or another template, using the given page coordinates.
Source§

fn use_template(&mut self, t: Rc<dyn Template>)

Adds a template to the current page or another template, using the size and position at which it was originally written.
Source§

fn write_aligned( &mut self, width: Unit, line_height: Unit, text: &str, align: &str, )

Is an implementation of Pdf::write that makes it possible to align text. Read more
Source§

fn write(&mut self, h: Unit, text: &str)

Prints text from the current position. When the right margin is reached (or the ‘\n’ character is met), a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text.
Source§

fn write_basic_html(&mut self, line_height: Unit, html: &str)

Write basic HTML into the PDF file. Read more
Writes text that when clicked, jumps to another location in the PDF. Read more
Writes text that when clicked launches an external URL. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Fpdf<'a>

§

impl<'a> !RefUnwindSafe for Fpdf<'a>

§

impl<'a> !Send for Fpdf<'a>

§

impl<'a> !Sync for Fpdf<'a>

§

impl<'a> Unpin for Fpdf<'a>

§

impl<'a> !UnwindSafe for Fpdf<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.