Andy Orr > PDF-Report-1.30 > PDF::Report

Download:
PDF-Report-1.30.tar.gz

Dependencies

Annotate this POD (4)

Related Modules

Win32::OLE
PDF::API2
PDF::Template
PDF::Reuse
HTML::Template
PDF::Labels
PDF::Create
GD::Graph
Mac::PropertyList
Geo::IP
more...
By perlmonks.org

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 1.30   Source  

PDF::Report ^

NAME ^

PDF::Report - A wrapper written for PDF::API2

SYNOPSIS ^

        use PDF::Report;

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

METHODS ^

my $pdf = new PDF::Report(%opts);
        Creates a new pdf report object.  
        If no %opts are specified the module 
        will use the factory defaults.

Example:

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

        my $pdf = new PDF::Report(File => $file);

%opts:

        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'
$pdf->newpage($nopage);

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

$pdf->openpage($index);

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

($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; } } chop($new); 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.

$pdf->setAlign($align);

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!

$pdf->getStringWidth($String);

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.

$pdf->setGfxLineWidth($width);

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.

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

$pdf->setFont($font);

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

$fontname = $pdf->getFont();

Returns the font name currently being used.

$pdf->setSize($size);

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

$fontsize = $pdf->getSize();

Returns the font size currently being used.

$pdf->setInfo(%infohash);

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

$pdf->saveAs($fileName);

Saves the document to a file.

Example:
       # Save the document as "file.pdf"
        my $fileName = "file.pdf";
       $pdf->saveAs($fileName);
print $pdf->Finish(\&callback());

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.

Example:
        # Hand the document to the web browser
        print "Content-type: application/pdf\n\n";
        print $pdf->Finish();

AUTHOR ^

Andrew Orr

syntax highlighting: