Skip to main content

OpcPackage

Struct OpcPackage 

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

An OPC (Open Packaging Convention) package.

This is the primary struct for reading and writing .pptx files. An OPC package is a ZIP archive containing XML and binary parts linked by relationships.

The package contains:

  • A collection of parts indexed by their PackURI
  • Package-level relationships (from _rels/.rels)
  • A content type map (from [Content_Types].xml)

Implementations§

Source§

impl OpcPackage

Source

pub fn or_add_image_part( &mut self, image: &Image, ) -> PptxResult<(PackURI, String)>

Add an image part to the package, deduplicating by SHA1 hash.

If an image with the same SHA1 already exists in /ppt/media/, it is reused. Otherwise a new image part is created.

Returns (partname, content_type) of the image part (new or existing).

§Errors

Returns an error if the part cannot be created.

Source

pub fn or_add_media_part( &mut self, video: &Video, ) -> PptxResult<(PackURI, String)>

Add a media (video) part to the package, deduplicating by SHA1 hash.

Returns (partname, content_type) of the media part (new or existing).

§Errors

Returns an error if the part cannot be created.

Source§

impl OpcPackage

Source

pub fn open(path: impl AsRef<Path>) -> PptxResult<Self>

Open an existing .pptx file from a filesystem path.

§Errors

Returns an error if the file cannot be read or is not a valid package.

Source

pub fn from_bytes(data: &[u8]) -> PptxResult<Self>

Open a package from in-memory bytes (a .pptx file loaded into memory).

§Errors

Returns an error if the bytes are not a valid OPC package.

Source

pub fn new() -> PptxResult<Self>

Create a new package from the embedded default template.

§Errors

Returns an error if the default template cannot be parsed.

Source

pub fn save(&self, path: impl AsRef<Path>) -> PptxResult<()>

Save the package to a filesystem path.

§Errors

Returns an error if serialization or file I/O fails.

Source

pub fn to_bytes(&self) -> PptxResult<Vec<u8>>

Serialize the package to in-memory bytes (a valid .pptx file).

§Errors

Returns an error if XML serialization or ZIP writing fails.

Source

pub fn part(&self, partname: &PackURI) -> Option<&Part>

Get a part by its partname.

Source

pub fn part_mut(&mut self, partname: &PackURI) -> Option<&mut Part>

Get a mutable reference to a part by its partname.

Source

pub fn put_part(&mut self, part: Part)

Add or replace a part in the package.

Source

pub fn remove_part(&mut self, partname: &PackURI) -> Option<Part>

Remove a part by its partname.

Source

pub fn parts(&self) -> impl Iterator<Item = &Part>

Iterate over all parts in the package.

Source

pub fn parts_mut(&mut self) -> impl Iterator<Item = &mut Part>

Iterate over all parts mutably.

Source

pub fn part_by_reltype(&self, reltype: &str) -> PptxResult<&Part>

Find the part related to the package by relationship type.

§Errors

Returns an error if the relationship or part is not found.

Source

pub fn part_by_reltype_mut(&mut self, reltype: &str) -> PptxResult<&mut Part>

Get a mutable reference to the part related to the package by relationship type.

§Errors

Returns an error if the relationship or part is not found.

Source

pub fn next_partname(&self, template: &str) -> PptxResult<PackURI>

Get the next available partname matching a pattern template.

The template should contain {} where the number goes. For example, “/ppt/slides/slide{}.xml” might return “/ppt/slides/slide1.xml”.

§Errors

Returns an error if no available partname can be found.

Source

pub fn next_image_partname(&self, ext: &str) -> PptxResult<PackURI>

Get the next available image partname with the given extension.

Returns a partname like “/ppt/media/image1.png”, “/ppt/media/image2.jpg”, etc.

§Errors

Returns an error if no available partname can be found.

Source

pub fn next_media_partname(&self, ext: &str) -> PptxResult<PackURI>

Get the next available media partname with the given extension.

Returns a partname like “/ppt/media/media1.mp4”, etc.

§Errors

Returns an error if no available partname can be found.

Trait Implementations§

Source§

impl Clone for OpcPackage

Source§

fn clone(&self) -> OpcPackage

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OpcPackage

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> 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> Same for T

Source§

type Output = T

Should always be Self
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 = 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.