Skip to main content

OfdReader

Struct OfdReader 

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

OFD 文档读取器。

Implementations§

Source§

impl OfdReader

Source

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

从文件路径打开并解析 OFD 文件。

§错误

文件无法读取或包含无效 OFD 数据时返回错误。

Source

pub fn open_with_options( path: impl AsRef<Path>, options: ReadOptions, ) -> OfdResult<Self>

使用指定选项打开 OFD 文件。

§错误

文件、ZIP 包或 XML 无效时返回错误。

Source

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

从内存字节数组解析 OFD 文件。

§错误

数据无效时返回错误。

Source

pub fn from_seek<R: Read + Seek>( source: R, options: ReadOptions, ) -> OfdResult<Self>

从实现 Read + Seek 的输入读取文档。

§错误

ZIP 包或 XML 无效时返回错误。

Source

pub fn visit_path( path: impl AsRef<Path>, options: ReadOptions, visitor: impl FnMut(usize, OfdPage) -> OfdResult<()>, ) -> OfdResult<usize>

逐页访问文件,不在内存中保留已经处理过的页面。

回调页码从 1 开始。回调返回错误时立即停止解析。

§错误

文件、ZIP、XML 或页面回调失败时返回错误。

Source

pub fn page_count(&self) -> usize

文档页数。

Source

pub fn pages(&self) -> &[OfdPage]

所有已解析的页面。

Source

pub fn metadata(&self) -> &OfdMetadata

文档元数据(从 OFD.xml 提取)。

Source

pub fn raw_entries(&self) -> &[(String, Vec<u8>)]

原始 ZIP 中不由写入器重新生成的条目(按名字排序),可用于无损 roundtrip:读取后把这些条目原样写回。

排除了 OFD.xmlDocument.xmlDocumentRes.xmlPublicRes.xml、 页面内容以及写入器按自身命名规则生成的图片资源。

Source

pub fn raw_ofd_xml(&self) -> Option<&str>

原始 OFD.xml 完整 XML 文本(roundtrip 保真用)。

传给 [OfdWriter::set_raw_ofd_xml] 可让 writer 原样输出 OFD.xml, 从而保证 Version、xmlns URI、DocType、DocInfo 子元素顺序等 全部与原始一致。

Source

pub fn raw_document_xml(&self) -> Option<&str>

原始 Document.xml 完整 XML 文本(roundtrip 保真用)。

传给 [OfdWriter::set_raw_document_xml] 可让 writer 原样输出 Document.xml,从而保证 CommonData 子元素顺序、Page ID、MaxUnitID、 PhysicalBox 原始文本、命名空间 URI 等全部与原始一致。

Source

pub fn extract_text(&self) -> Vec<String>

从所有页面提取文本,每页一个 String

Source

pub fn extract_all_text(&self) -> String

提取所有文本并合并为单个字符串,以页面分隔符分隔。

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 = !

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.