Skip to main content

PdfParagraph

Struct PdfParagraph 

Source
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>

Source

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.

Source

pub fn empty(maximum_width: PdfPoints, alignment: PdfParagraphAlignment) -> Self

Creates a new, empty PdfParagraph with the given maximum line width and alignment settings.

Source

pub fn is_empty(&self) -> bool

Returns true if this PdfParagraph contains no fragments.

Source

pub fn fragments(&self) -> &[PdfParagraphFragment<'a>]

Returns a reference to the fragments in this paragraph.

Source

pub fn bottom(&self) -> Option<PdfPoints>

Returns the bottom Y position of this paragraph, if known.

Source

pub fn left(&self) -> Option<PdfPoints>

Returns the left X position of this paragraph, if known.

Source

pub fn alignment(&self) -> PdfParagraphAlignment

Returns the alignment of this paragraph.

Source

pub fn push(&mut self, string: PdfStyledString<'a>)

Adds a new fragment containing the given styled string to this paragraph.

Source

pub fn maximum_width(&self) -> PdfPoints

Returns the maximum line width of this paragraph.

Source

pub fn set_maximum_width(&mut self, width: PdfPoints)

Sets the maximum line width of this paragraph to the given value.

Source

pub fn text(&self) -> String

Returns the text contained within all text fragments in this paragraph.

Source

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.

Source

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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.