example_svg_basic_write/
example_svg_basic_write.rs1use fpdf::{Fpdf, Pdf, RGB, Unit};
2
3const HTML: &'static str = r#"This example renders a simple
6<a href="https://www.w3.org/TR/SVG/">SVG</a> (scalable vector graphics)
7image that contains only basic path commands without any styling,
8color fill, reflection or endpoint closures. In particular, the
9type of vector graphic returned from a
10<a href="https://willowsystems.github.io/jSignature/#/demo/">jSignature</a>
11web control is supported and is used in this example."#;
12
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}