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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.