Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: convert text file to pdf with PDF::Create

by almut (Canon)
on Apr 06, 2009 at 17:15 UTC ( #755800=note: print w/replies, xml ) Need Help??


in reply to convert text file to pdf with PDF::Create

Here's a simple example, essentially using printnl() to put the lines of your text on the page without any kind of advanced layouting:

#!/usr/bin/perl use strict; use warnings; use PDF::Create; my $text = <<'EOT'; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliqui +p ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. EOT my $pdf = new PDF::Create('filename' => 'mydoc.pdf', 'Title' => 'Simple Demo', ); my $root = $pdf->new_page('MediaBox' => $pdf->get_page_size('A4')); my $font = $pdf->font(); # using defaults my $page = $root->new_page(); $page->printnl($text, $font, 14, 50, 750); # text, font, size, x, y $pdf->close;

For anything non-trivial, though, I'd personally use LaTeX (there exists a variant which directly outputs PDF), in which case you'd have to markup your text (paragraphs, headlines, etc.), and specify the style (column widths, fonts, etc.) using a well-established syntax. LaTeX would then do the layouting in a much more professional way than you could code with PDF::Create in the same time it takes to write the markup... (although there's of course a learning curve, if you're using it for the first time).  But it all depends on what exactly you want to achieve.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-11-25 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?