Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How to create beautiful PDF from Pod

by Tux (Monsignor)
on Oct 26, 2012 at 13:25 UTC ( #1001077=perlquestion: print w/ replies, xml ) Need Help??
Tux has asked for the wisdom of the Perl Monks concerning the following question:

I am well aware of Pod::Pdf, but that generates PDF with horrible fonts: Times and Courier are unacceptable for me. The module and has the font-metrics builtin in the module. I do not understand how Adobe could have picked these fonts as defaults.

The module has no option(s) to choose other fonts. My font of choice would be DejaVu Sans + DejaVu Sans Mono or Kuro, but any non-serif font would be a huge improvement.

What I currently do is convert pod to html with pod2html, open that in Opera and print as pdf. The result is exactly what I want, but it is hard to imagine that I cannot do this in/with perl.

Beauty is withing the eye of the reader and thus very subjective, but companies do have standards for how their docs look like and I am very happy that Times and Courier are not in our company standards.


Enjoy, Have FUN! H.Merijn

Comment on How to create beautiful PDF from Pod
Download Code
Re: How to create beautiful PDF from Pod
by Anonymous Monk on Oct 26, 2012 at 13:47 UTC

    It might be best to make a patch or a Pod::Pdf::Fonts that takes the font as a parameter, for everyone to enjoy.

Re: How to create beautiful PDF from Pod
by tobyink (Abbot) on Oct 26, 2012 at 13:53 UTC

    I'd go with your current solution, but swap out Opera in favour of the Python xhtml2pdf library. No, you don't need to learn Python; it's bundled with a command-line script.

    Or instead of xhtml2pdf, wkhtmltopdf.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      The pyhton stuff installed but failed due to missing dependency. I didn't want to pursue that.

      The wkhtmltopdf solution works quite well. The perl module around it sucks, as it does not offer any features beyond the program itself. I would have hoped for it to support streaming (piped input, piped output), but all it does is pass the arguments to the system command. I can do that myself.

      Pod::Html shows its age. Not well thought through, sadly. Even if one uses local *STDOUT;, there is no way to get its output caught. This module also doe not support piping/streaming.

      I ended up with the code below (feel free to use, alter or comment on), where I still note a few drawbacks

      • Page wraps are unclean. On many page breaks the top half of a line is on the end of one page, the bottom half is on the next
      • CSS like text-align: justify; doesn't work very well.

      Enjoy, Have FUN! H.Merijn
        potyl's work with HTML → Webkit → Cairo → PDF is super-sweet: CPAN, Github. There's lots of example code strewn around, check every distro/repository that looks related/has the keywords in the name.

        As of 2012, this is the most modern and formidable solution.

Re: How to create beautiful PDF from Pod
by rpnoble419 (Pilgrim) on Oct 26, 2012 at 14:24 UTC
    Times and Courier were picked due to the fact they are on all PC and Mac computers. PC use Arial, Macs have Helvetica, so thats out.
Re: How to create beautiful PDF from Pod
by james2vegas (Chaplain) on Oct 26, 2012 at 14:52 UTC
Re: How to create beautiful PDF from Pod
by LanX (Canon) on Oct 27, 2012 at 00:31 UTC

      That doesn't look very assuring

      $ podchecker /pro/bin/plp /pro/bin/plp pod syntax OK. $ pod2latex -full -out plp /pro/bin/plp Unknown sequence A</td> at /pro/bin/pod2latex line 218. Unknown sequence D</a> at /pro/bin/pod2latex line 218. Unknown sequence D</a> at /pro/bin/pod2latex line 218. Unknown sequence N</a> at /pro/bin/pod2latex line 218. Unknown sequence U</a> at /pro/bin/pod2latex line 218. Unknown sequence O</a> at /pro/bin/pod2latex line 218. Unknown sequence U</a> at /pro/bin/pod2latex line 218. Unknown sequence A</a> at /pro/bin/pod2latex line 218. Unknown sequence D</a> at /pro/bin/pod2latex line 218. Escape sequence /a not recognised at line 2407 of file /pro/bin/plp Unknown sequence M</a> at /pro/bin/pod2latex line 218. ... and a lot more $ latex2man plp.tex plp.man latex2man: in line 37 Arguments of \subsection are not contained in a single line +. Remember: all arguments of a macro must be on the same line +. $ ls -l plp* -rw-rw-rw- 1 merijn users 0 Oct 28 10:57 plp.man -rw-rw-rw- 1 merijn users 44990 Oct 28 10:54 plp.tex $
      </code>

      Enjoy, Have FUN! H.Merijn
        well from what I can spot with my smartphone pod2latex is complaining about inlined html. IIRC the man for pod::latex is pretty explicitely saying that it cant handle html.

        OTOH I did a testrun yesterday combining pod2latex -full and pdflatex and it produced pdf.

        but if you really need to cover inlined html you will always need a html2pdf solution.

        Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-17 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls