Struct Canvas

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

A visual area where content can be drawn (a page).

Provides methods for defining and stroking or filling paths, as well as placing text objects.

TODO Everything here that takes a BuiltinFont should take any FontSource instead.

Implementations§

Source§

impl<'a> Canvas<'a>

Source

pub fn rectangle( &mut self, x: f32, y: f32, width: f32, height: f32, ) -> Result<()>

Append a closed rectangle with a corner at (x, y) and extending width × height to the to the current path.

Examples found in repository?
examples/text.rs (line 15)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn set_line_join_style(&mut self, style: JoinStyle) -> Result<()>

Set the line join style in the graphics state.

Source

pub fn set_line_cap_style(&mut self, style: CapStyle) -> Result<()>

Set the line join style in the graphics state.

Source

pub fn set_line_width(&mut self, w: f32) -> Result<()>

Set the line width in the graphics state.

Examples found in repository?
examples/circles.rs (line 32)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
Source

pub fn set_stroke_color(&mut self, color: Color) -> Result<()>

Set color for stroking operations.

Examples found in repository?
examples/circles.rs (line 31)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
More examples
Hide additional examples
examples/mandala.rs (line 20)
10fn main() {
11    // Open our pdf document.
12    let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13    let mut args = env::args().skip(1);
14    let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16    // Render a page with something resembling a mandala on it.
17    document
18        .render_page(600.0, 600.0, |c| {
19            c.concat(Matrix::translate(300., 300.))?;
20            c.set_stroke_color(Color::gray(0))?;
21            let segment = 2. * PI / n as f32;
22            for _i in 0..n {
23                c.move_to(0., 33.5)?;
24                c.line_to(0., 250.)?;
25                let r = 99.;
26                c.circle(0., r, r * 1.25 * segment)?;
27                let d = 141.4;
28                let rr = 36.;
29                c.circle(0., d + rr, rr)?;
30                c.stroke()?;
31                c.concat(Matrix::rotate(segment))?;
32            }
33            c.concat(Matrix::rotate(segment / 2.))?;
34            for _i in 0..n {
35                let mut r0 = 58.66;
36                let mut r = 0.7705 * r0 * segment;
37                for _j in 0..(n + 1) / 3 {
38                    c.circle(0., r0, r)?;
39                    let r2 = 1.058 * r;
40                    r0 = r0 + r + r2;
41                    r = r2;
42                }
43                c.stroke()?;
44                c.concat(Matrix::rotate(segment))?;
45            }
46
47            Ok(())
48        })
49        .unwrap();
50    document.finish().unwrap();
51}
examples/text.rs (line 14)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn set_fill_color(&mut self, color: Color) -> Result<()>

Set color for non-stroking operations.

Source

pub fn concat(&mut self, m: Matrix) -> Result<()>

Modify the current transformation matrix for coordinates by concatenating the specified matrix.

Examples found in repository?
examples/mandala.rs (line 19)
10fn main() {
11    // Open our pdf document.
12    let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13    let mut args = env::args().skip(1);
14    let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16    // Render a page with something resembling a mandala on it.
17    document
18        .render_page(600.0, 600.0, |c| {
19            c.concat(Matrix::translate(300., 300.))?;
20            c.set_stroke_color(Color::gray(0))?;
21            let segment = 2. * PI / n as f32;
22            for _i in 0..n {
23                c.move_to(0., 33.5)?;
24                c.line_to(0., 250.)?;
25                let r = 99.;
26                c.circle(0., r, r * 1.25 * segment)?;
27                let d = 141.4;
28                let rr = 36.;
29                c.circle(0., d + rr, rr)?;
30                c.stroke()?;
31                c.concat(Matrix::rotate(segment))?;
32            }
33            c.concat(Matrix::rotate(segment / 2.))?;
34            for _i in 0..n {
35                let mut r0 = 58.66;
36                let mut r = 0.7705 * r0 * segment;
37                for _j in 0..(n + 1) / 3 {
38                    c.circle(0., r0, r)?;
39                    let r2 = 1.058 * r;
40                    r0 = r0 + r + r2;
41                    r = r2;
42                }
43                c.stroke()?;
44                c.concat(Matrix::rotate(segment))?;
45            }
46
47            Ok(())
48        })
49        .unwrap();
50    document.finish().unwrap();
51}
Source

