Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

using Image Magick converted files as background for PDF's created with PDF :: API2

by Perl$Noob$ (Initiate)
on Apr 03, 2013 at 14:26 UTC ( #1026865=perlquestion: print w/ replies, xml ) Need Help??
Perl$Noob$ has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

i am an absolute begginer in perl and i was hoping to get your help with this pickle i have found my self in. i have first converted a file using Image Magick from PDF to jpg using the following function:

sub PDFtoIMAGE { foreach my $a (keys %dir) { my $file = $a; printf "$file\n"; if($file=~/\.pdf/ || $file=~/\.PDF/) { my $Img = Image::Magick->new; $Img->Set(density => '300'); print "reading: $file\n"; $Img->read("$path$file"); my ($width, $height, $size, $format)=$Img->Ping("$path$file"); print "$width, $height, $size, $format\n"; $Img->Extent(width=>$width,height=>$height); $file=~s/\.pdf/\.jpg/; $file=~s/\.PDF/\.jpg/; print "creating: $file\n"; $Img->Write("png24:$path$file"); print "created: $file\n"; } } }

the image file which i have created i am now trying to pass as the input image to the below piece of code. but when i run the code, i get this error: "cant call method val on an undefined value /../Image.pm line 66" my converted image is located at the same place i am runing my scripts from and other jpg images which i have used are handled with no problem... please help.

#!/usr/bin/perl use PDF::API2; $InFile = $ARGV[0]; $InImage = $ARGV[1]; $OutFile = $ARGV[2]; #$InFile = $Global_ImageFile; my ($aLine); my($count); ######################### sub escape ######################### { local ( $text ) = @_; $text =~ s/\014//g; $text =~ s/\015//g; $text =~ s/\133\133B\135\135//g; $text =~ s/\133\133\057B\135\135//g; $text =~ s/\133\133U\135\135//g; $text =~ s/\133\133\057U\135\135//g; $text =~ s/\133\133BU\135\135/<B><U>/g; $text =~ s/\133\133\057BU\135\135/<\/U><\/B>/g; #$text =~ s/\050/\134\050/g; $text =~ s/\133\133O\061\067\135\135//g; $text =~ s/\133\133O\061\062\135//g; #$text =~ s/\051/\134\051/g; $text =~ s/\115\105\123\123\105\122\123\072//g; $text =~ s/&#1491;&#1493;&#1489;&#1499;&#1500;//g; return $text; } $pdf = PDF::API2->new(); $page = $pdf->page; print "$InImage\n"; $img = $pdf->image_jpeg($InImage) or die "Couldn't add '$InImage' as a + file."; $gfx = $page->gfx; $font = $pdf->corefont('Helvetica', -encoding => 'latin1'); $pagelines = 1; $MaxHeight=900; $TopPage=$MaxHeight ; $page ->mediabox( 'A4'); $gfx->image( $img,-15, -25, 0.25); open (InFile,$InFile); while ($fLine = <InFile>) { $aLine = $fLine; #chomp $aLine; #$pos = index($aLine,"\014"); $aLine = &escape( $aLine ); $pagelines++; $text = $page->text; $text->font($font, 10); $tmp_page=$TopPage - $pagelines*13; $text->translate(0, $tmp_page); $text->text($aLine); ### file load ### if(!(($count % 2)==0 )) { printf("$count\n"); } $count++; ######################## }; close (InFile); $pdf->saveas($OutFile);

Comment on using Image Magick converted files as background for PDF's created with PDF :: API2
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1026865]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2015-07-06 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (81 votes), past polls