forked from mikeparisstuff/printpdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
michael.paris
committed
Oct 26, 2023
1 parent
cec012a
commit 7dc8c69
Showing
5 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
extern crate printpdf; | ||
|
||
use image_crate::codecs::png::PngDecoder; | ||
use printpdf::*; | ||
use std::fs::File; | ||
use std::io::BufWriter; | ||
use std::io::Cursor; | ||
|
||
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); | ||
|
||
// currently, the only reliable file formats are bmp/jpeg/png | ||
// this is an issue of the image library, not a fault of printpdf | ||
|
||
let image_bytes = include_bytes!("../assets/img/dog_alpha.png"); | ||
let mut reader = Cursor::new(image_bytes.as_ref()); | ||
|
||
let decoder = PngDecoder::new(&mut reader).unwrap(); | ||
let image = Image::try_from(decoder).unwrap(); | ||
|
||
let rotation_center_x = Px((image.image.width.0 as f32 / 2.0) as usize); | ||
let rotation_center_y = Px((image.image.height.0 as f32 / 2.0) as usize); | ||
|
||
// layer, | ||
image.add_to_layer( | ||
current_layer.clone(), | ||
ImageTransform { | ||
rotate: Some(ImageRotation { | ||
angle_ccw_degrees: 0.0, | ||
rotation_center_x, | ||
rotation_center_y, | ||
}), | ||
translate_x: Some(Mm(50.0)), | ||
translate_y: Some(Mm(50.0)), | ||
..Default::default() | ||
}, | ||
); | ||
|
||
doc.save(&mut BufWriter::new(File::create("test_image.pdf").unwrap())) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters