pub struct PdfParagraph<'a> { /* private fields */ }Expand description
A group of PdfPageTextObject objects contained in the same PdfPageObjects collection
that should be laid out together as a single paragraph.
Text layout in PDF files is handled entirely by text objects. Each text object contains a single span of text that is styled consistently and can be at most a single line long. Multiple text objects stitched together visually at the time the page is generated are interpreted by the reader as paragraphs, but there is no concept in the PDF file format of a multi-line text block, and there is no native functionality for retrieving a single paragraph from its constituent text objects. This makes it difficult to work with long spans of text.
The PdfParagraph is an attempt to improve multi-line text handling. Paragraphs can be created from existing groups of page objects, or created by scratch; once created, text in a paragraph can be edited and re-formatted, and then used to generate a group of text objects that can be placed on a page.
Implementations§
Source§impl<'a> PdfParagraph<'a>
impl<'a> PdfParagraph<'a>
Sourcepub fn from_objects(objects: &'a [PdfPageObject<'a>]) -> Vec<PdfParagraph<'a>>
pub fn from_objects(objects: &'a [PdfPageObject<'a>]) -> Vec<PdfParagraph<'a>>
Creates a set of one or more PdfParagraph objects from the given slice of page objects.
Sourcepub fn empty(maximum_width: PdfPoints, alignment: PdfParagraphAlignment) -> Self
pub fn empty(maximum_width: PdfPoints, alignment: PdfParagraphAlignment) -> Self
Creates a new, empty PdfParagraph with the given maximum line width and alignment settings.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this PdfParagraph contains no fragments.
Sourcepub fn fragments(&self) -> &[PdfParagraphFragment<'a>]
pub fn fragments(&self) -> &[PdfParagraphFragment<'a>]
Returns a reference to the fragments in this paragraph.
Sourcepub fn bottom(&self) -> Option<PdfPoints>
pub fn bottom(&self) -> Option<PdfPoints>
Returns the bottom Y position of this paragraph, if known.
Sourcepub fn left(&self) -> Option<PdfPoints>
pub fn left(&self) -> Option<PdfPoints>
Returns the left X position of this paragraph, if known.
Sourcepub fn alignment(&self) -> PdfParagraphAlignment
pub fn alignment(&self) -> PdfParagraphAlignment
Returns the alignment of this paragraph.
Sourcepub fn push(&mut self, string: PdfStyledString<'a>)
pub fn push(&mut self, string: PdfStyledString<'a>)
Adds a new fragment containing the given styled string to this paragraph.
Sourcepub fn maximum_width(&self) -> PdfPoints
pub fn maximum_width(&self) -> PdfPoints
Returns the maximum line width of this paragraph.
Sourcepub fn set_maximum_width(&mut self, width: PdfPoints)
pub fn set_maximum_width(&mut self, width: PdfPoints)
Sets the maximum line width of this paragraph to the given value.
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Returns the text contained within all text fragments in this paragraph.
Sourcepub fn text_separated(&self, separator: &str) -> String
pub fn text_separated(&self, separator: &str) -> String
Returns the text contained within all text fragments in this paragraph, separating each text fragment with the given separator.
Sourcepub fn into_lines(self) -> Vec<PdfLine<'a>>
pub fn into_lines(self) -> Vec<PdfLine<'a>>
Assembles the fragments in this paragraph into lines, taking into account the paragraph’s current sizing, overflow, indent, and alignment settings. Consumes the paragraph and returns the assembled lines.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for PdfParagraph<'a>
impl<'a> !Send for PdfParagraph<'a>
impl<'a> !Sync for PdfParagraph<'a>
impl<'a> !UnwindSafe for PdfParagraph<'a>
impl<'a> Freeze for PdfParagraph<'a>
impl<'a> Unpin for PdfParagraph<'a>
impl<'a> UnsafeUnpin for PdfParagraph<'a>
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> 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