Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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 sample.pl 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 +.com>'); $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!

TIA

peppiv

"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 Create.pm 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.

      peppiv

        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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://248905]
Approved by Corion
help
Chatterbox?
[shmem]: that's why it is called "Windows"
[stevieb]: shmem thanks for the 'insight' :P
[shmem]: good thing that Sun already took "OpenWindows", otherwise I'd not stop to shudder imagining an "OpenWindows" from MS
[shmem]: more garbage in, more garbage out that would be
[stevieb]: I found that win10 broke a C# library I was using for one project while enhancing tests for a Perl dist, which breaks other Perl dists, and I'm about to throw my hands up on berrybrew. win2k12 broke one thing, win10 breaks something...
[stevieb]: ...unrelated which requires replacing a lot of code and a whole lib. I'm about to go nix only ffs
[shmem]: stevieb: what you're doing sounds afwully complex. Too much for me this evening to provide brighter insight ;-)
[stevieb]: I don't even own a Windows computer. Both my girl and I have a laptop each with Linux. I'm supporting Windows in some of my projects and I can't even guage whether it's worth it or not.
[stevieb]: shmem It's something I desired to have years ago, which is why I took over berrybrew. Cross-platform build/test automation locally, or over the network Test::BrewBuild

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-03-28 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (342 votes). Check out past polls.