pub struct PdfDocumentModel { /* private fields */ }Expand description
PDF 文档的引擎无关语义表示。
包含元数据与按页组织的语义内容块。
Implementations§
Source§impl PdfDocumentModel
impl PdfDocumentModel
Sourcepub const fn new(metadata: PdfMetadata, pages: Vec<PdfPageModel>) -> Self
pub const fn new(metadata: PdfMetadata, pages: Vec<PdfPageModel>) -> Self
创建文档模型。
Sourcepub const fn metadata(&self) -> &PdfMetadata
pub const fn metadata(&self) -> &PdfMetadata
返回文档元数据。
Sourcepub fn pages(&self) -> &[PdfPageModel]
pub fn pages(&self) -> &[PdfPageModel]
返回页面列表。
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
返回页面数量。
Sourcepub fn iter(&self) -> impl Iterator<Item = &PdfPageModel>
pub fn iter(&self) -> impl Iterator<Item = &PdfPageModel>
返回页面迭代器。
Sourcepub fn total_blocks(&self) -> usize
pub fn total_blocks(&self) -> usize
返回所有页面中内容块的总数。
§Examples
use easypdf_core::{PdfBlock, PdfDocumentModel, PdfPageModel, SourceLocation};
use easypdf_core::{PageIndex, PdfMetadata};
let loc = SourceLocation::new(PageIndex::new(0), 1.0);
let page = PdfPageModel::new(PageIndex::new(0))
.with_block(PdfBlock::paragraph("A", loc))
.with_block(PdfBlock::paragraph("B", loc));
let doc = PdfDocumentModel::new(PdfMetadata::default(), vec![page]);
assert_eq!(doc.total_blocks(), 2);Sourcepub fn iter_all_blocks(&self) -> impl Iterator<Item = (usize, &PdfBlock)>
pub fn iter_all_blocks(&self) -> impl Iterator<Item = (usize, &PdfBlock)>
扁平遍历所有页面的内容块,附带一基页码。
返回迭代器产出 (page_number, &PdfBlock) 元组。
§Examples
use easypdf_core::{PdfBlock, PdfDocumentModel, PdfPageModel, SourceLocation};
use easypdf_core::{PageIndex, PdfMetadata};
let loc = SourceLocation::new(PageIndex::new(0), 1.0);
let page = PdfPageModel::new(PageIndex::new(0))
.with_block(PdfBlock::paragraph("Hello", loc));
let doc = PdfDocumentModel::new(PdfMetadata::default(), vec![page]);
let blocks: Vec<_> = doc.iter_all_blocks().collect();
assert_eq!(blocks.len(), 1);
assert_eq!(blocks[0].0, 1); // 1-based page numberSourcepub fn block_count_by_type(&self) -> HashMap<PdfBlockType, usize>
pub fn block_count_by_type(&self) -> HashMap<PdfBlockType, usize>
统计每种 PdfBlockType 的出现次数。
§Examples
use easypdf_core::{PdfBlock, PdfBlockType, PdfDocumentModel, PdfPageModel, SourceLocation};
use easypdf_core::{PageIndex, PdfMetadata};
let loc = SourceLocation::new(PageIndex::new(0), 1.0);
let page = PdfPageModel::new(PageIndex::new(0))
.with_block(PdfBlock::heading(1, "Title", loc))
.with_block(PdfBlock::paragraph("Body", loc));
let doc = PdfDocumentModel::new(PdfMetadata::default(), vec![page]);
let counts = doc.block_count_by_type();
assert_eq!(counts[&PdfBlockType::Heading], 1);
assert_eq!(counts[&PdfBlockType::Paragraph], 1);Trait Implementations§
Source§impl Clone for PdfDocumentModel
impl Clone for PdfDocumentModel
Source§fn clone(&self) -> PdfDocumentModel
fn clone(&self) -> PdfDocumentModel
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PdfDocumentModel
impl Debug for PdfDocumentModel
Source§impl Default for PdfDocumentModel
impl Default for PdfDocumentModel
Source§fn default() -> PdfDocumentModel
fn default() -> PdfDocumentModel
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PdfDocumentModel
impl RefUnwindSafe for PdfDocumentModel
impl Send for PdfDocumentModel
impl Sync for PdfDocumentModel
impl Unpin for PdfDocumentModel
impl UnsafeUnpin for PdfDocumentModel
impl UnwindSafe for PdfDocumentModel
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more