pub fn line(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> Result<()>

Append a straight line from (x1, y1) to (x2, y2) to the current path.

Examples found in repository?
examples/text.rs (line 16)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn move_to(&mut self, x: f32, y: f32) -> Result<()>

Begin a new subpath at the point (x, y).

Examples found in repository?
examples/circles.rs (line 39)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
More examples
Hide additional examples
examples/mandala.rs (line 23)
10fn main() {
11    // Open our pdf document.
12    let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13    let mut args = env::args().skip(1);
14    let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16    // Render a page with something resembling a mandala on it.
17    document
18        .render_page(600.0, 600.0, |c| {
19            c.concat(Matrix::translate(300., 300.))?;
20            c.set_stroke_color(Color::gray(0))?;
21            let segment = 2. * PI / n as f32;
22            for _i in 0..n {
23                c.move_to(0., 33.5)?;
24                c.line_to(0., 250.)?;
25                let r = 99.;
26                c.circle(0., r, r * 1.25 * segment)?;
27                let d = 141.4;
28                let rr = 36.;
29                c.circle(0., d + rr, rr)?;
30                c.stroke()?;
31                c.concat(Matrix::rotate(segment))?;
32            }
33            c.concat(Matrix::rotate(segment / 2.))?;
34            for _i in 0..n {
35                let mut r0 = 58.66;
36                let mut r = 0.7705 * r0 * segment;
37                for _j in 0..(n + 1) / 3 {
38                    c.circle(0., r0, r)?;
39                    let r2 = 1.058 * r;
40                    r0 = r0 + r + r2;
41                    r = r2;
42                }
43                c.stroke()?;
44                c.concat(Matrix::rotate(segment))?;
45            }
46
47            Ok(())
48        })
49        .unwrap();
50    document.finish().unwrap();
51}
Source

pub fn line_to(&mut self, x: f32, y: f32) -> Result<()>

Add a straight line from the current point to (x, y) to the current path.

Examples found in repository?
examples/circles.rs (line 43)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
More examples
Hide additional examples
examples/mandala.rs (line 24)
10fn main() {
11    // Open our pdf document.
12    let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13    let mut args = env::args().skip(1);
14    let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16    // Render a page with something resembling a mandala on it.
17    document
18        .render_page(600.0, 600.0, |c| {
19            c.concat(Matrix::translate(300., 300.))?;
20            c.set_stroke_color(Color::gray(0))?;
21            let segment = 2. * PI / n as f32;
22            for _i in 0..n {
23                c.move_to(0., 33.5)?;
24                c.line_to(0., 250.)?;
25                let r = 99.;
26                c.circle(0., r, r * 1.25 * segment)?;
27                let d = 141.4;
28                let rr = 36.;
29                c.circle(0., d + rr, rr)?;
30                c.stroke()?;
31                c.concat(Matrix::rotate(segment))?;
32            }
33            c.concat(Matrix::rotate(segment / 2.))?;
34            for _i in 0..n {
35                let mut r0 = 58.66;
36                let mut r = 0.7705 * r0 * segment;
37                for _j in 0..(n + 1) / 3 {
38                    c.circle(0., r0, r)?;
39                    let r2 = 1.058 * r;
40                    r0 = r0 + r + r2;
41                    r = r2;
42                }
43                c.stroke()?;
44                c.concat(Matrix::rotate(segment))?;
45            }
46
47            Ok(())
48        })
49        .unwrap();
50    document.finish().unwrap();
51}
Source

pub fn curve_to( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, ) -> Result<()>

Add a Bézier curve from the current point to (x3, y3) with (x1, y1) and (x2, y2) as Bézier controll points.

Source

pub fn circle(&mut self, x: f32, y: f32, r: f32) -> Result<()>

Add a circle approximated by four cubic Bézier curves to the current path. Based on http://spencermortensen.com/articles/bezier-circle/

Examples found in repository?
examples/circles.rs (line 33)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
More examples
Hide additional examples
examples/mandala.rs (line 26)
10fn main() {
11    // Open our pdf document.
12    let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13    let mut args = env::args().skip(1);
14    let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16    // Render a page with something resembling a mandala on it.
17    document
18        .render_page(600.0, 600.0, |c| {
19            c.concat(Matrix::translate(300., 300.))?;
20            c.set_stroke_color(Color::gray(0))?;
21            let segment = 2. * PI / n as f32;
22            for _i in 0..n {
23                c.move_to(0., 33.5)?;
24                c.line_to(0., 250.)?;
25                let r = 99.;
26                c.circle(0., r, r * 1.25 * segment)?;
27                let d = 141.4;
28                let rr = 36.;
29                c.circle(0., d + rr, rr)?;
30                c.stroke()?;
31                c.concat(Matrix::rotate(segment))?;
32            }
33            c.concat(Matrix::rotate(segment / 2.))?;
34            for _i in 0..n {
35                let mut r0 = 58.66;
36                let mut r = 0.7705 * r0 * segment;
37                for _j in 0..(n + 1) / 3 {
38                    c.circle(0., r0, r)?;
39                    let r2 = 1.058 * r;
40                    r0 = r0 + r + r2;
41                    r = r2;
42                }
43                c.stroke()?;
44                c.concat(Matrix::rotate(segment))?;
45            }
46
47            Ok(())
48        })
49        .unwrap();
50    document.finish().unwrap();
51}
Source

pub fn stroke(&mut self) -> Result<()>

Stroke the current path.

Examples found in repository?
examples/circles.rs (line 34)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
More examples
Hide additional examples
examples/mandala.rs (line 30)
10fn main() {
11    // Open our pdf document.
12    let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13    let mut args = env::args().skip(1);
14    let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16    // Render a page with something resembling a mandala on it.
17    document
18        .render_page(600.0, 600.0, |c| {
19            c.concat(Matrix::translate(300., 300.))?;
20            c.set_stroke_color(Color::gray(0))?;
21            let segment = 2. * PI / n as f32;
22            for _i in 0..n {
23                c.move_to(0., 33.5)?;
24                c.line_to(0., 250.)?;
25                let r = 99.;
26                c.circle(0., r, r * 1.25 * segment)?;
27                let d = 141.4;
28                let rr = 36.;
29                c.circle(0., d + rr, rr)?;
30                c.stroke()?;
31                c.concat(Matrix::rotate(segment))?;
32            }
33            c.concat(Matrix::rotate(segment / 2.))?;
34            for _i in 0..n {
35                let mut r0 = 58.66;
36                let mut r = 0.7705 * r0 * segment;
37                for _j in 0..(n + 1) / 3 {
38                    c.circle(0., r0, r)?;
39                    let r2 = 1.058 * r;
40                    r0 = r0 + r + r2;
41                    r = r2;
42                }
43                c.stroke()?;
44                c.concat(Matrix::rotate(segment))?;
45            }
46
47            Ok(())
48        })
49        .unwrap();
50    document.finish().unwrap();
51}
examples/text.rs (line 18)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn close_and_stroke(&mut self) -> Result<()>

Close and stroke the current path.

Examples found in repository?
examples/circles.rs (line 45)
14fn main() {
15    // Open our pdf document.
16    let mut document = Pdf::create("circles.pdf").unwrap();
17
18    // Add a 400x400 pt page.
19
20    // Render-page writes the pdf file structure for a page and
21    // creates a Canvas which is sent to the function that is the last
22    // argument of the render_page method.
23    // That function then puts content on the page by calling methods
24    // on the canvas.
25    document
26        .render_page(400.0, 400.0, |c| {
27            let (x, y) = (200.0, 200.0);
28            let r = 190.0;
29
30            // Set a wide black pen and stroke a circle
31            c.set_stroke_color(Color::rgb(0, 0, 0))?;
32            c.set_line_width(2.0)?;
33            c.circle(x, y, r)?;
34            c.stroke()?;
35
36            // Set a finer yellow pen and stroke a 200-sided polygon
37            c.set_stroke_color(Color::rgb(255, 230, 150))?;
38            c.set_line_width(1.0)?;
39            c.move_to(x + r, y)?;
40            let sides: u8 = 200;
41            for n in 1..sides {
42                let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43                c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44            }
45            c.close_and_stroke()
46        })
47        .unwrap();
48    document.finish().unwrap();
49}
Source

pub fn fill(&mut self) -> Result<()>

Fill the current path.

Source

pub fn get_font(&mut self, font: BuiltinFont) -> FontRef

Get a FontRef for a specific font.

Examples found in repository?
examples/text.rs (line 31)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn text<F, T>(&mut self, render_text: F) -> Result<T>
where F: FnOnce(&mut TextObject<'_>) -> Result<T>,

Create a text object.

The contents of the text object is defined by the function render_text, by applying methods to the TextObject it gets as an argument. On success, return the value returned by render_text.

Examples found in repository?
examples/text.rs (lines 32-44)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn left_text( &mut self, x: f32, y: f32, font: BuiltinFont, size: f32, text: &str, ) -> Result<()>

Utility method for placing a string of text.

Examples found in repository?
examples/text.rs (line 20)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn right_text( &mut self, x: f32, y: f32, font: BuiltinFont, size: f32, text: &str, ) -> Result<()>

Utility method for placing a string of text.

Examples found in repository?
examples/text.rs (line 22)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn center_text( &mut self, x: f32, y: f32, font: BuiltinFont, size: f32, text: &str, ) -> Result<()>

Utility method for placing a string of text.

Examples found in repository?
examples/text.rs (lines 24-30)
9fn main() {
10    let mut document = Pdf::create("text.pdf").unwrap();
11    document.set_title("Text example");
12    document
13        .render_page(300.0, 400.0, |c| {
14            c.set_stroke_color(Color::rgb(200, 200, 255))?;
15            c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16            c.line(10.0, 300.0, 290.0, 300.0)?;
17            c.line(150.0, 10.0, 150.0, 390.0)?;
18            c.stroke()?;
19            let helvetica = BuiltinFont::Helvetica;
20            c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21            c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22            c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23            c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24            c.center_text(
25                150.0,
26                330.0,
27                BuiltinFont::Times_Bold,
28                18.0,
29                "Centered",
30            )?;
31            let times = c.get_font(BuiltinFont::Times_Roman);
32            c.text(|t| {
33                t.set_font(&times, 14.0)?;
34                t.set_leading(18.0)?;
35                t.pos(10.0, 300.0)?;
36                t.show("Some lines of text in what might look like a")?;
37                t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38                t.show_line("sit amet. Blahonga. ")?;
39                t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40                t.pos(0., -30.)?;
41                t.show_adjusted(
42                    &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43                )
44            })?;
45
46            // In Swedish, we use the letters å, ä, and ö
47            // in words like sloe liqueur.  That is why rust-pdf
48            // uses /WinAnsiEncoding for text.
49            let times_italic = BuiltinFont::Times_Italic;
50            c.right_text(
51                290.0,
52                200.0,
53                times_italic,
54                14.0,
55                "På svenska använder vi bokstäverna å, ä & ö",
56            )?;
57            c.right_text(
58                290.0,
59                182.0,
60                times_italic,
61                14.0,
62                "i ord som slånbärslikör. Därför använder",
63            )?;
64            c.right_text(
65                290.0,
66                164.0,
67                times_italic,
68                14.0,
69                "rust-pdf /WinAnsiEncoding för text.",
70            )?;
71
72            c.center_text(
73                150.0,
74                130.0,
75                BuiltinFont::Symbol,
76                14.0,
77                "Hellas ΑΒΓΔαβγδ",
78            )?;
79            c.center_text(
80                150.0,
81                114.0,
82                BuiltinFont::Symbol,
83                14.0,
84                "∀ μ < δ : ∃ σ ∈ Σ",
85            )?;
86            c.center_text(
87                150.0,
88                90.0,
89                BuiltinFont::ZapfDingbats,
90                14.0,
91                "♥♠♦♣",
92            )?;
93            Ok(())
94        })
95        .unwrap();
96    document.finish().unwrap();
97}
Source

pub fn add_outline(&mut self, title: &str)

Add an item for this page in the document outline.

An outline item associates a name (contained in an ordered tree) with a location in the document. The PDF standard supports several ways to specify an exact location on a page, but this implementation currently only supports linking to a specific page (the page that this Canvas is for).

Source

pub fn gsave(&mut self) -> Result<()>

Save the current graphics state. The caller is responsible for restoring it later.

Source

pub fn grestore(&mut self) -> Result<()>

Restor the current graphics state. The caller is responsible for having saved it earlier.

Auto Trait Implementations§

§

impl<'a> Freeze for Canvas<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for Canvas<'a>

§

impl<'a> !UnwindSafe for Canvas<'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> 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, 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.