Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

PDF::Create Questions

by peppiv (Curate)
on Apr 08, 2003 at 12:30 UTC ( #248905=perlquestion: print w/replies, xml ) Need Help??

peppiv has asked for the wisdom of the Perl Monks concerning the following question:

Good day,

I just started using PDF::Create and it works very well. I do have two particular needs that I can't figure out from the documentation or anywhere else I've looked. I can create a .pdf document very easily. What I'd like to do is write over the same file.

Let me explain. Using an applicant tracking system I built (all in Perl and on our Intranet) I'd like to have the ability to print out a summary of an application for the individuals to sign so we can have it on file. Since we've got all the information stored in the DB, we shouldn't have to save a .pdf for each candidate. I'd rather create one on the fly and print it and be done with it. Then when I come to the next candidate, just overwrite the existing .pdf and print. Here's the code from the that comes with the Module:

#!/usr/bin/perl -w BEGIN { unshift @INC, "lib", "../lib" } use strict; use PDF::Create; my $pdf = new PDF::Create('filename' => '/html/mypdf.pdf', 'Version' => 1.2, 'PageMode' => 'UseNone', 'Author' => 'Ovaltine', 'Title' => 'Anything', ); my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]); # Add a page which inherits its attributes from $root my $page = $root->new_page; # Prepare 2 fonts my $f1 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica'); my $f2 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica-Bold'); # Prepare a Table of Content my $toc = $pdf->new_outline('Title' => 'Document', 'Destination' => $page); $page->stringc($f2, 40, 306, 626, "PDF::Create 2"); $page->stringc($f1, 20, 306, 596, "version $PDF::Create::VERSION") +; # Add another page my $page2 = $root->new_page; $page2->stringc($f1, 20, 306, 400, 'Let us see what is on page 2.' +); $page2->line(40, 40, 572, 40); $page2->line(40, 752, 572, 752); # Add something to the first page $page->stringc($f1, 20, 306, 400, 'by Ovaltine <bellybuster@thebar>'); $page->stringc($f1, 15, 306, 350, 'More text for the reading.'); # Add the missing PDF objects and a the footer then close the file $pdf->close;

My only idea so far is to have Perl delete the file before it creates on (of the same name). Any ideas?

Also, I've learned how to draw lines (thanks to the example) but I can't figure out how to draw rectangles and shaded boxes. I haven't been able to find a good example to build from. The docs give the verbage but I can't seem to get anywhere. Help!



"flying blind on a rocket cycle!"

Replies are listed 'Best First'.
Re: PDF::Create Questions
by tall_man (Parson) on Apr 08, 2003 at 13:26 UTC
    In the PDF::Create constructor code, I find the following line:
    my $fh = new FileHandle "> $self->{'filename'}";
    It means that the file will be overwritten automatically, (provided you have write permission to the old file).

    The pod for contains a command to add a rectangle to the path. Then you can either stroke or fill that path. For example:

    $page2->rectangle(0,0,40,60); $page2->stroke();
    Update: improved rectangle example.
      Thank for the help. The rectangle works like a charm. It's a shame you couldn't shade with the fill command. That would rock.

      In the FileHandle example (your code explains more than the docs) how do I declare $self? Would this line come after the Create line? Sorry for all the questions.


        You don't have to declare $self. I just clipped out a line from the PDF::Create "new" function to show you that it opens the file with a '>' in front of the name, which means that it will overwrite the old file automatically. There's no extra code you have to put in.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-05-18 08:29 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (176 votes). Check out past polls.