Apache2 and Perl with modules PDF::API2 & MIME::Lite (Creating a PDF Document)

Hope someone can point me in the right Direction or help with a problem / lack of knowledge.

SuSE Linux 12.1 64bit

Apache2, Perl and the PDF::API2 & MIME::Lite modules installed.

Simplistic cgi script created so far:


use PDF::API2;
use MIME::Lite;

Create PDF Document

my $pdf = PDF::API2->new(-file => “…/htdocs/invoices/invoice.pdf”);
my $page = $pdf->page;
my $fnt = $pdf->corefont(‘Arial’,-encoding => ‘latin1’);
my $txt = $page;
$pdf->saveas (’…/htdocs/invoices/invoice-$Number.pdf’;

Mailing Data

my $from_address = ‘mai1test@otherdomainname.co.uk’;
my $to_address = ‘admin@mydomainname.co.uk’;

Adjust subject and body message

my $subject = ‘eInvoice blah’;
my $message_body = “Please find attached your invoice, blah, blah”;

Adjust the filenames

my $path = ‘…/htdocs/invoices/’;
my $attachment = ‘invoice-$Number.pdf’;

Create the multipart container

$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type =>‘multipart/mixed’
) or die "Error creating multipart container: $!

Add the text message part

$msg->attach (
Type => ‘TEXT’,
Data => $message_body
) or die "Error adding the text message part: $!

Add the PDF Document

$msg->attach (
Type => ‘application/pdf’,
Path => $path,
Filename => $attachment,
Disposition => ‘attachment’
) or die "Error adding $file_gif: $!

Send the Message


this successfully creates the pdf document and then sends it off as an attachment in an email.

At the mo i have a html webform for entering user data that is sent to a cgi script, the script formats the data does a few sums then prints to screen a html page for printing, a html email is sent to myself and to the person entering the data.

I would like to learn how to take that same data from the webform and use images to create a pdf document that can then be sent as an attachment in an email.

Can someone help or recommend a website or two where i may find more info and get help.


I assume that you have written the PHP script above with a more telling lay-out then we see. Please use the appropriate wrappers to post these sorts of things. That is CODE wrappers for “neutral” computer text anf PHP wrappers for PHP. THis is a description for CODE, but PHP is a few icons further in there: http://forums.opensuse.org/english/information-new-users/advanced-how-faq-read-only/451526-posting-code-tags-guide.html

(BTW it is openSUSE, not SuSE Linux).

hcvv wrote:
> I assume that you have written the PHP script

It isn’t PHP, it is perl, as the title says :slight_smile:

akwe-xavante wrote:
> Can someone help or recommend a website or two where i may find more
> info and get help.

This is a perl question rather than an opensuse question, so you’re
likely to get more answers on a perl site such as http://www.perlmonks.org/

e.g. http://www.perlmonks.org/?node=pdf

I appologize. Even I should be able to see of something is PHP or not :shame:

Thank you everybody for your help.

I’ll look elsewhere for help with this, at least for now i have fresh servers installed with the new OS and all related packages and modules and i’ve proved so far that the perl modules are working.

I just need to find out / learn how to use imported data and images into a respectable PDF document now, using perl and perls PDF::API2 module

That’s going to be fun, does anybody know where i can bulk buy copious amounts of Valium!?

Thank you again