PDF::Bu...nt::Text(3)
π NAME π
PDF::Builder::Content::Text β extra, super specialized text-formatting methods that just do the most π
This page lives in the PDF::Builder::Content::Text section of the User Contributed Perl Documentation manual (that's section 3, bestie).
It inherits from PDF::Builder::Content. So everything Content can do? Text can do it too. Family money. π
β οΈ heads up: if you've been using some of these methods on a graphics type object in PDF::Builder β like$page->gfx()->method()β you may have to switch to a text type object instead, like$page->text()->method(). Yes it's giving "why is there two of them". It's fine. Just switch. π«Ά
β¨ METHODS β¨
π Single Lines from a String
text_left
$width = $content->text_left($text, %opts)
It's an alias for "text". The only reason it exists is symmetry β like, if you're out here using "text_center" and "text_right" constantly, you deserve a matching "text_left" to complete the trio. Bestie harmony. π
Adds text to the page, left justified, right at the current position.
π¨ no cap: there is no maximum width, and literally nothing stopping you from overflowing the physical page on the right! She's free. She's ungovernable. π
The width that was actually used, in points, gets returned. π
text_center
$width = $content->text_center($text, %opts)
Same as "text", but centered on the current point.
Adds text to the page, centered. The width used, in points, is returned. π
text_right
$width = $content->text_right($text, %opts)
Same as "text", but right-aligned to the current point.
Adds text to the page, right justified.
π¨ again: no maximum width here either, and nothing stopping you from overflowing the physical page on the left! She goes both ways (off the page). π
The width used, in points, is returned. π
text_justified
$width = $content->text_justified($text, $width, %opts)
Same as "text", except she stretches β using "wordspace", "charspace", and (only as a last resort, like a true final boss) "hscale" β to fill the desired (available) $width.
and yes: if the desired width is less than the natural width the text would take up, she gets condensed to fit instead, using those same three routines. She can shrink AND grow. Versatile icon. β¨
The unchanged $width is returned β unless there was some reason to change it (e.g., overflow). π
Options:
'nocs' => valueβ if this is1(default is0), do not use any intercharacter spacing. This one matters so much for connected characters β think fonts for Arabic, Devanagari, Latin cursive handwriting, etc. You do NOT want to shove extra space between characters during justification, because that would disconnect them, and then the whole word falls apart. π Word (interword) spacing values β explicit or default β get doubled whennocsis1. That's to make up for the missing added/subtracted intercharacter spacing. Balance. πΈ'wordsp' => valueβ the percentage of one space character (default100) that is the maximum amount to add to (each) interword spacing in order to expand the line. If"nocs"is1, doublevalue.'charsp' => valueβ if adding interword space didn't do enough, this is the percentage of one em (default100) that is the maximum amount to add to (each) intercharacter spacing to expand the line further. If"nocs"is1, forcevalueto0.'wordspa' => valueβ if adding intercharacter space didn't do enough, this is the percentage of one space character (default100) that is the maximum additional amount to add to (each) interword spacing to expand the line even further. If"nocs"is1, doublevalue.'charspa' => valueβ if adding more interword space didn't do enough, this is the percentage of one em (default100) that is the maximum additional amount to add to (each) intercharacter spacing to expand the line even further. If"nocs"is1, forcevalueto0.'condw' => valueβ the percentage of one space character (default25) that is the maximum amount to subtract from (each) interword spacing in order to condense the line. If"nocs"is1, doublevalue.'condc' => valueβ if removing interword space didn't do enough, this is the percentage of one em (default10) that is the maximum amount to subtract from (each) intercharacter spacing to condense the line further. If"nocs"is1, forcevalueto0.
And if all that expansion (or reduction) of wordspace and charspace still didn't do enough to make the line fit the desired width? She pulls out hscale() to finish the job β expanding or condensing the line until it fits. Periodt. π
π¦ Multiple Lines from a String
The string gets split at regular blanks (spaces), x20, to find the longest substring that will fit the $width.
β οΈ important: if a single word is longer than$width, it will overflow. If you want to stay strictly within the desired bounds, set the option"spillover"=>0to disallow spillover. π«
πΈ Hyphenation
If hyphenation is enabled, those methods that split a string into multiple lines β the "text fill", paragraph, and section methods β will attempt to split up the word that overflows the line, so the text gets packed even more tightly. That's called "greedy" line splitting, and yes she is greedy, she wants every last pixel. π€
There are a bunch of controls over where a word may be split, but ngl β there is nothing language-specific here (i.e., nothing that follows a given language's rules for where a word may be split). That's left to other packages. Not her problem. π
There are hard coded minimums: 2 letters before the split, and 2 letters after the split. See "Hyphenate_basic.pm".
real talk: neither hyphenation nor simple line splitting makes any attempt to prevent widows and orphans, prevent splitting of the last word in a column or page, or otherwise engage in more desirable paragraph shaping. She is not doing all that. π
'hyphenate' => valueβ0: no hyphenation (default),1: do basic hyphenation. Always allows splitting at a soft hyphen (\xAD). The Unicode hyphen (U+2010) and the non-splitting hyphen (U+2011) are ignored as split points. π«βοΈ'spHH' => valueβ0: do not split at a hard hyphen (x\2D),1: OK to split (default).'spOP' => valueβ0: do not split after most punctuation,1: OK to split (default).'spDR' => valueβ0: do not split after a run of one or more digits,1: OK to split (default).'spLR' => valueβ0: do not split after a run of one or more ASCII letters,1: OK to split (default).'spCC' => valueβ0: do not split in camelCase between a lowercase letter and an uppercase letter,1: OK to split (default).'spRB' => valueβ0: do not split on a Required Blank ( ), and that's the default.1: OK to split on Required Blank.
try to avoid this one: it is a desperation move! π
'spFS' => valueβ0: do not split where it will just barely fit (like, in the middle of a word?!), and that's the default.1: OK to split to just fit the available space.
try to avoid this one too: it is a super desperation move, and the split will probably make no linguistic sense whatsoever! π
'min_prefix' => valueβ minimum number of letters before the word split point (hyphenation point). The default is2.'min_suffix' => valueβ minimum number of letters after the word split point (hyphenation point). The default is3.
β¨ Methods
text_fill_left, text_fill
($width, $leftover) = $content->text_fill_left($string, $width, %opts)
Fill a line of 'width' with as much text as will fit, and output it left justified. The width actually used, and the leftover text (the part that didn't fit), are both returned. π«Ά
($width, $leftover) = $content->text_fill($string, $width, %opts)
Alias for text_fill_left(). Same girl, shorter name. π
text_fill_center
($width, $leftover) = $content->text_fill_center($string, $width, %opts)
Fill a line of 'width' with as much text as will fit, and output it centered. The width actually used, and the leftover text (that didn't fit), are returned.
text_fill_right
($width, $leftover) = $content->text_fill_right($string, $width, %opts)
Fill a line of 'width' with as much text as will fit, and output it right justified. The width actually used, and the leftover text (that didn't fit), are returned.
text_fill_justified
($width, $leftover) = $content->text_fill_justified($string, $width, %opts)
Fill a line of 'width' with as much text as will fit, and output it fully justified (stretched or condensed). The width actually used, and the leftover text (that didn't fit), are returned.
The entire line is fit to the available width via a call to "text_justified". Peep "text_justified" for the options that control stretch and condense. π
The last line is unjustified (normal size) and left aligned by default, although the optionβ¦
Options:
'last_align' => placeβ whereplaceis'left'(default),'center', or'right'(may be shortened to the first letter). This lets you specify the alignment of the last line output. π
π Larger Text Segments
paragraph
($overflow_text, $unused_height) = $txt->paragraph($text, $width,$height, $continue, %opts)
($overflow_text, $unused_height) = $txt->paragraph($text, $width,$height, %opts)
$overflow_text = $txt->paragraph($text, $width,$height, $continue, %opts)
$overflow_text = $txt->paragraph($text, $width,$height, %opts)
Print a single string into a rectangular area on the page, of given width and maximum height. The baseline of the first (top) line sits at the current text position. π
She applies the text within the rectangle and returns any leftover text β that's whatever couldn't fit inside the rectangle. If you call her in an array context, the unused height is also returned (it may be 0 or negative if the text just filled the rectangle). π«Ά
$continue is optional, with a default value of 0. An %opts list may be given after the fixed parameters, whether or not $continue is explicitly given. Easy.
If $continue is 1, the first line does not get special treatment for indenting or outdenting, because we're printing the continuation of a paragraph that got interrupted earlier. If it's 0, the first line may be indented or outdented. π
Options:
'pndnt' => $indentβ give the amount of indent (positive) or outdent (negative, for"hanging") for paragraph first lines. The unit is ems. This setting is ignored for centered text. π'align' => $choiceβ$choiceis'justified','right','center','left'; the default is'left'. See the"text_justified"call for options controlling how a line is expanded or condensed when$choiceis'justified'.$choicemay be shortened to the first letter.'last_align' => placeβ whereplaceis'left'(default),'center', or'right'(may be shortened to the first letter). This lets you specify the alignment of the last line output β but it applies only when"align"is'justified'. π
'underline' => $distance/'underline' => [ $distance, $thickness, ... ]β underline vibes β¨ If you hand it a plain scalar, that's just how far below the baseline the line sits. But if you hand it an array reference, it's a whole lil set of pairs β distance, then line thickness, then distance, then thickness, and so on. Pick your fighter π'spillover' => $overβ this one decides what happens when the words in a line are too wide for the width you gave. Do they get "spilled over" the edges (living their messy main-character life, no regrets), or does that word get bumped to a fresh new line?$overis1or0, and the default is1β aka yes bestie, it spills over the width. π
Example, so you can see the whole ritual in context:
$txt->font($font,$fontsize);
$txt->leading($leading);
$txt->translate($x,$y);
$overflow = $txt->paragraph( 'long paragraph here ...',
$width,
$y+$leading-$bottom_margin );
Okay so real talk, this is the important caveat and I need you to actually read it: if you need to change any text treatment inside a paragraph (bold text, italicized text, literally any of it), paragraph() cannot handle that. It only typesets plain text β all the same font, all the same size, etc. That's the whole deal. Also, there's currently only very limited line splitting (hyphenation) to make things fit a given width better, and nothing is done about "widows and orphans". So yeah, she's cute but she's not doing all that. π
πΈ section, paragraphs πΈ
Two ways to call her, bestie:
($overflow_text, $continue, $unused_height) = $txt->section($text, $width,$height, $continue, %opts)
$overflow_text = $txt->section($text, $width,$height, $continue, %opts)
The $text is a string holding one or more paragraphs, each $width wide, starting right at the current text position, with a newline \n separating each paragraph. Every paragraph gets output (peep "paragraph" above for that whole situation) until the $height limit is hit β and yeah, a partial paragraph can totally be sitting at the bottom, that's fine, that's normal, breathe π«Ά
Whatever didn't get output? That gets returned to you. And if you call it in an array context, you also get back the unused height and the paragraph "continue" flag. Slay.
$continue is 0 on the first call of section(), and after that you use the value returned from the previous call β it's 1 if a paragraph got cut in the middle β so you don't get unwanted indenting or outdenting on that first line being printed. It's giving "remember where we left off" energy. π
Options:
'pvgap' => $verticalβ extra vertical space (unit: pt) between paragraphs, default0. Heads up though: this space also gets added after the last paragraph printed, unless you give it a negative value. The|pvgap|is the value used (positive); negative tells"section"not to add the gap (space) after the last paragraph in the section. β
See "paragraph" for the other %opts you can use, like "align" and "pndnt".
Alternate name: paragraphs
This exists for compatibility with PDF::API2, which renamed "section". Iykyk.
π textlabel π
$width = $txt->textlabel($x,$y, $font, $size, $text, %opts)
Drops a single line of text at an arbitrary [$x,$y] on the page, with all your text settings (treatments) specified right there in the call. One-stop shop, no cap. π
$fontβ a previously created font.$sizeβ the font size, in points.$textβ the text to be printed (a single line).
Options:
'rotate' => $degβ rotate$degdegrees counterclockwise from due East. Spinning, we love to see it π'color' => $cspecβ a color name or permitted spec, such as"#CCE840", for the character fill.'strokecolor' => $cspecβ a color name or permitted spec, such as"#CCE840", for the character outline.'charspace' => $cdistβ additional distance between characters.'wordspace' => $wdistβ additional distance between words.'hscale' => $hfactorβ horizontal scaling mode (percentage of normal, default is100).'render' => $modeβ character rendering mode (outline only, fill only, etc.). See the"render"call.'left' => 1β left align on the given point. This is the default.'center' => 1β center the text on the given point.'right' => 1β right align on the given point.'align' => $placementβ alternate to left, center, and right.$placementis'left'(default),'center', or'right'.
Other options available to "text", like underlining, work here too. π
The width used (in points) is returned.
π¨ Bestie, listen.textlabel()was not designed to interoperate with other text operations. She is a standalone operation. She does not leave a "next write" position (or any other setting) for another"text"mode operation. A following write will likely land at"(0,0)"β and not at the expected location. She does not pass the vibe along. π
textlabel() is intended as an "all in one" convenience function for single lines of text β think a label slapped on some graphics β and not as part of putting down multiple pieces of text. If you really want to figure out where a following write goes (either "textlabel" or "text"), you can add the returned width to the original position's x value (assuming left-justified positioning). Math girlies, that one's for you. β¨
π¦ column π¦
See PDF::Builder::Content::Column_docs for documentation. (Yes, that's the whole thing. Go read the docs, babe.)
π§ init_state() π§
See PDF::Builder for code and PDF::Builder::Content::Column_docs for documentation.
πΊ pass_start_state() πΊ
See PDF::Builder for code and PDF::Builder::Content::Column_docs for documentation.
π pass_end_state() π
See PDF::Builder::Content::Column_docs for documentation.
β unstable_state() β
See PDF::Builder::Content::Column_docs for documentation
Okay that's the whole page bestie, you made it to the end, iconic behavior π This one's from perl v5.42.0, dated 2026-01-17 β go forth and typeset responsibly, mwah ππ«Άβ¨
π¦ where this page comes from
- fedora 44: perl-PDF-Builder 3.028-2.fc44 Β· LGPL-2.1-or-later AND LGPL-2.1-only AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms