pub struct Document { /* private fields */ }Expand description
A DOCX file opened and laid out once for a target: its display list, which an output draws or
writes, the places of its lines, and the text blocks of its body. It holds no state of the
parse or the layout: what the layout left out or drew in another way comes out of
Document::open beside it.
Implementations§
Source§impl Document
impl Document
Sourcepub fn open(
docx: &[u8],
fonts: &FontDb,
options: &Options,
) -> Result<Warned<Self>, Error>
pub fn open( docx: &[u8], fonts: &FontDb, options: &Options, ) -> Result<Warned<Self>, Error>
Opens a DOCX file and lays it out into pages for the target of options, with the
warnings of what it left out or drew in another way. The layout runs once, here.
§Errors
Returns an error when the file is not a readable DOCX package or its content cannot be laid out, or when the configuration or the target’s profile does not read.
Sourcepub fn open_with_art(
docx: &[u8],
fonts: &FontDb,
art: &ArtPictures,
options: &Options,
) -> Result<Warned<Self>, Error>
pub fn open_with_art( docx: &[u8], fonts: &FontDb, art: &ArtPictures, options: &Options, ) -> Result<Warned<Self>, Error>
Opens a DOCX file as Document::open does, with the pictures of the art page borders
art, which the caller adds beside the fonts (ArtPictures::add). A page border’s side
of an art style whose picture art lacks is not drawn, with a warning.
§Errors
As Document::open.
Sourcepub fn open_file(
path: &Path,
fonts: &FontDb,
options: &Options,
) -> Result<Warned<Self>, Error>
pub fn open_file( path: &Path, fonts: &FontDb, options: &Options, ) -> Result<Warned<Self>, Error>
Opens a DOCX file from disk and lays it out into pages for the target of options,
reading only the ZIP central directory and the parts needed for layout without loading
the entire file into memory.
§Errors
Returns an error when the file cannot be opened as a DOCX package, its content cannot be laid out, or the configuration or target profile does not read.
Sourcepub fn open_file_with_art(
path: &Path,
fonts: &FontDb,
art: &ArtPictures,
options: &Options,
) -> Result<Warned<Self>, Error>
pub fn open_file_with_art( path: &Path, fonts: &FontDb, art: &ArtPictures, options: &Options, ) -> Result<Warned<Self>, Error>
Opens a DOCX file from disk as Document::open_file does, with art page-border
pictures art.
§Errors
Sourcepub fn open_source(
source: Arc<dyn RandomAccessRead>,
fonts: &FontDb,
options: &Options,
) -> Result<Warned<Self>, Error>
pub fn open_source( source: Arc<dyn RandomAccessRead>, fonts: &FontDb, options: &Options, ) -> Result<Warned<Self>, Error>
Opens a DOCX package from a caller-provided random-access byte source (such as a browser
File.slice() or OPFS sync handle) without copying the whole archive into memory.
§Errors
As Document::open.
Sourcepub fn open_source_with_art(
source: Arc<dyn RandomAccessRead>,
fonts: &FontDb,
art: &ArtPictures,
options: &Options,
) -> Result<Warned<Self>, Error>
pub fn open_source_with_art( source: Arc<dyn RandomAccessRead>, fonts: &FontDb, art: &ArtPictures, options: &Options, ) -> Result<Warned<Self>, Error>
Opens a DOCX package from a random-access byte source as Document::open_source does,
with art page-border pictures art.
§Errors
As Document::open.
Sourcepub fn display_list(&self) -> &DisplayList
pub fn display_list(&self) -> &DisplayList
The display list of the pages, the only border between the layout and an output.
Sourcepub fn pages(&self) -> &[Page]
pub fn pages(&self) -> &[Page]
The pages in order: the pages of the display list (Document::display_list).
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
The number of pages.
Sourcepub fn page(&self, index: usize) -> Option<&Page>
pub fn page(&self, index: usize) -> Option<&Page>
The page at index, counted from 0, or none past the last page.
Sourcepub fn page_size(&self, index: usize) -> Option<(Length, Length)>
pub fn page_size(&self, index: usize) -> Option<(Length, Length)>
The width and the height of the page at index, counted from 0, without drawing it, or
none past the last page.
Sourcepub fn text_blocks(&self) -> &[TextBlock]
pub fn text_blocks(&self) -> &[TextBlock]
The paragraphs and tables of the body in the order of the document, each with its
address, which counts from 1, its kind with its style and text, and the indices of the
pages that its lines lie on, which count from 0 as Document::page does. The pages are
those of this document’s layout, so of the configuration that it was opened with
(Options::configuration): the same file can give other pages for another target.
The paragraphs of a table’s cells follow the table. Headers, footers, notes and text
boxes are not text blocks.
Sourcepub fn text_map(&self, index: usize) -> Vec<TextLine>
pub fn text_map(&self, index: usize) -> Vec<TextLine>
The text map of the page at index, counted from 0 (Text map): its lines in reading
order, the header first, then the body, the endnotes, the frames, the text boxes, the
footnotes and the footer.
Each line names its story and its paragraph in Document::story_text, with its range
of the paragraph’s text, its line box and its clusters in visual order with their edges
on the page. It is empty past the last page.
Sourcepub fn text_maps(&self, indices: &[usize]) -> Vec<Vec<TextLine>>
pub fn text_maps(&self, indices: &[usize]) -> Vec<Vec<TextLine>>
The text maps of the pages at indices, each as Document::text_map gives it, from
one read of each story on them: a viewer that needs many pages, such as for a search,
reads the body once and not once for each page.
Sourcepub fn story_text(&self, story: TextStory) -> Vec<StoryParagraph>
pub fn story_text(&self, story: TextStory) -> Vec<StoryParagraph>
The text of story by paragraph (Story text): the texts of the paragraph’s laid out
lines joined, so that a field gives its shown result, a list label is given as drawn,
hidden text is left out, and an automatic hyphen at a wrap is not in it.
Sourcepub fn write_pdf(&self, fonts: &FontDb) -> Result<Warned<Vec<u8>>, Error>
pub fn write_pdf(&self, fonts: &FontDb) -> Result<Warned<Vec<u8>>, Error>
Writes the pages as a PDF file, with the fonts subset and embedded, and with the warnings of the PDF writer.
Each page becomes one PDF page of the same size, with every glyph at its laid out position and with its text, so that a viewer can search and copy it. The same document and fonts always give the same bytes.
§Errors
Returns an error when the pages cannot be written as PDF.
Sourcepub fn write_pdf_to<W: Write>(
&self,
fonts: &FontDb,
writer: &mut W,
) -> Result<Warned<()>, Error>
pub fn write_pdf_to<W: Write>( &self, fonts: &FontDb, writer: &mut W, ) -> Result<Warned<()>, Error>
Streams the pages directly as a PDF 1.7 document into writer without buffering the
complete PDF bytes in memory.
§Errors
Returns an error when the pages cannot be written as PDF or when writing to writer fails.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Document
impl !UnwindSafe for Document
impl Forget for Document
impl Freeze for Documentwhere
*const u8 is !null: Freeze,
PhantomData<Page>: Freeze,
PhantomData<TextBlock>: Freeze,
PhantomData<(ParagraphId, Address)>: Freeze,
PhantomData<(ParagraphId, RunMarks)>: Freeze,
PhantomData<CompactLine>: Freeze,
impl Move for Document
impl Send for Documentwhere
RawVecInner: Send,
Arc<[u8]>: Send,
Arc<dyn ImageLoader>: Send,
Arc<[ColorEffect]>: Send,
NonZero<usize>: Send,
RawTable<(ParagraphId, Address)>: Send,
RawTable<(ParagraphId, RunMarks)>: Send,
impl Sync for Documentwhere
RawVecInner: Sync,
Arc<[u8]>: Sync,
Arc<dyn ImageLoader>: Sync,
Arc<[ColorEffect]>: Sync,
NonZero<usize>: Sync,
RawTable<(ParagraphId, Address)>: Sync,
RawTable<(ParagraphId, RunMarks)>: Sync,
impl Unpin for Document
impl UnsafeUnpin for Documentwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<Page>: UnsafeUnpin,
PhantomData<TextBlock>: UnsafeUnpin,
PhantomData<(ParagraphId, Address)>: UnsafeUnpin,
PhantomData<(ParagraphId, RunMarks)>: UnsafeUnpin,
PhantomData<CompactLine>: UnsafeUnpin,
Blanket Implementations§
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
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,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.