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

Hello all Monks.

I have a script to generate a formatted report using the write function that sends the output to the screen.

Is there a way I can save it to a PDF file?

Thanks much...

Replies are listed 'Best First'.
Re: Write To PDF File
by frozenwithjoy (Priest) on Jun 28, 2012 at 19:57 UTC
    I'm not aware of a way to use write to output in pdf format. Maybe take a look at PDF::API2 or PDF::Create.

      Thanks FrozenWithJoy for your reply...

      I did look at that module and it seems to require you to save the report into a text file first, then read that text file and write to a pdf.

      Just wondering if there's a direct way to print to a pdf file.

        I wrote a quick script based on the documentation from PDF::API2 and it works fine without using an intermediate file:

        #!/usr/bin/env perl use strict; use warnings; use PDF::API2; # Create a blank PDF file my $pdf = PDF::API2->new(); # Add a blank page my $page = $pdf->page(); # Set the page size $page->mediabox('Letter'); # Add a built-in font to the PDF my $font = $pdf->corefont('Helvetica-Bold'); # Add some text to the page my $text = $page->text(); $text->font($font, 20); $text->translate(200, 700); $text->text('Hello World!'); # Save the PDF $pdf->saveas('new.pdf');
        A reply falls below the community's threshold of quality. You may see it by logging in.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Write To PDF File
by kcott (Archbishop) on Jun 29, 2012 at 17:04 UTC

    You might find PDF::API2::Simple to be a gentler introduction to PDF coding.

    In the past, I've found it quite adequate for the type of task you're describing; however, as this module subclasses PDF::API2, you have access to the full-blown interface should you require it.

    -- Ken

      Hi Ken

      I tried installing that package:

      ppm-shell

      install PDF::API2::Simple

      but it said "Can't find any package that provides PDF::API2::Simple.