pub struct PdfDocument {
pub metadata: PdfMetadata,
pub resources: PdfResources,
pub bookmarks: PageAnnotMap,
pub pages: Vec<PdfPage>,
}
Expand description
Parsed PDF document
Fields§
§metadata: PdfMetadata
Metadata about the document (author, info, XMP metadata, etc.)
resources: PdfResources
Resources shared between pages, such as fonts, XObjects, images, forms, ICC profiles, etc.
bookmarks: PageAnnotMap
Document-level bookmarks (used for the outline)
pages: Vec<PdfPage>
Page contents
Implementations§
Source§impl PdfDocument
impl PdfDocument
Sourcepub fn shape_text(
&self,
text: &str,
font_id: &FontId,
options: &TextShapingOptions,
) -> Option<ShapedText>
pub fn shape_text( &self, text: &str, font_id: &FontId, options: &TextShapingOptions, ) -> Option<ShapedText>
Looks up a text and shapes it without coordinate transformation.
Only returns None
on an invalid FontId
.
pub fn new(name: &str) -> Self
Sourcepub fn parse(
bytes: &[u8],
opts: &PdfParseOptions,
warnings: &mut Vec<PdfWarnMsg>,
) -> Result<Self, String>
pub fn parse( bytes: &[u8], opts: &PdfParseOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Result<Self, String>
Parses a PDF
pub async fn parse_async( bytes: &[u8], opts: &PdfParseOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Result<Self, String>
pub fn add_graphics_state( &mut self, gs: ExtendedGraphicsState, ) -> ExtendedGraphicsStateId
pub fn add_layer(&mut self, layer: &Layer) -> LayerInternalId
pub fn add_font(&mut self, font: &ParsedFont) -> FontId
Sourcepub fn add_image(&mut self, image: &RawImage) -> XObjectId
pub fn add_image(&mut self, image: &RawImage) -> XObjectId
Adds an image to the internal resources
Sourcepub fn add_xobject(&mut self, parsed_svg: &ExternalXObject) -> XObjectId
pub fn add_xobject(&mut self, parsed_svg: &ExternalXObject) -> XObjectId
Adds an external XObject stream (usually SVG or other stream) to the PDF resources
so that it can be later be invoked with UseXobject { id }
Sourcepub fn add_bookmark(&mut self, name: &str, page: usize) -> PageAnnotId
pub fn add_bookmark(&mut self, name: &str, page: usize) -> PageAnnotId
Adds a new page-level bookmark on page $page
, returning the bookmarks internal ID
Sourcepub fn from_html(
html: &str,
images: &BTreeMap<String, Base64OrRaw>,
fonts: &BTreeMap<String, Base64OrRaw>,
options: &GeneratePdfOptions,
warnings: &mut Vec<PdfWarnMsg>,
) -> Result<Self, String>
pub fn from_html( html: &str, images: &BTreeMap<String, Base64OrRaw>, fonts: &BTreeMap<String, Base64OrRaw>, options: &GeneratePdfOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Result<Self, String>
Renders HTML to pages
pub async fn from_html_async( html: &str, images: &BTreeMap<String, Base64OrRaw>, fonts: &BTreeMap<String, Base64OrRaw>, options: &GeneratePdfOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Result<Self, String>
Sourcepub fn page_to_svg(
&self,
page: usize,
opts: &PdfToSvgOptions,
warnings: &mut Vec<PdfWarnMsg>,
) -> Option<String>
pub fn page_to_svg( &self, page: usize, opts: &PdfToSvgOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Option<String>
Renders a PDF Page into an SVG String. Returns None
on an invalid page number
(note: 1-indexed, so the first PDF page is “page 1”, not “page 0”).
pub async fn page_to_svg_async( &self, page: usize, opts: &PdfToSvgOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Option<String>
Sourcepub fn with_pages(&mut self, pages: Vec<PdfPage>) -> &mut Self
pub fn with_pages(&mut self, pages: Vec<PdfPage>) -> &mut Self
Replaces document.pages
with the new pages
Sourcepub fn save_writer<W: Write>(
&self,
w: &mut W,
opts: &PdfSaveOptions,
warnings: &mut Vec<PdfWarnMsg>,
)
pub fn save_writer<W: Write>( &self, w: &mut W, opts: &PdfSaveOptions, warnings: &mut Vec<PdfWarnMsg>, )
Serializes the PDF document and writes it to a writer
Sourcepub fn save(
&self,
opts: &PdfSaveOptions,
warnings: &mut Vec<PdfWarnMsg>,
) -> Vec<u8> ⓘ
pub fn save( &self, opts: &PdfSaveOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Vec<u8> ⓘ
Serializes the PDF document to bytes
pub async fn save_async( &self, opts: &PdfSaveOptions, warnings: &mut Vec<PdfWarnMsg>, ) -> Vec<u8> ⓘ
Trait Implementations§
Source§impl Clone for PdfDocument
impl Clone for PdfDocument
Source§fn clone(&self) -> PdfDocument
fn clone(&self) -> PdfDocument
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PdfDocument
impl Debug for PdfDocument
Source§impl Default for PdfDocument
impl Default for PdfDocument
Source§fn default() -> PdfDocument
fn default() -> PdfDocument
Source§impl<'de> Deserialize<'de> for PdfDocument
impl<'de> Deserialize<'de> for PdfDocument
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for PdfDocument
impl PartialEq for PdfDocument
Source§impl Serialize for PdfDocument
impl Serialize for PdfDocument
impl StructuralPartialEq for PdfDocument
Auto Trait Implementations§
impl Freeze for PdfDocument
impl !RefUnwindSafe for PdfDocument
impl !Send for PdfDocument
impl !Sync for PdfDocument
impl Unpin for PdfDocument
impl !UnwindSafe for PdfDocument
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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