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

Update: At time of writing wkhtmltopdf did not work headless, it now does.


In reply to Re: printing metacpan by marto
in thread printing metacpan by lee_crites

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, details, 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, summary, 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.