Skip to main content

CosDoc

Struct CosDoc 

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

A low-level PDF document providing access to the COS object graph.

Implementations§

Source§

impl CosDoc

Source

pub fn open(data: Vec<u8>) -> Result<Self>

Open a PDF document from raw bytes.

Source

pub fn open_file(path: &str) -> Result<Self>

Open a PDF document from a file path.

Source

pub fn new() -> Self

Create a new empty PDF document.

Source

pub fn trailer(&self) -> &IndexMap<Vec<u8>, PdfObject>

Get the trailer dictionary.

Source

pub fn trailer_mut(&mut self) -> &mut IndexMap<Vec<u8>, PdfObject>

Get a mutable reference to the trailer dictionary.

Source

pub fn get_object(&mut self, obj_num: u32) -> Result<Option<&PdfObject>>

Get an object by its object number.

Returns the object directly (resolves the xref entry to load from file).

Source

pub fn resolve(&mut self, obj: &PdfObject) -> Result<PdfObject>

Resolve a PdfObject::Reference to the referenced object. Returns the object itself if it’s not a reference.

Source

pub fn create_indirect(&mut self, obj: PdfObject) -> ObjectId

Create a new indirect object and return its ObjectId.

Source

pub fn update_object(&mut self, obj_num: u32, obj: PdfObject)

Update an existing indirect object.

Source

pub fn xref_size(&self) -> u32

Get the number of entries in the xref table.

Source

pub fn is_modified(&self) -> bool

Check if the document has been modified.

Source

pub fn save_to_bytes(&mut self) -> Result<Vec<u8>>

Save the document to bytes (full save, not incremental).

All objects are written as a flat traditional xref table, even if the original used xref streams or object streams.

Source

pub fn save_to_file(&mut self, path: &str) -> Result<()>

Save the document to a file.

Source

pub fn decode_stream(&self, stream: &PdfStream) -> Result<Vec<u8>>

Decode a stream object’s data using its filters.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.