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

Print to PDF

by PilotinControl (Scribe)
on Jun 11, 2013 at 18:03 UTC ( #1038301=perlquestion: print w/ replies, xml ) Need Help??
PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Good Afternoon fellow monks! My question is why do all the lines from the file print to the screen and only one line gets printed to the PDF? Code posted below:

#!/usr/bin/perl use PDF::Reuse; use strict; use warnings; printinterrr(); sub printinterrr { open(MYINPUTFILEONE, "data.txt"); $| = 1; my @linesone = <MYINPUTFILEONE>; # read file into list close (MYINPUTFILEONE); printf (" =================\n\n"); printf (" | VERIFY NAME |\n\n"); printf (" =================\n\n"); printf (" \n\n"); printf (" PLEASE INSERT NAME TO VERIFY:\n\n"); printf (" \n\n\n\n\n\n\n\n"); my $interrrverify = <STDIN>; $interrrverify = <STDIN> until defined $interrrverify; chomp($interrrverify); printf (" ========================================\n\n"); printf (" | NAME | NUMBER | TYPE | OWNER | INTER |\n\n"); printf (" ========================================\n\n\n"); my $found = 0; foreach my $interrrverify2 (@linesone) { my @fieldone = split(":", $interrrverify2); if ($fieldone[4] =~ /(?<![\w-])$interrrverify(?![\w-])/i) { my $format = " %-13s %-15s %-11s %-10s %0s\n"; printf ($format, $fieldone[0], $fieldone[1], $fieldone[2], $fieldone[3 +], $fieldone[4]); my $pageTop = 800; my $pageBottom = 40; my $x = 35; # Left margin my $y = 760; my $step = 10; # Distance between lines (fontsize = 12) prFile('data.pdf'); prCompress(1); # Compress streams prFont('Times-Roman'); prText(50, 800, "======================================="); prText(50, 790, "NAME NUMBER TYPE OWNER INTER"); prText(50, 780, "======================================="); + prText(50, $y, "$fieldone[0]"); prText((50 + 90), $y, "$fieldone[1]"); prText((50 + 195), $y, "$fieldone[2]"); prText((50 + 272), $y, "$fieldone[3]"); prText((50 + 335), $y, "$fieldone[4]"); $found =1; if ($y < $pageBottom) { prPage(); $y = $pageTop; } else { $y -= $step; } } prEnd; } # END FILE LOOP } sleep 10;

Comment on Print to PDF
Download Code
Re: Print to PDF
by poj (Priest) on Jun 11, 2013 at 19:00 UTC

    Looking at the code you have inside the loop, $y is being set to 760 for all lines.

    my $y = 760;
    poj

      Removing the $y = 760; has no effect

        With prFile('data.pdf') being within the loop, a new document is being created at every line. This is how I think it should look ;
        #!/usr/bin/perl use PDF::Reuse; use strict; use warnings; printinterrr(); sub printinterrr { open(MYINPUTFILEONE, "data.txt"); $| = 1; my @linesone = <MYINPUTFILEONE>; # read file into list close (MYINPUTFILEONE); printf (" =================\n\n"); printf (" | VERIFY NAME |\n\n"); printf (" =================\n\n"); printf (" \n\n"); printf (" PLEASE INSERT NAME TO VERIFY:\n\n"); printf (" \n\n\n\n\n\n\n\n"); my $interrrverify = <STDIN>; $interrrverify = <STDIN> until defined $interrrverify; chomp($interrrverify); printf (" ========================================\n\n"); printf (" | NAME | NUMBER | TYPE | OWNER | INTER |\n\n"); printf (" ========================================\n\n\n"); my $found = 0; my $pageTop = 800; my $pageBottom = 40; my $x = 35; # Left margin my $y = 760; my $step = 10; # Distance between lines (fontsize = 12) prFile('data.pdf'); prCompress(1); # Compress streams prFont('Times-Roman'); prText(50, 800, "======================================="); prText(50, 790, "NAME NUMBER TYPE OWNER INTER"); prText(50, 780, "======================================="); + my $format = " %-13s %-15s %-11s %-10s %0s\n"; foreach my $interrrverify2 (@linesone) { my @fieldone = split(":", $interrrverify2); if ($fieldone[4] =~ /(?<![\w-])$interrrverify(?![\w-])/i) { printf ($format, $fieldone[0], $fieldone[1], $fieldone[2], $fiel +done[3], $fieldone[4]); prText(50, $y, "$fieldone[0]"); prText((50 + 90), $y, "$fieldone[1]"); prText((50 + 195), $y, "$fieldone[2]"); prText((50 + 272), $y, "$fieldone[3]"); prText((50 + 335), $y, "$fieldone[4]"); $found =1; if ($y < $pageBottom) { prPage(); $y = $pageTop; } else { $y -= $step; } } } # END FILE LOOP prEnd; } sleep 10;
        Note the prEnd is also outside the loop.
        poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-09-18 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (120 votes), past polls