Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

printing metacpan

by lee_crites (Scribe)
on Sep 13, 2018 at 23:45 UTC ( #1222325=perlquestion: print w/replies, xml ) Need Help??
lee_crites has asked for the wisdom of the Perl Monks concerning the following question:

Printing Module Page on Metacpan

Call me old fashioned, I don't mind. However, I have a couple of reasons for wanting to print out the module docu. The old cpan.org site, when I clicked on print (I use firefox) and selected PDF, I got a reasonable docu. I could print it out and make notes on it as I went along. But there seems to be nothing I can do with the same page on metacpan.org to do the same.

I can't believe I'm the only one who prints this stuff out, so I'm betting if anyone else does, one of y'all would be that one. So, my friends, how do you pull it off? If I have to use a command-line tool to build the pdf from the installed module, that's fine with me. I'm just looking for suggestions from folks who have already perfected it.

Thanks muchly!

David Lee Crites
lee@critesclan.com
quad alii ut vivere

Replies are listed 'Best First'.
Re: printing metacpan
by salva (Abbot) on Sep 14, 2018 at 07:59 UTC
    If you are on a Unix or Linux system, and have the module installed, you can convert its documentation easily into a postscript document using man.

    For instance:

    $ man -t IO::Handle >IO::Handle.ps

    Or you can also use pod2pdf.

Re: printing metacpan
by marto (Archbishop) on Sep 14, 2018 at 11:22 UTC

    So I don't understand what your problem is regarding printing the page to PDF, but here is something really quickly thrown together to generate a PDF from the command line, I'll fix it up properly and post it in Cool Uses for Perl.

    This requires PDF::WebKit (which uses wkhtmltopdf) and Mojo::UserAgent to ensure the target module is on metacpan. wkhtmltopdf won't work headless (without patches they say), but this works reasonably well for me, as I said, I'll tidy it up later today hopefully.

    Usage: podtopdf Module::Name generates a pdf called Module-Name.pod.pdf:

    #!/usr/bin/perl use strict; use warnings; use PDF::WebKit; use Mojo::UserAgent; # Change to Letter, or whatever my $pagesize = 'A4'; # URLs for metacpan API and POD my $metacpanapi = 'https://fastapi.metacpan.org/v1/module/'; my $metacpanpod = 'https://metacpan.org/pod/'; my ($module) = @ARGV or die "no module specified: $0 Module::Name"; my $ua = Mojo::UserAgent->new(); # check metacpan for distribution my $dist = $ua->get( $metacpanapi.$module )->res->json->{distribution} or die "Can't find $module. Are you sure it exists in the CPAN?\n"; # default filename is distname.pod.pdf my $pdffilename = $dist . '.pod.pdf'; $dist =~ s/-/::/g; $metacpanpod .= $dist; # create PDF my $kit = PDF::WebKit->new( $metacpanpod, page_size => $pagesize ); my $pdf = $kit->to_pdf; # save the PDF to a file
Re: printing metacpan
by LanX (Bishop) on Sep 13, 2018 at 23:57 UTC
    The print preview in Firefox really looks messy, but once I clicked on "Simplify Page"* it looks reasonable .

    If not ...

    You probably want to design your own @media:print css and perhaps even contribute to the metacpan project on git-hub.

    HTH! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    *) or whatever it's called, in my German version it's "Seite vereinfachen".

    PS: yes there are command line tools like pod2html or pod2pdf, but I don't see the point if you prefer browsing metacpan anyway.

      Sorry, I just realized that "Simplify Page" is only available on windows, which is weird.

      Most of the mess comes from the upper left navigation pane, since browsers are trying to expand some links to the underlying URL in the print.

      Since the links are often very long and not easily broken into another line, they are overlaying the actual POD.

      this is caused by this CSS setting

      @media print { // ... a[href]:after { content: " (" attr(href) ")"; } //..

      As already said changing the media CSS (like hiding navigation) would solve your issues either locally by amending Firefox settings or by providing a patch here

      https://github.com/metacpan/metacpan-web/issues

      edit

      especially https://github.com/metacpan/metacpan-web/issues/1786

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Sorry, I just realized that "Simplify Page" is only available on windows, which is weird.

        I never use MSWin32 and my Firefox 62.0 on Linux has "Simplify Page". Using it works well on MetaCPAN pages. HTH.

Re: printing metacpan
by Anonymous Monk on Sep 14, 2018 at 01:23 UTC
    You should be able to print to pdf from metacpan with firefox. If not there's a problem with your firefox or os. The issue with meta is no clean stylesheet for printing so there's irrelevant site navigation at the top and a pile of spam at the bottom of the document.

    Also note that perldoc.perl.org provides pdf for core documentation.

    This command line tool let's you type something like "perlpdf" instead of "perldoc":

    perlpdf for perldoc as PDF

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-11-12 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (142 votes). Check out past polls.

    Notices?