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

Gurus: What is the standard module to convert a text file into a PDF file? Or, is there something that is already packaged in Active State Perl? Thanks.

Replies are listed 'Best First'.
Re: Text to PDF
by leighsharpe (Monk) on Jan 28, 2010 at 22:06 UTC

    PDF::API2 is packaged by Active State.

    This works :
    use strict; use warnings; use PDF::API2; # Create a pdf object. my $pdf = PDF::API2->new(-file => "test.pdf"); # Create a media box in pdf object. $pdf->mediabox(595,842); # Create font objects. my $fnt = $pdf->corefont('Verdana',-encode => 'latin1'); my $boldfont=$pdf->corefont('Verdana-Bold',-encode => 'latin1'); # Set the font size. my $font_size=8; # Create a page object. my $page = $pdf->page(0); # Create a text object on the page. my $txt = $page->text; $txt->font($boldfont,$font_size); $txt->translate(20,800); $txt->text("A Heading here."); $txt->font($fnt, $font_size); $txt->translate(100,750); $txt->font($fnt, $font_size); $txt->text("A small piece of text here."); # Read a large piece of text from a file and put it in a paragraph on +the PDF document. open(FH, "<largetext.txt") or die "$!\n"; my @fred=<FH>; close FH; $txt->paragraph(join("\n", @fred), -x=>30, -y=>720, -w=>500, -h=>800); # Save the PDF and destroy the object. $pdf->save; $pdf->end( );
    ...but it has a few problems. It requires that you know (or calculate) the size of the paragraph, and it seems to ignore some formatting, such as multiple spaces and newlines. It also requires that you put your own page breaks in. With a bit of work, it could be made to do what you want.
      I'll check it out. Thanks for the info, Dave
Re: Text to PDF
by molecules (Monk) on Jan 28, 2010 at 19:29 UTC

    I don't know about a "standard module" but here a few tools I ran across by typing "Text PDF perl" in Google:

    a2pdf
    txt2pdf

    By the way, searching for "Text to PDF" Perl gave me your question as hit number 6.

      Thanks, I guess I could have done that. I know there are many different modules to implement. But, I like to know what everyone else is using in production. Hope this help narrow down what I'm looking for.
Re: Text to PDF
by holli (Abbot) on Jan 29, 2010 at 22:39 UTC