pub struct ExtractionQuery { /* private fields */ }Expand description
An extraction query.
Implementations§
Source§impl ExtractionQuery
impl ExtractionQuery
Sourcepub fn new_page(page_index: usize) -> Self
pub fn new_page(page_index: usize) -> Self
Create a new page extraction query with the given page index.
Examples found in repository?
examples/extract_one_page.rs (line 21)
10fn main() {
11 // First load the data that constitutes the PDF file.
12 let data = std::fs::read(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../in.pdf")).unwrap();
13 let page_index = 0;
14
15 // Then create a new PDF file from it.
16 //
17 // Here we are just unwrapping in case reading the file failed, but you
18 // might instead want to apply proper error handling.
19 let pdf = Pdf::new(data).unwrap();
20
21 let query = ExtractionQuery::new_page(page_index);
22
23 let mut counter = 0;
24 let mut new_ref = || {
25 counter += 1;
26 Ref::new(counter)
27 };
28 let extraction_result = extract(
29 &pdf,
30 Box::new(&mut new_ref),
31 ChunkSettings { pretty: false },
32 &[query],
33 )
34 .unwrap();
35
36 let chunk = extraction_result.chunk;
37 let page_ref = extraction_result.root_refs[0].unwrap();
38 let parent = extraction_result.page_tree_parent_ref;
39
40 let catalog_id = new_ref();
41 let mut out_pdf = pdf_writer::Pdf::with_settings(ChunkSettings { pretty: false });
42 out_pdf.extend(&chunk);
43 out_pdf.catalog(catalog_id).pages(parent);
44 out_pdf.pages(parent).kids([page_ref]).count(1);
45
46 std::fs::write(
47 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../out.pdf"),
48 out_pdf.finish(),
49 )
50 .unwrap();
51}Sourcepub fn new_xobject(page_index: usize) -> Self
pub fn new_xobject(page_index: usize) -> Self
Create a new XObject extraction query with the given page index.
Trait Implementations§
Source§impl Clone for ExtractionQuery
impl Clone for ExtractionQuery
impl Copy for ExtractionQuery
Auto Trait Implementations§
impl Freeze for ExtractionQuery
impl RefUnwindSafe for ExtractionQuery
impl Send for ExtractionQuery
impl Sync for ExtractionQuery
impl Unpin for ExtractionQuery
impl UnsafeUnpin for ExtractionQuery
impl UnwindSafe for ExtractionQuery
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