Skip to content

Commit

Permalink
fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
s3bk committed Jul 28, 2023
1 parent 96c002c commit 284d81c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
19 changes: 17 additions & 2 deletions pdf/examples/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use pdf::error::PdfError;
use pdf::content::*;
use pdf::file::FileOptions;
use pdf::file::Trailer;
use pdf::font::Font;
use pdf::font::FontData;
use pdf::font::TFont;
use pdf::object::*;
use pdf::build::*;
use pdf::primitive::Dictionary;
Expand All @@ -21,8 +24,8 @@ fn main() -> Result<(), PdfError> {
let content = Content::from_ops(vec![
Op::MoveTo { p: Point { x: 100., y: 100. } },
Op::LineTo { p: Point { x: 100., y: 200. } },
Op::LineTo { p: Point { x: 200., y: 100. } },
Op::LineTo { p: Point { x: 200., y: 200. } },
Op::LineTo { p: Point { x: 200., y: 100. } },
Op::Close,
Op::Stroke,
]);
Expand All @@ -34,7 +37,19 @@ fn main() -> Result<(), PdfError> {
right: 400.0
});
let resources = Resources::default();
new_page.resources = Some(MaybeRef::Direct(Arc::new(resources)));
/*
let font = Font {
name: Some("Test".into()),
subtype: pdf::font::FontType::TrueType,
data: FontData::TrueType(TFont {
base_font: None,
})
}
resources.fonts.insert("f1", font);
*/

new_page.resources = Some(MaybeRef::Indirect(builder.storage.create(resources)?));
pages.push(new_page);

let catalog = CatalogBuilder::from_pages(pages);
Expand Down
6 changes: 1 addition & 5 deletions pdf/examples/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ fn main() -> Result<(), PdfError> {

let file = FileOptions::cached().open(&path).unwrap();
if let Some(ref info) = file.trailer.info_dict {
info.iter()
.filter(|(_, primitive)| primitive.to_string_lossy().is_ok())
.for_each(|(key, value)| {
eprintln!("{:>15}: {}", key, value.to_string_lossy().unwrap());
});
dbg!(info);
}

if let Some(ref forms) = file.get_root().forms {
Expand Down
4 changes: 2 additions & 2 deletions pdf/examples/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fn main() -> Result<(), PdfError> {

let file = FileOptions::cached().open(&path).unwrap();
if let Some(ref info) = file.trailer.info_dict {
let title = info.get("Title").and_then(|p| p.to_string_lossy().ok());
let author = info.get("Author").and_then(|p| p.to_string_lossy().ok());
let title = info.title.as_ref().map(|p| p.to_string_lossy());
let author = info.author.as_ref().map(|p| p.to_string_lossy());

let descr = match (title, author) {
(Some(title), None) => title,
Expand Down

0 comments on commit 284d81c

Please sign in to comment.