14.2.12

PDF-CreateSimple

In the belief that Google will last longer than my computers or backups, I record this for my own info.

I have been tasked to produce a receipt, and the method proposed is for the office to feed relevant data into a web form, then advise the recipient that the receipt can be collected from a clickable link.

First problem is how to generate the PDF. I selected PDF-CreateSimple from CPAN. It requires PDF::API2 which was available as a package for this SUSE.

PDF-CreateSimple however required building, it had a faulty Makefile, but changing the paths from lib/PDF/CreateSimple.pm to ./CreateSimple.pm fixed it enought to get it installed.

Much reading, and this script produced a PDF like what is shown in the image below;

#!/usr/bin/perl

use PDF::CreateSimple;

my $pdfPath = '/home/owen/yyy.pdf';
my $pdfFile = PDF::CreateSimple->new($pdfPath);

           #--------------------------------------
           # Add a new page
           #--------------------------------------
           # $pdfFile->addNewPage;

           #--------------------------------------
           # Write Text
           #--------------------------------------

$pdfFile->drawText('Verdana 12pt ','Verdana',12,200,350,'blue');
$pdfFile->drawText('Courier 14pt ','Courier',14,200,250,'blue');
$pdfFile->drawText('Times-Italic 16pt ','Times-Italic',16,200,150,'blue');
$pdfFile->drawText('Helvetica 18pt ','Helvetica',18,200,50,'blue');

$pdfFile->drawText('12pt 500,200','Verdana',12,500,200,'black');
$pdfFile->drawText('14pt 300,200','Verdana',14,300,200,'black');
$pdfFile->drawText('16pt 100,200','Verdana',16,100,200,'black');
$pdfFile->drawText('17pt 200,100','Verdana',17,300,100,'black');
$pdfFile->drawText('18pt 300,400','Verdana',18,300,400,'black');
$pdfFile->drawText('19pt 300,500','Verdana',19,300,500,'black');
$pdfFile->drawText('20pt 300,300','Verdana',20,300,300,'black');
$pdfFile->drawText('21pt 300,700','Verdana',21,300,700,'black');
$pdfFile->drawText('42pt 300,600','Verdana',42,300,600,'black');

$pdfFile->drawLine(490,0,490,841.89,2,'black');
$pdfFile->drawRectangle(60,60,100,100,5,'blue');

$pdfFile->drawImage('/home/owen/PCUG_Logo_b.png',40,680,0.20);

$pdfFile->closeFile;

No comments: