Struct printpdf::SvgXObjectRef
source · pub struct SvgXObjectRef {
pub width: Px,
pub height: Px,
/* private fields */
}
Fields§
§width: Px
Width of the rendered SVG content
height: Px
Height of the rendered SVG content
Implementations§
source§impl SvgXObjectRef
impl SvgXObjectRef
sourcepub fn add_to_layer(self, layer: &PdfLayerReference, transform: SvgTransform)
pub fn add_to_layer(self, layer: &PdfLayerReference, transform: SvgTransform)
Examples found in repository?
examples/svg.rs (lines 20-32)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
let (doc, page1, layer1) =
PdfDocument::new("printpdf graphics test", Mm(210.0), Mm(297.0), "Layer 1");
let current_layer = doc.get_page(page1).get_layer(layer1);
let svg = Svg::parse(SVG).unwrap();
let rotation_center_x = Px((svg.width.0 as f32 / 2.0) as usize);
let rotation_center_y = Px((svg.height.0 as f32 / 2.0) as usize);
let reference = svg.into_xobject(¤t_layer);
for i in 0..10 {
reference.clone().add_to_layer(
¤t_layer,
SvgTransform {
rotate: Some(SvgRotation {
angle_ccw_degrees: i as f32 * 36.0,
rotation_center_x: rotation_center_x.into_pt(300.0),
rotation_center_y: rotation_center_y.into_pt(300.0),
}),
translate_x: Some(Mm(i as f32 * 20.0 % 50.0).into()),
translate_y: Some(Mm(i as f32 * 30.0).into()),
..Default::default()
},
);
}
let pdf_bytes = doc.save_to_bytes().unwrap();
std::fs::write("test_svg.pdf", &pdf_bytes).unwrap();
}
Trait Implementations§
source§impl Clone for SvgXObjectRef
impl Clone for SvgXObjectRef
source§fn clone(&self) -> SvgXObjectRef
fn clone(&self) -> SvgXObjectRef
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SvgXObjectRef
impl Debug for SvgXObjectRef
source§impl PartialEq for SvgXObjectRef
impl PartialEq for SvgXObjectRef
source§fn eq(&self, other: &SvgXObjectRef) -> bool
fn eq(&self, other: &SvgXObjectRef) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for SvgXObjectRef
impl PartialOrd for SvgXObjectRef
source§fn partial_cmp(&self, other: &SvgXObjectRef) -> Option<Ordering>
fn partial_cmp(&self, other: &SvgXObjectRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl StructuralPartialEq for SvgXObjectRef
Auto Trait Implementations§
impl RefUnwindSafe for SvgXObjectRef
impl Send for SvgXObjectRef
impl Sync for SvgXObjectRef
impl Unpin for SvgXObjectRef
impl UnwindSafe for SvgXObjectRef
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more