PDF::Report(3pm)
π PDF::Report β the manual, but make it make sense π
okay bestie, sit down, hydrate, and let me tell you about PDF::Report β a wrapper written for PDF::API2. This is the PDF::Report(3pm) page from the User Contributed Perl Documentation, and yes we're doing this properly, no skimming, no skipping, periodt. β¨
πΈ NAME πΈ
PDF::Report β a wrapper written for PDF::API2. That's it, that's the whole vibe. π
π¦ SYNOPSIS π¦
Look at this, it's literally three lines, you can do this:
use PDF::Report;
my $pdf = new PDF::Report(%opts);
That's the whole opening move. You pull the module in, you make yourself an object, and you go live your life. π
β¨ DESCRIPTION β¨
So here's the tea: this is a wrapper for Alfred Reibenschuh's PDF::API2. And what does it do with that? It defines methods to create PDF reports. That's the whole personality. It's a report-making bestie sitting on top of a PDF-making bestie. Iconic chain of command honestly. π
β VERSION β
1.36
Yes bestie, we're on 1.36. Write it down. π
π METHODS π
okay here comes the main event, the whole roster, every single one, let's go:
π new π
my $pdf = new PDF::Report(%opts);
Creates a new pdf report object. If no %opts are specified, the module will use the factory defaults. That's it. No drama, no fuss, defaults carry you. π«Ά
Example:
my $pdf = new PDF::Report(PageSize => "letter",
PageOrientation => "Landscape");
my $pdf = new PDF::Report(File => $file);
Look at that second one, so chill, just hand it a file and go.
%opts:
Here's your option menu, don't lose it:
PageSizeβ pick your paper, bestie:'4A','2A','A0','A1','A2','A3','A4','A5','A6','4B','2B','B0','B1','B2','B3','B4','B5','B6','LETTER','BROADSHEET','LEDGER','TABLOID','LEGAL','EXECUTIVE','36X36'PageOrientationβ which way is it facing:'Portrait','Landscape'
π¦ newpage π¦
$pdf->newpage($nopage);
Creates a new blank page. Pass $nopage = 1 to toggle page numbering. That's the little switch, don't forget it exists. β¨
πΈ openpage πΈ
$pdf->openpage($index);
If no index is specified, this will open the last page of the document. No index = last page, that's the default behaviour, no cap. π
π importpage π
Import page from another PDF document, see PDF::API2. That's it, that's the whole entry, go read the other manual for the details, iykyk. π§
π clonepage π
Clone page within document, see PDF::API2. Same deal, the details live over there. π
π getPageDimensions π
($pagewidth, $pageheight) = $pdf->getPageDimensions();
Returns the width and height of the page according to what page size chosen in "new". So whatever you picked up in new, this hands you back the measurements. Cute. π¦
π addRawText π
$pdf->addRawText($text, $x, $y, $color, $underline, $indent, $rotate);
Add $text at position $x, $y with $color, $underline, $indent and/or $rotate. Yes you can rotate it. Slay.
β οΈ okay this next part is the important lore, pay attention bestie:
PDF::API2 removes all space between every word in the string you pass and then rejoins each word with one space. So if you want to use a string with more than one space between words for formatting purposes, you can either use the hack below or change PDF::API2 (that's what I did ;). The code below may or may not work according to what font you are using. I used 2 \xA0 per space because that worked for the Helvetica font I was using.
To use a fixed width string with more than one space between words, you can do something like:
sub replaceSpace {
my $text = shift;
my $nbsp = "\xA0";
my $new = '';
my @words = split(/ /, $text);
foreach my $word (@words) {
if (length($word)) {
$new.=$word . ' ';
} else {
$new.=$nbsp . $nbsp;
}
}
chop($new);
return $new;
}
Copy it, paste it, thank me later. π
π setAddTextPos π
$pdf->setAddTextPos($hPos, $vPos);
Set the position on the page. Used by the addText function. You set it here, addText uses it there. Teamwork. π«Ά
β¨ getAddTextPos β¨
($hPos, $vPos) = $pdf->getAddTextPos();
Return the (x, y) value of the text position. Yes, (x, y). That's exactly how the original says it. Not changing it. π
π setAlign π
$pdf->setAlign($align);
Set the justification of the text. Used by the addText function. Left, right, center, whatever, you pick. π
β getAlign β
$align = $pdf->getAlign();
Returns the text justification. Just tells you where you set it. Simple. π
π¦ wrapText π¦
$newtext = $pdf->wrapText($text, $width);
This is a helper function called by addText, which can be called by itself. wrapText() wraps $text within $width. It's a helper, but it's a helper with main character energy, you can absolutely call it on its own. π
πΈ addText πΈ
$pdf->addText($text, $hPos, $textWidth, $textHeight);
Takes $text and prints it to the current page at $hPos. You may just want to pass this function $text if the text is "pre-wrapped" and setAddTextPos has been called previously. Pass a $hPos to change the position the text will be printed on the page. Pass a $textWidth and addText will wrap the text for you. $textHeight controls the row height. Four knobs, all of them optional-ish depending on your vibe. π
π addParagraph π
$pdf->addParagraph($text, $hPos, $vPos, $width, $height, $indent,
$lead);
Add $text at ($hPos, $vPos) within $width and $height, with $indent. $indent is the number of spaces at the beginning of the first line. Yes, just the first line. First-line indent only. π§
π centerString π
$pdf->centerString($a, $b, $yPos, $text);
Centers $text between points $a and $b at position $yPos. Be careful how much text you try to jam between those points, this function shrinks the text till it fits! fr fr, it will squeeze your text to fit. Don't put a whole novel between two points and act surprised. π
π setRowHeight π
No description given in the original. It's just here, sitting pretty, existing. Respect the mystery. β
π getStringWidth π
$pdf->getStringWidth($String);
Returns the width of $String according to the current font and fontsize being used. So it depends on your font and size, not a fixed number. Keep that in mind. β¨
π addImg π
$pdf->addImg($file, $x, $y);
Add image $file to the current page at position ($x, $y). Simple, clean, one image, one spot. π¦
π addImgScaled π
$pdf->addImgScaled($file, $x, $y, $scale);
Add image $file to the current page at position ($x, $y) scaled to $scale. Same as before but now with a size slider. π
β setGfxLineWidth β
$pdf->setGfxLineWidth($width);
Set the line width drawn on the page. Thicc lines, thin lines, your call. π
π¦ getGfxLineWidth π¦
$width = $pdf->getGfxLineWidth();
Returns the current line width. Whatever you set, it tells you back. π«Ά
πΈ drawLine πΈ
$pdf->drawLine($x1, $y1, $x2, $y2);
Draw a line on the current page starting at ($x1, $y1) and ending at ($x2, $y2). Start point, end point, line. We love a straight line. π
π drawRect π
$pdf->drawRect($x1, $y1, $x2, $y2);
Draw a rectangle on the current page. Top left corner is represented by ($x1, $y1) and the bottom right corner is ($x2, $y2). Top-left to bottom-right, that's the mapping, don't get it twisted. π
π shadeRect π
$pdf->shadeRect($x1, $y1, $x2, $y2, $color);
Shade a rectangle with $color. Top left corner is ($x1, $y1) and the bottom right corner is ($x2, $y2). Same corner rules as drawRect, but now it's filled in. Slay. β¨
Defined color-names are:
aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque,
black, blanchedalmond, blue, blueviolet, brown, burlywood,
cadetblue, chartreuse, chocolate, coral, cornflowerblue, cornsilk,
crimson, cyan, darkblue, darkcyan, darkgoldenrod, darkgray,
darkgreen, darkgrey, darkkhaki, darkmagenta, darkolivegreen,
darkorange, darkorchid, darkred, darksalmon, darkseagreen,
darkslateblue, darkslategray, darkslategrey, darkturquoise,
darkviolet, deeppink, deepskyblue, dimgray, dimgrey, dodgerblue,
firebrick, floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite,
gold, goldenrod, gray, grey, green, greenyellow, honeydew, hotpink,
indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen,
lemonchiffon, lightblue, lightcoral, lightcyan,
lightgoldenrodyellow, lightgray, lightgreen, lightgrey, lightpink,
lightsalmon, lightseagreen, lightskyblue, lightslategray,
lightslategrey, lightsteelblue, lightyellow, lime, limegreen, linen,
magenta, maroon, mediumaquamarine, mediumblue, mediumorchid,
mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen,
mediumturquoise, mediumvioletred, midnightblue, mintcream,
mistyrose, moccasin, navajowhite, navy, oldlace, olive, olivedrab,
orange, orangered, orchid, palegoldenrod, palegreen, paleturquoise,
palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue,
purple, red, rosybrown, royalblue, saddlebrown, salmon, sandybrown,
seagreen, seashell, sienna, silver, skyblue, slateblue, slategray,
slategrey, snow, springgreen, steelblue, tan, teal, thistle, tomato,
turquoise, violet, wheat, white, whitesmoke, yellow, yellowgreen
or the rgb-hex-notation:
#rgb, #rrggbb, #rrrgggbbb and #rrrrggggbbbb
or the cmyk-hex-notation:
%cmyk, %ccmmyykk, %cccmmmyyykkk and %ccccmmmmyyyykkkk
and additionally the hsv-hex-notation:
!hsv, !hhssvv, !hhhsssvvv and !hhhhssssvvvv
So like, name it, hash it, percent it, or bang it. Four whole ways to say a color. Rainbow-coded honestly. π
π drawPieGraph π
$pdf->drawPieGraph($x, $y, $size, $rData, $rLabels);
Method to create a piegraph using a reference to an array of values. It also takes a reference to an array for labels for each data value. A legend with all the colors and labels will appear if $rLabels is passed. $x and $y are the coordinates for the center of the pie and $size is the radius. Center, radius, data ref, label ref. Boom, pie. π₯§ (well, pie chart.) π
β getcolors β
Returns list of available colours. That's it. Short king of a method. π
π¦ drawBarcode π¦
$pdf->drawBarcode($x, $y, $scale, $frame, $type, $code, $extn, $umzn,
$lmzn, $zone, $quzn, $spcr, $ofwt, $fnsz,
$text);
This is really not that complicated, trust me! ;) I am pretty unfamiliar with barcode lingo and types so if I get any of this wrong, lemme know! This is a very flexible way to draw a barcode on your PDF document. Okay here's the full breakdown, one by one:
$xand$yrepresent the center of the barcode's position on the document.$scaleis the size of the entire barcode,1being 1:1, which is all you'll need most likely.$typeis the type of barcode which can becodabar,2of5int,3of9,code128, orean13.$codeis the alpha-numeric code which the barcode will represent.$extnis the extension to the$code, where applicable.$umznis the upper mending zone and$lmznis the lower mending zone.$zoneis the the zone or height of the bars. (yes, "the the", it's in the original, I'm keeping it, it's canon now π)$quznis the quiet zone or the space between the frame and the barcode.$spcris what to put between each number/character in the text.$ofwtis the overflow width.$fnszis the fontsize used for the text.$textis optional text beneathe the barcode.
See? Not that complicated. Sixteen-ish arguments but they all have jobs. π
πΈ setFont πΈ
$pdf->setFont($font);
Creates a new font object of type $font to be used in the page. New font object, just for your page. π
π getFont π
$fontname = $pdf->getFont();
Returns the font name currently being used. Current font, right now, at this moment. β
π setSize π
$pdf->setSize($size);
Sets the fontsize to $size. Called before setFont(). Order matters bestie, size first, then font. Don't reverse it. π«Ά
π getSize π
$fontsize = $pdf->getSize();
Returns the font size currently being used. Same energy as getFont but for size. β¨
π pages π
$pages = $pdf->pages();
The number of pages in the document. Count 'em. π¦
π setInfo π
$pdf->setInfo(%infohash);
Sets the info structure of the document. Valid keys for %infohash: Creator, Producer, CreationDate, Title, Subject, Author, etc. Metadata moment. Put your name on it. π
β getInfo β
%infohash = $pdf->getInfo();
Gets meta-data from the info structure of the document. Valid keys for %infohash: Creator, Producer, CreationDate, Title, Subject, Author, etc. Same keys, but reading instead of writing. π
π¦ saveAs π¦
Saves the document to a file.
# Save the document as "file.pdf"
my $fileName = "file.pdf";
$pdf->saveAs($fileName);
That's it, that's the whole thing. Name it, save it, done. π
πΈ Finish πΈ
Returns the PDF document as text. Pass your own custom routine to do things on the footer of the page. Pass 'roman' for Roman Numeral page numbering.
# Hand the document to the web browser
print "Content-type: application/pdf\n\n";
print $pdf->Finish();
So you can hand it straight to the browser like that. Content-type first, then the document. Classic. π
π getPDFAPI2Object π
Object method returns underlying PDF::API2 object. For when you wanna go under the wrapper and talk to the base module directly. iykyk. β¨
π AUTHOR EMERITUS π
Andrew Orr β the legend emeritus. Respect the emeritus status. π
π MAINTAINER π
Aaron TEEJAY Trevena β current holder of the crown, keeping this thing alive. π«Ά
π BUGS π
Please report any bugs or feature requests to "bug-calendar-model at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PDF-Report>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. So like, you file it, I see it, you get updates. Closed loop, no ghosting. π
okay bestie that's part 1, and there is more coming, so don't go anywhere, hydrate, stretch, and keep scrolling π β¨
π SUPPORT π
okay bestie, if you ever get stuck (and you won't, you're doing amazing), the docs for this module live right at your fingertips, no cap:
and if you wanna go full detective mode, there's a whole lil network of places to peek at:
- RT: CPAN's request tracker (report bugs here) β this is the spot to snitch on bugs, they wanna hear it fr fr
http://rt.cpan.org/NoAuth/Bugs.html?Dist=PDF-Report
- AnnoCPAN: Annotated CPAN documentation β the docs but with the community's lil commentary sprinkled on top β¨
http://annocpan.org/dist/PDF-Report
- CPAN Ratings β go drop your hot take, be honest but be nice π
http://cpanratings.perl.org/d/PDF-Report
- METACPAN β the main character of CPAN interfaces, she has everything
https://metacpan.org/module/PDF::Report/
- GITHUB β the source code's actual home, come thru π«Ά
https://github.com/hashbangperl/perl-pdf-report
π SEE ALSO π
PDF::API2β the icon this whole thing is built on top of, lowkey the blueprint π
π LICENSE AND COPYRIGHT π
Copyright 2008-2010 Andy Orr
Copyright 2013 Aaron Trevena
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
so basically you can remix it, share it, whatever β just respect the license terms, mkay? it's giving generous but read-the-fine-print energy πβ¨
and that's a wrap on this whole page, bestie π you just read the manual for perl v5.34.0, dated 2022-06-16, aka PDF::Report(3pm) β go forth and generate some iconic PDFs, you absolute legend ππ
π¦ where this page comes from
- debian bookworm: libpdf-report-perl 1.36-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpdf-report-perl 1.36-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpdf-report-perl 1.36-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpdf-report-perl 1.36-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpdf-report-perl 1.36-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms