Home |
Blog |
( 2 ) |
Subscribe
Disclosure: This post may contain affiliate links which may earn us a commission when you click on them.
Posted by
Felix Okoli on Monday September 6, 2010 at 11:51:38:
I was searching for a Perl script that would allow me to simply create pdpf online once I enter some variables. I was able to come up with a script like this that allows me to create a Hello world file with the text "Hello World" from http://oreilly.com/pub/h/2429:
#!/usr/bin/perl
# HelloWorld.pl; adapted from 0x_test-pl
use PDF::API2;
my $pdf = PDF::API2->new(-file => "HelloWorld.pdf");
$pdf->mediabox(595,842);
my $page = $pdf->page;
my $fnt = $pdf->corefont('Arial',-encode => 'latin1');
my $txt = $page->hybrid;
$txt->textstart;
$txt->font($fnt, 20);
$txt->translate(100,800);
$txt->text("Hello World! left-aligned");
$txt->translate(500,750);
$txt->text_right("Hello World! right-aligned");
$txt->translate(300,700);
$txt->text_center("Hello World! center-aligned");
$txt->textend;
$pdf->save;
$pdf->end( );
Since PDF::API2 was not yet installed on my Bluehost hosting account, I had to search and install the module and took quite some time to do so before respondin that the install had been don. Now i run the perl scrip after choding the values to 0755 but it gives error and I think the path to perl was incorrect. Since I had run into this problem before, I now looked for a way to auto-insert the path to the new installed perl module since usr/bin/perl would not do. So I went back to Perl modules under Cpanel:
BEGIN {
my $base_module_dir = (-d '/home1/multidox/perl' ? '/home1/multidox/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, map { $base_module_dir . $_ } @INC;
}
I have added the correct path to the perl module and it works partially but still gives and error:
Can't locate object method "hybrid" via package "PDF::API2::Page" at createpdf.pl line 18.
I would still work on it at my spare time
Comments:
Re: Using Perl to create pdf online
Posted by scott
on Thursday December 15, 2011 at 17:24:59:
Late response, but I found this post first when I had the same problem. Using the more simple definition solved it for me:
$txt = $page->text()