Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Perl to generate PDF

by BernieC (Pilgrim)
on Jan 09, 2020 at 16:11 UTC ( [id://11111250]=perlquestion: print w/replies, xml ) Need Help??

BernieC has asked for the wisdom of the Perl Monks concerning the following question:

I've done a search and there are a LOT of threads having to do with PDF generation, and metacpan reveals there are hundres of PDF-related modules. It is all very mindboggling, especially for someone {like me} that doesn't really understand the format of a PDF file. What I'd like to do is produce a "pretty" document. I don't care much what sort of output I produce, since almost anything can be changed into something else.

I've contemplated trying generating HTML {and there's even and HTML->PDF module :o)}, I've considered generating "rich text". It is all a bit confusing.

Any recommendations on a good place to start to try to get a handle on not too complicated to use fancy-document creation? I don't anticipate needing anything much more complicated than that I could do in HTML, and I've done that before {in CGI programs} but I was wondering if there was something with similar {or better?} capabilities. Thanks!!

Replies are listed 'Best First'.
Re: Perl to generate PDF
by duelafn (Parson) on Jan 09, 2020 at 17:16 UTC

    I typically generate LaTeX from perl and then convert that to PDF.

    Good Day,
        Dean

      LaTeX is the way to go for me also. Its composition is similar to HTML and other *MLs and can easily be automated by a program through templates. Its internal engine is a beast. It's open source and always will be. It has thousands of packages/modules for a novice to do anything, even writing ukelele sheet music. It keeps your source clear-texted, no binary, encrypted, proprietary file formats. And above all it renders the most aesthetically pleasing documents you love to not just read but stare at. Donald Knuth douz points!

Re: Perl to generate PDF
by marto (Cardinal) on Jan 09, 2020 at 17:17 UTC
      This looks like a good start. Template isn't quite right, because I'll need to do different document formats and so I'll have to bang out a new program to process the data and generate the output.

      The most interesting idea is to use LaTeX. 50 years ago I had a lot of trouble with it -- it wouldn't use normal fonts {only Knuth's metafont-based fonts} and was horribly huge and complicated to configure and such. Probably by today's standards the "huge" isn't so intractable any more and I bet that today's LaTeX can use PostScript fonts and TrueType fonts. I know that if I were facile in LaTeX it would be *easier* to generate than the corresponding HTML code for my documents, so maybe I should start by seeing if I can find my LaTeX manual. I vaguely recall I had a book called something like "The LaTeX book" but I bet that there are really much better books than that available now, but that's for me to poke at and not a perlmonks problem Thanks for all the advice!

        Whatever works for you, one program to generate different HTML per report type wouldn't be too taxing. The webkit route I suggested has had good quality results including font rendering and colours, which wasn't the case with other tools.

Re: Perl to generate PDF
by holli (Abbot) on Jan 09, 2020 at 17:49 UTC
Re: Perl to generate PDF
by CountZero (Bishop) on Jan 09, 2020 at 22:01 UTC
    If you know LaTex, that is without doubt the best way to generate good-looking PDF documents.

    I have done it time and time again by using database provided data, Template::Toolkit templates and some Perl glue.

    If you are not trying to automate making the document, just take any fairly capable wordprocessor and print the document out in PDF-format. There are a number of printer-drivers that will do that if your version of the wordprocessor cannot do it.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Perl to generate PDF
by alexander_lunev (Pilgrim) on Jan 10, 2020 at 06:43 UTC

    Just to add a method that we create documents (and PDF from them) in our system: we use LibreOffice documents as templates (which are zip files), and with HTML::Template, Archive::Zip, some Perl glue and https://github.com/unoconv/unoconv with LibreOffice (it is also work as a headless server). It is not as straightforward as with LaTeX, but it works for us - we need PDF only as option, main format for generated documents is Open Document Format, and it is a convenient to create document template in LibreOffice with variable holders like %THIS_IS_VAR% and then in our Perl glue we're replace %THIS_IS_VAR% in content.xml file inside of ODF file with HTML::Template's variables like <TMPL NAME=THIS_IS_VAR>.

Re: Perl to generate PDF
by karlgoethebier (Abbot) on Jan 09, 2020 at 20:43 UTC

    See here

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11111250]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-12-09 05:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (53 votes). Check out past polls.