Outputting to PDF simply?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Fellow mongers...

I've searched CPAN as well as googled for numerous pdf creator
utilities.  I've read about some of the perl modules available (i.e.:
PDF::API, PDF::Report, PDF::ReportWriter, etc).

I think all these are overkill for what I am trying to do.  Perhaps
some of you can recommend a workable solution that I can research and
hopefully incorporate.  

I have some perl programs that create business reports using the
write(format) feature (which works very well, BTW) and they are now
creating text output.  I would like to have those converted to or
output directly as PDF's so they can be more easily opened for
viewing, searching  and printing with Acrobat.

Any recommendations as to what my fill this bill with the least amount
of changes?

Thanks all for your kind and knowledgeable advice!

Re: Outputting to PDF simply?


Quoted text here. Click to load it

Run a2ps and ps2pdf on the output.

http://www.gnu.org/software/a2ps /

http://www.ghostscript.com /


(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc /

Re: Outputting to PDF simply?

On May 19, 10:34=A0am, bo...@worthless.info wrote:
Quoted text here. Click to load it

'Simple' might be in the eye of the beholder. I use PDF::API2. One of
the scripts I use it is for the creation of about 5,000 contracts five
times a year, and it does exactly what you would expect -- create
about 5,000 PDF documents, along with a cover letter and instructions.

Yes, you do have to write each line, but that's no harder than hand
writing HTML or creating a format, and it variable interpolates so you
can write templates. I've included a sample below.


-----------sample using PDF::API2--------------------
    $text->font( $font, 11/pt );

    $text->translate( 72, 580 );
    $text->text("Greetings, $fac_contract $fac_contract

    $text->font( $font, 11/pt );

    $text->translate( 72, 560);
    $text->text("The following is information for reviewing and
completing your Term $fac_contract adjunct contract. After");

    $text->translate( 72, 550);
    $text->text("you have reviewed your contract, print and sign as
Faculty Appointee. Mail it to the address listed");

    $text->translate( 72, 540);
    $text->text("below as soon as possible.");

    $text->font( $font, 12/pt );

    $text->translate( 72, 500);
    $text->text("Need to change your address, phone number?");

Re: Outputting to PDF simply?

bobm3@worthless.info wrote:
Quoted text here. Click to load it

I mostly use the approach suggested by A. Sinan Unur.

Sometimes I write Postscript directly and, if needed, convert the result
to PDF on the fly.

Sometimes I use Perl to insert generated Postscript into a Postscript

My basic approach is to use Perl to convert
   Lorem ipsum dolor sit amet
   consectetur adipisicing elit
   sed do eiusmod tempor incididunt
   (Lorem ipsum dolor sit amet) newline
   (consectetur adipisicing elit) newline
   (sed do eiusmod tempor incididunt) newline


    use strict;
    use warnings;

    my $template = $ARGV[0] || 'template.ps';
    my $psname = $ARGV[1] || 'report.ps';
    open my $in, '<', $template or die "can't open '$template' - $!";
    open my $out, '>', $psname or die "can't write '$psname' - $!";
    while (my $tline=<$in>) {
      print $out $tline;
      if ($tline =~ /insert data here/) {
        for my $dataline (<DATA>) {
            print $out "($dataline) newline\n";
    close $out;
    close $in;
    Lorem ipsum dolor sit amet
    consectetur adipisicing elit
    sed do eiusmod tempor incididunt

In the above, 'newline' is an operator I've defined in the Postscript
template: This saves most of the tedious manual calculating of x and y

   % Very basic example Postscript template, with example text data
   /inch { 72 mul } def           % Postscript's units are 1/72 inch
   /leftmargin 1 inch def
   /lineheight 1 inch 6 div def
   /newline {                     % Stack contains text
     show                         % <empty>
     leftmargin                   % 72
     currentpoint                 % 72 x y
     exch                         % 72 y x
     pop                          % 72 y
     lineheight                   % 72 y 12
     sub                          % 72 y'
     moveto                       % <empty>
   } def

   /Courier 10 selectfont
   1 inch 8 inch moveto           % origin is bottom left

   (This is a page heading) newline
   (and a subheading) newline
   () newline

   % insert data here


Then I convert the resulting Postscript file to PDF as needed.

If you know Postscript it isn't hard to extend my newline operator above
to check for bottom of page and start a new one. Google for Ben
Cranston's asciiprint.ps - it copes with multiple pages, tabs etc.

The above approach has some advantages over a2ps or enscript but, If I
don't need a complicated mixture of fonts, boxes, lines, custom page
headers etc, the latter two are what I would use if they are available.


Re: Outputting to PDF simply?

Thanks gents!

You've all given me good feedback to research and dabble with.

Much appreciated.  B

Site Timeline