Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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);

In reply to using Image Magick converted files as background for PDF's created with PDF :: API2 by Perl$Noob$

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2015-07-31 04:35 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 (274 votes), past polls