Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Simple Text to PDF

by tomazos (Deacon)
on Aug 06, 2005 at 01:12 UTC ( #481414=perlquestion: print w/replies, xml ) Need Help??
tomazos has asked for the wisdom of the Perl Monks concerning the following question:

I have a scalar containing a multi-paragraph sequence of English text.

I want to convert this into a PDF. I want reasonable margins and maybe page numbers if it is easy, but that's about it.

I've had a quick look through the available PDF modules and they all look like they have quite complex APIs.

Is there one out there that is something like:

my $pdf = PDF::Simple::make_pdf_from_text($text); print MYPDFFILE $pdf;

...or am I dreaming?


Andrew Tomazos  |  |

Replies are listed 'Best First'.
Re: Simple Text to PDF
by fmerges (Chaplain) on Aug 06, 2005 at 01:40 UTC


    Take a look at HTMLDOC and HTML::HTMLDoc

    For mee it was very usefull for creating a PDF output hack when the site was actually complete... this kinds of addons that get notified when all is done ;-)

    Update: here you can see what you need.


    |fire| at
Re: Simple Text to PDF
by newroz (Monk) on Aug 06, 2005 at 12:18 UTC
    Use Text-PDF-0.25 I use below code for produce pdf from a proper text file.
    #!/usr/bin/perl use Text::PDF::File; use Text::PDF::Page; use Text::PDF::Utils; # not strictly needed use Text::PDF::SFont; $/=undef; my $file1=shift; open (SUSAM,"$file1"); my $ligne=<SUSAM>; my @fischier=split(/\n/,$ligne); my $pdf = Text::PDF::File->new; $root = Text::PDF::Pages->new($pdf); $root->proc_set("PDF", "Text"); $root->bbox(0, 0, 595, 840); $page = Text::PDF::Page->new($pdf, $root); $font = Text::PDF::SFont->new($pdf, 'Helvetica', 'F0'); $root->add_font($font); $i=800; foreach(@fischier){ $page->add("BT 1 0 0 1 1 $i Tm /F0 13 Tf ('$_') Tj ET"); $i=$i-12; } $page->{' curstrm'}{'Filter'} = PDFArray(PDFName('FlateDecode')); $pdf->out_file("c.pdf");
Re: Simple Text to PDF
by tlm (Prior) on Aug 06, 2005 at 13:26 UTC

    In Unix I use something like

    % enscript -Bp - file.txt | ps2pdf - file.pdf
    If it needs to be from within perl, and quick-and-dirty is good enough, then use system with the above, and let 'er rip.

    (I've seen mentions of text2pdf and txt2pdf online, but never bothered to get either; I just made a shell function to shorten the above.)

    the lowliest monk

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://481414]
Approved by Zaxo
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-06-22 06:17 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (121 votes). Check out past polls.