Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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.


Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

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

    Hi,

    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.

    Regards,

    |fire| at irc.freenode.net
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://481414]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2015-08-01 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls