PDF::Report(3) A wrapper written for PDF::API2


use PDF::Report;
my $pdf = new PDF::Report(%opts);


This is a wrapper for Alfred Reibenschuh's PDF::API2 Defines methods to create PDF reports





my $pdf = new PDF::Report(%opts);

        Creates a new pdf report object.
        If no %opts are specified the module
        will use the factory defaults.


        my $pdf = new PDF::Report(PageSize => "letter",
                                  PageOrientation => "Landscape");
        my $pdf = new PDF::Report(File => $file);


        PageSize - '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 - 'Portrait', 'Landscape'



Creates a new blank page. Pass $nopage = 1 to toggle page numbering.



If no index is specified, this will open the last page of the document.


Import page from another PDF document, see PDF::API2


Clone page within document, see PDF::API2


($pagewidth, $pageheight) = $pdf->getPageDimensions();

Returns the width and height of the page according to what page size chosen in ``new''.


$pdf->addRawText($text, $x, $y, $color, $underline, $indent, $rotate);

Add $text at position $x, $y with $color, $underline, $indent and/or $rotate.

PDF::API2 Removes all space between every word in the string you pass and then rejoins each word with one space. 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;
      return $new;


$pdf->setAddTextPos($hPos, $vPos);

Set the position on the page. Used by the addText function.


($hPos, $vPos) = $pdf->getAddTextPos();

Return the (x, y) value of the text position.



Set the justification of the text. Used by the addText function.


$align = $pdf->getAlign();

Returns the text justification.


$newtext = $pdf->wrapText($text, $width);

This is a helper function called by addText, which can be called by itself. wrapText() wraps $text within $width.


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


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


$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!




Returns the width of $String according to the current font and fontsize being used.


$pdf->addImg($file, $x, $y);

Add image $file to the current page at position ($x, $y).


$pdf->addImgScaled($file, $x, $y, $scale);

Add image $file to the current page at position ($x, $y) scaled to $scale.



Set the line width drawn on the page.


$width = $pdf->getGfxLineWidth();

Returns the current line width.


$pdf->drawLine($x1, $y1, $x2, $y2);

Draw a line on the current page starting at ($x1, $y1) and ending at ($x2, $y2).


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


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

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


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


Returns list of available colours


$pdf->drawBarcode($x, $y, $scale, $frame, $type, $code, $extn, $umzn,

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. $x and $y represent the center of the barcode's position on the document. $scale is the size of the entire barcode 1 being 1:1, which is all you'll need most likely. $type is the type of barcode which can be codabar, 2of5int, 3of9, code128, or ean13. $code is the alpha-numeric code which the barcode will represent. $extn is the extension to the $code, where applicable. $umzn is the upper mending zone and $lmzn is the lower mending zone. $zone is the the zone or height of the bars. $quzn is the quiet zone or the space between the frame and the barcode. $spcr is what to put between each number/character in the text. $ofwt is the overflow width. $fnsz is the fontsize used for the text. $text is optional text beneathe the barcode.



Creates a new font object of type $font to be used in the page.


$fontname = $pdf->getFont();

Returns the font name currently being used.



Sets the fontsize to $size. Called before setFont().


$fontsize = $pdf->getSize();

Returns the font size currently being used.


$pages = $pdf->pages();

The number of pages in the document.



Sets the info structure of the document. Valid keys for %infohash: Creator, Producer, CreationDate, Title, Subject, Author, etc.


%infohash = $pdf->getInfo();

Gets meta-data from the info structure of the document. Valid keys for %infohash: Creator, Producer, CreationDate, Title, Subject, Author, etc.


Saves the document to a file.

  # Save the document as "file.pdf"
  my $fileName = "file.pdf";


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();


Object method returns underlying PDF::API2 object


Andrew Orr


Aaron TEEJAY Trevena


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.


You can find documentation for this module with the perldoc command.

    perldoc PDF::Report

You can also look for information at:


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.