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
impl OpcPackage
Sourcepub fn or_add_image_part(
&mut self,
image: &Image,
) -> PptxResult<(PackURI, String)>
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.
Sourcepub fn or_add_media_part(
&mut self,
video: &Video,
) -> PptxResult<(PackURI, String)>
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
impl OpcPackage
Sourcepub fn open(path: impl AsRef<Path>) -> PptxResult<Self>
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.
Sourcepub fn from_bytes(data: &[u8]) -> PptxResult<Self>
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.
Sourcepub fn new() -> PptxResult<Self>
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.
Sourcepub fn to_bytes(&self) -> PptxResult<Vec<u8>>
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.
Sourcepub fn part_mut(&mut self, partname: &PackURI) -> Option<&mut Part>
pub fn part_mut(&mut self, partname: &PackURI) -> Option<&mut Part>
Get a mutable reference to a part by its partname.
Sourcepub fn remove_part(&mut self, partname: &PackURI) -> Option<Part>
pub fn remove_part(&mut self, partname: &PackURI) -> Option<Part>
Remove a part by its partname.
Sourcepub fn part_by_reltype(&self, reltype: &str) -> PptxResult<&Part>
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.
Sourcepub fn part_by_reltype_mut(&mut self, reltype: &str) -> PptxResult<&mut Part>
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.
Sourcepub fn next_partname(&self, template: &str) -> PptxResult<PackURI>
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.
Sourcepub fn next_image_partname(&self, ext: &str) -> PptxResult<PackURI>
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.
Sourcepub fn next_media_partname(&self, ext: &str) -> PptxResult<PackURI>
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
impl Clone for OpcPackage
Source§fn clone(&self) -> OpcPackage
fn clone(&self) -> OpcPackage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more