Skip to main content

ExtractionQuery

Struct ExtractionQuery 

Source
pub struct ExtractionQuery { /* private fields */ }
Expand description

An extraction query.

Implementations§

Source§

impl ExtractionQuery

Source

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}
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ExtractionQuery

Source§

impl Debug for ExtractionQuery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.