PDF::EasyPDF - PDF creation from a one-file module, with postscript-like controls
use PDF::EasyPDF;
my $pdf = PDF::EasyPDF->new({file=>"mypdffile.pdf",x=>mm(297),y=>mm(210)});
$pdf->setStrokeColor("CC0000");
$pdf->setStrokeWidth(8);
$pdf->rectangle(mm(10),mm(10),mm(297-20),mm(210-20));
$pdf->setFillColor("FFCC00");
$pdf->filledRectangle(mm(20),mm(20),mm(297-40),mm(210-40));
$pdf->setFillColor("CC0000");
$pdf->setFontFamily("Helvetica-Bold");
$pdf->setFontSize(24);
$pdf->text(mm(105),mm(210-22.5),"PDF::EasyPDF Demo");
$pdf->lines(mm(85),mm(35),mm(90),mm(105),mm(95),mm(35),mm(100),mm(105),mm(105),mm(35),mm(110),mm(105));
$pdf->setStrokeColor("000099");
$pdf->curve(300,300,300,400,400,400,400,300);
$pdf->setStrokeColor("0066FF");
$pdf->setFillColor("00FFFF");
$pdf->polygon(100,100,250,200,250,400,200,500);
$pdf->filledPolygon(100,100,250,200,250,400,200,500);
$pdf->close;
This module started life as a workaround, on discovering that PDF::API2 and friends are extremely tricky to compile using Activestate's PerlApp utility because of the large number of runtime modules and resource files they use. The module consists of a single .pm file. It produces small PDF files, partly because it only uses the 14 standard PDF fonts. Page content is implemented using a single stream object, and the controls are vaguely postscript-like.
Mark Howe, <melonman@cpan.org>
The mm and inch functions.
mm
inch
Creates a new PDF::EasyPDF object. The arguments are passed as an anonymous hash to allow, eventually, for different combinations of arguments. filename is the name of the PDF to be created (although nothing is output until the close method is called. x and y are the x and y dimensions of the page in points (see the mm and inch functions for a more convenient way to specify page sizes).
close
Writes a pdf file.
Returns a list of supported fonts (currently the fourteen standard Adobe fonts).
Sets the stroke (more or less 'line') colour using an html-like rrggbb string, ie FFFF00 = bright yellow.
FFFF00
Sets the fill colour (including the text colour).
Sets the stroke (more or less 'line') width in points.
Sets the font.
Sets the font size in points
Sets the dash pattern. Pass a list of numbers to set the alternating 'on' and 'off' lengths in points, or, with no arguments, to reset to a solid line
Set the cap style for the ends of lines. Options are round, square or butt.
round
square
butt
Set the join style for lines. Options are round, bevel or miter.
bevel
miter
Places text at x,y
Prints one or more lines, using alternative x and y coordinates.
Prints a closed, unfilled polygon using alternative x and y coordinates.
Prints a closed, filled polygon with no border using alternative x and y coordinates.
Prints a bezier curve.
Prints a filled bezier curve without a border.
Prints an unfilled bezier curve, with the first and last points joined by a straight line.
Inserts a move operation (use to start new paths)
Inserts a line segment
Inserts a curve segment
Closes a path
Strokes the path
Fills the path using the non-zero winding number rule
Fills the path using the odd-even winding rule (f*, hence the 'star')
Fills the path using the non-zero winding number rule and then strokes it
Fills the path using the odd-even winding rule and then fills it (B*, hence the 'star')
Prints an unfilled rectangle.
Prints a filled rectangle with no border.
Converts inches into points
Converts millimetres into points
None known, but the methods do relatively little sanity checking, and there is absolutely no encoding yet for text (so it's probably impossible to print parentheses, for example).
A first stab at encoding text, arrowheads.
0.04: Consistent capitalisation of methods, generic arbitrary path drawing mechanism. 0.03: Beat module into something approaching standard CPAN shape.
Copyright (C) 2006 by Mark Howe
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
To install PDF::EasyPDF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDF::EasyPDF
CPAN shell
perl -MCPAN -e shell install PDF::EasyPDF
For more information on module installation, please visit the detailed CPAN module installation guide.