NAME
PDF::CreateSimple
DESCRIPTION
This module let you create simple PDF files using a set of eary to use function. You can either create a file from scratch or start using an already existing file.
SYNOPSIS
use PDF::CreateSimple;
my $pdfFile = PDF::CreateSimple->new($pdfPath);
#-----------------------------------------------------------------------------
# Add a new page
#-----------------------------------------------------------------------------
$pdfFile->addNewPage;
#-----------------------------------------------------------------------------
# Write Text
#-----------------------------------------------------------------------------
$pdfFile->drawText('See what it can do!','Verdana',12,400,200,'cyan');
#-----------------------------------------------------------------------------
# Create Straight and Curved Lines
#-----------------------------------------------------------------------------
$pdfFile->drawLine(0,0,50,50,1,'black');
$pdfFile->drawCurve(0,0,50,50,100,50,1,'olive');
#-----------------------------------------------------------------------------
# Create Hollow Geometric Figures
#-----------------------------------------------------------------------------
$pdfFile->drawRectangle(0,0,50,50,2,'blue');
$pdfFile->drawPolygon([10,15,20,25,25,30,50,100,50,200],2,'orange');
#-----------------------------------------------------------------------------
# Create Filled Geometric Figures
#-----------------------------------------------------------------------------
$pdfFile->drawCircle(100,100,30,3,'black','green');
$pdfFile->drawSquare(150,100,30,1,'olive','red');
#-----------------------------------------------------------------------------
# Import Images (png,pnm,tiff,gif,jpg) and other PDF Files
#-----------------------------------------------------------------------------
$pdfFile->drawImage('some_img.jpg',150,150,1.75);
$pdfFile->drawImage('some_other_img.jpg',350,150,200,200);
$pdfFile->importPage('source_pdf');
#-----------------------------------------------------------------------------
# Save And close
#-----------------------------------------------------------------------------
$pdfFile->closeFile;
METHODS
Note on recurring function parameters:
lineWidth(integer) : Specefy the thickness of the lines defining the figures strokecolor : See color for more info fillcolor : Optional, when defined, the object will be filled using that color. If undef, the form will be hollow pageno : optional, when not defined, it will used the currently selected page.
Text
drawText(string,font,fontsize,x,y,color,align,pageNo)
Draw the text 'string' at (x,y) using the font 'font' of size fontSize and color 'color'. If align is undef or 0, the text will be left aligned at (x,y) If align is set to 1, the text will be centered at (x,y) If align is set to 2, the text will be right aligned at (x,y) calling 'drawText' in scalar context will return the width of the printed Text.
drawTextOrWidth($drawing,$text,$font,$size,@more)
If drawing is set to 1, return the width of 'text' given the 'font' and the 'size'. If drawing is set to 0, draw the text 'string' at (x,y) using the font 'font' of size fontSize and color 'color'. If align is undef or 0, the text will be left aligned at (x,y) If align is set to 1, the text will be centered at (x,y) If align is set to 2, the text will be right aligned at (x,y)
drawTextOnlyIfFit($text,$font,$fontSize,$x,$y,$color,$align,$pageNo)
Draw the text 'string' at (x,y) using the font 'font' of size fontSize and color 'color' only if the text will fit in the page. Otherwise, it will draw nothing. If align is undef or 0, the text will be left aligned at (x,y) If align is set to 1, the text will be centered at (x,y) If align is set to 2, the text will be right aligned at (x,y) calling 'drawTextOnlyIfFit' in scalar context will return the width of the printed Text or 0 if it can't display it.
Fonts Properties
getFontWidth($text,$font,$size)
Return the width of the 'text' given the 'font' and 'size'
getFontMaxWidth($font,$size)
Return the maximum width for the given 'font' and 'size'. The maximum width is the width of the largest possible caracter of the font set.
getFontSpaceWidth($font,$size)
Return the width of the whitespace caracter for the given 'font' and 'size'
getFontPosition($font,$size)
Return the relative y position for the given 'font' and 'size'
Lines and Curves
drawLine(x1,x2,y1,y2,lineWidth,strokecolor,pageNo)
Draw a line at the specified coordinates from (x1,y1) to (x2,y2)
drawDashedLine($x1, $y1, $x2, $y2, $lineWidth, $on, $off, $strokecolor, $pageNo)
Draw a dashed line at the specified coodinates from (x1,y1) to (x2,y2). $on specifies the length of the 'on'(drawn) portions while $off the length of the 'off'(not drawn) portions.
drawCurve(x1,y1,x2,y2,fx,fy,linewidth,strokecolor,pageNo)
Draw a curve at the specified coordinates from (x1,y1) to (x2,y2) with a curve streching to reach the flex point(fx,fy)
Simple Geometric Forms
drawRectangle(x1,y1,x2,y2,lineWidth,strokecolor,fillcolor,pageNo)
Draw a rectangle using (x1,y1) and (x2,y2) as corner point
drawSquare(x,y,size,lineWidth,strokecolor,fillcolor,pageNo)
Draw a square using (x,y) as one of the corner and size as width and height
drawCircle(x,y,r,lineWidth,strokecolor,fillcolor,pageNo)
Draw a circle of center point(x,y) and radius r
drawEllipse(x,y,r1,r2,lineWidth,strokecolor,fillcolor,pageNo)
Draw an ellipse of center point(x,y), horizontal radius r1 and vertical radius r2
drawArc(x,y,r1,r2,alpha,beta,lineWidth,strokecolor,fillcolor,pageNo)
Draw an arc of center point(x,y), horizontal radius r1 , versitcal radius r2 and going from degree alpha to beta
drawPie(x,y,r1,r2,alpha,beta,lineWidth,strokecolor,fillcolor,pageNo)
Draw a pie of center point (x,y), horizontal radius r1, vertical redius r2 and going from degree alpha to beta. Unlike an Arc, drawPie will close the form to make a pie slice shape form.
Complex Figures
drawPolygon(points,lineWidth,strokecolor,fillcolor,pageNo)
Draw a polygon using the specified points. Points format is (x1,y1,x2,y2,x3,y3,...,xn,yn)
drawGridFromPoints(xs,ys,lineWidth,strokecolor,pageNo)
draw a grid using two list of points for vertical line(xs) and horizontal lines(ys)
drawGridFromIntervals(x1,y1,x2,y2,xInt,yInt,lineWidth,stokecolor,pageNo)
draw a grid starting at (x1,y1) and ending at (x2,y2) that have a vertical line at every 'xInt' and an horizontal line at every 'yInt'
drawPieChart(x,y,r1,r2,values,showString,showValue,pageNo)
Draw a pie chart at center point (x,y), horizontal radius r1 and vertical radius r2. Each item in values is a slice of the pie. The format of the values list is a hash string : the caption to display, value : the value of the item (used to calculate the size of the slice) color : the color of the pie slice If showString is set to true, the caption will be shown near the slice. If showValue is set to true, the value will be shown near the slice. If both showString and showValue are set to true, the label that will appear near the slice will be string(value)
Images and Pdf Pages
drawImage(path,x,y,scale,undef,pageNo)
Import an image found in path and draw it with left,bottom corner point at (x,y). If scale is defined, but not h, the image size will be multiplied by 'scale' (ex: 0.5 would print it at half its size) If both scale and h is defined, then the image will be resized to width of 'scale' and height of 'h' Currently supported image format are png,pnm,jpeg,gif and tiff
importPage(sourcePath,sourcePageIndex,pageNo)
Import a page from another pdf file into this one. The source page will be 'sourcePageIndex' and will be inserted before the 'pageNo'th page (ex: if pageNo = 2, it will insert between the first and second page) If pageNo is set to 0 or undef, the page will be inserted at the end. The current page will also be set to the newly created page.
Cannonical Transformations
setRotation(angle)
Set the rotation angle to 'angle' degree (not radian). All future objects (except an inported pdf page) will be rotated counter-clockwise by that angle until it is changed. To remove the rotation, either set it to 0 or call resetTransformations. setRotation is not additive (ex : setRotation(15); setRotation(25) will set it to 25, not 40)
setSkew(x,y)
Set the skewness to (x,y). All future objects (except an inported pdf page), will be skewed until it is changed. To remove skewness, either set it to (0,0) or call resetTransformations setSkew is not additive (ex : setSkew(1,1); setSkew(2,3) will set it to (2,3), not (3,4))
resetTransformations
Reset both rotation and skewness to none.
File Browsing
addNewPage(format,pageNo)
Add a new page before the 'pageNo'th page (ex: addNewPage(1) will add at the beginnig, while addNewPage(3) will add between the second and third page) If pageNo is set to 0 or undef, it will add at the end. The following format are supported : '4A', '2A', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', '4B', '2B', 'B0', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'LETTER', 'BROADSHEET', 'LEDGER', 'TABLOID', 'LEGAL', 'EXECUTIVE', and '36X36'. leaving it undefined will use the default 8 1/2* 11 format
changePage(pageNo)
Change the current page to 'pageNo'. If set to 0 or undef, will go at the last page.
Others Functions
Constructor: new($outPath,$inFile,$firstPageFormat)
Create the PDF::CreateSimple object. The file will be put at outPath. If inpath is defined, the new pdf will be a copy of inPath at start. If not defined, it will be a one page blank pdf file. $firstPageFormat define the format of the first page. The following format are supported : '4A', '2A', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', '4B', '2B', 'B0', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'LETTER', 'BROADSHEET', 'LEDGER', 'TABLOID', 'LEGAL', 'EXECUTIVE', and '36X36'. leaving it undefined will use the default 8 1/2* 11 format
getPDF
Return the PDF::API2 object used by the package. Do not use this unless you really know what you are doing.
setFilePath(path)
Change the file location of the pdf file to path.
getFilePath
Return the location of the pdf file
getContent(isBinary)
Return the content of the file. If isBinary is set to true, the content will be in binary format. Otherwise is ASCII format.
FONTS
The following fonts are supported by PDF::CreateSimple
"Adobe Font"
Courier
Courier-Bold
Courier-BoldOblique
Courier-Oblique
Helvetica
Helvetica-Bold
Helvetica-BoldOblique
Helvetica-Oblique
Symbol
Times-Bold
Times-BoldItalic
Times-Italic
Times-Roman
ZapfDingbats
"Windows Fonts"
Georgia
Georgia,Bold
Georgia,BoldItalic
Georgia,Italic
Verdana
Verdana,Bold
Verdana,BoldItalic
Verdana,Italic
Webdings
Wingdings
COLORS
The following colors are available in text format :
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
You can also define a color using the "#RRGGBB" notation
Other
This module is still in development phase, so comments and suggestions about new stuff to added or corrections are welcomed.
BUGS
None known yet
ACKNOWLEDGEMENTS
First of all, I would like to thank alfred reibenschuh, the author of PDF::API2. In no particular order: Philippe Cot?, author of Devel::Monitor and Julien Gervais-Bird, my boss.
AUTHOR
David Brunelle < david.brunelle@usherbrooke.ca > G?nome Qu?bec < http://www.genomequebec.com >