Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: convert text file to pdf with PDF::Create by almut
in thread convert text file to pdf with PDF::Create by dmbrooking

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2020-12-03 16:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (57 votes). Check out past polls.

      Notices?