#!/usr/bin/perl use Text::Autoformat; use Text::ParseWords; use PDF::Create; use strict; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $pdf = new PDF::Create('filename' => "mypdf.pdf", 'PageMode' => 'UseOutlines', 'Author' => 'My Author', 'Title' => 'My Title', 'CreationDate' => [ localtime ], ); my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]); # Add a page which inherits its attributes from $root my $mpage = $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' => 'Retention Reports', 'Destination' => $mpage ); my $gif = $pdf->image("mypicture.jpg"); $mpage->image('image' => $gif, 'xpos' => 100, 'ypos' => 426, ); $mpage->stringc($f2, 40, 306, 426, "My Data For PDF"); $year = 1900 + $year; $mpage->stringc($f1, 20, 306, 396, "Final Draft $mon-$mday-$year"); # starting location my $loc = 680; my $firstpage = 0; my $partc = 0; my $recc = 0; my $retc = 0; my $citrc = 0; ## The Part below is/was for me opening a data file and dumpign the data into an array. Then I took the array and parsed the data out to print it. ## To do a new line all I had to do was subtract 14 from each $loc and then if $loc ever goes below 60.. begin a new page. ## I know most of this is kind of ugly... but hey it may help those who have the task of making a PDF on the fly. ## Sorry for the lack of comments in the code... That is one of my down falls... foreach my $cat (@catagories) { chomp $cat; $cat =~ s/&\;/&/g; ($catid, $catname) = split(/#!#/,$cat); $catid = uc$catid; $page{"$catid"} = $root->new_page; $s{"$catid"} = $toc->new_outline('Title' => "$catname"); foreach $entry (@series) { chomp $entry; $entry =~ s/&\;/&/g; my ($id, $title, $retent, $smdesc, $lngdesc, $recordcopy, $retention, $citref) = split(/\t/,$entry); my ($letter,$number) = $id =~ /(\w+?)(\d+)/; $letter = uc$letter; if ($letter eq $catid) { if ($firstpage != 1) { $page{"$catid"}->stringl($f2, 15, 36, 710, "$catname / Category $catid"); $firstpage = 1; } $page{"$catid"}->stringl($f2, 12, 36, $loc, "($number) $title"); $loc -= 14; if ($lngdesc) { $formatted = autoformat $lngdesc, { left=>0, right=>80 }; } else { $formatted = " "; } my @lng = split(/\n/,$formatted); foreach my $part (@lng) { if ($loc < 60) { $page{"$catid"} = $root->new_page; $loc = 700; } if ($partc != 1) { $page{"$catid"}->stringl($f2, 12, 36, $loc, "Explanation: "); $page{"$catid"}->stringl($f1, 12, 110, $loc, $part); $loc -= 14; $partc = 1; } else { if ($part) { $page{"$catid"}->stringl($f1, 12, 113, $loc, $part); $loc -= 14; } } } if ($recordcopy) { $formatted = autoformat $recordcopy, { left=>0, right=>80 }; } else { $formatted = " "; } my @recordcopy = split(/\n/,$formatted); foreach my $rec (@recordcopy) { chomp $rec; $rec =~ s/^\s+//g; $rec =~ s/\s+$//g; if ($loc < 60) { $page{"$catid"} = $root->new_page; $loc = 700; } if ($recc != 1) { $page{"$catid"}->stringl($f2, 12, 36, $loc, "Record Copy: "); $page{"$catid"}->stringl($f1, 12, 120, $loc, $rec); $loc -= 14; $recc = 1; } else { if ($rec) { $page{"$catid"}->stringl($f1, 12, 125, $loc, $rec); $loc -= 14; } } } if ($retention) { $formatted = autoformat $retention, { left=>0, right=>80 }; } else { $formatted = " "; } my @retention = split(/\n/,$formatted); foreach my $ret (@retention) { chomp $ret; $ret =~ s/^\s+//g; $ret =~ s/\s+$//g; if ($loc < 60) { $page{"$catid"} = $root->new_page; $loc = 700; } if ($retc != 1) { $page{"$catid"}->stringl($f2, 12, 36, $loc, "Retention: "); $page{"$catid"}->stringl($f1, 12, 100, $loc, $ret); $loc -= 14; $retc = 1; } else { if ($ret) { $page{"$catid"}->stringl($f1, 12, 105, $loc, $ret); $loc -= 14; } } } if ($citref) { $formatted = autoformat $citref, { left=>0, right=>80 }; } else { $formatted = " "; } my @citref = split(/\n/,$formatted); foreach my $citr (@citref) { chomp $citr; $citr =~ s/^\s+//g; $citr =~ s/\s+$//g; if ($loc < 60) { $page{"$catid"} = $root->new_page; $loc = 700; } if ($citrc != 1) { $page{"$catid"}->stringl($f2, 12, 36, $loc, "Citation or Reference: "); $page{"$catid"}->stringl($f1, 12, 165, $loc, $citr); $loc -= 14; $citrc = 1; } else { if ($citr) { $page{"$catid"}->stringl($f1, 12, 170, $loc, $citr); $loc -= 14; } } } $loc -= 14; if ($loc < 60) { $page{"$catid"} = $root->new_page; $loc = 700; } } $partc = 0; $recc = 0; $retc = 0; $citrc = 0; } $loc = 680; $firstpage = 0; } $pdf->close; sub parse2array { return quotewords($_[1],0,$_[0]); }