Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: printing metacpan

by Tux (Canon)
on Dec 10, 2019 at 10:52 UTC ( [id://11109904]=note: print w/replies, xml ) Need Help??


in reply to Re: printing metacpan
in thread printing metacpan

THANK YOU! This fixed a lot of my headaches. I wrote html2pdf.pl with this as base, which works with files as well as with URL's:

#!/usr/bin/perl use 5.14.2; use warnings; our $VERSION = "0.01 - 20191210"; our $CMD = $0 =~ s{.*/}{}r; sub usage { my $err = shift and select STDERR; say "usage: $CMD [-p A4] [-f] [-o file.pdf] file.html"; say " -p size --page-size=size Set page size. Default = A4" +; say " -o out --out=out Set ouput file name. Default + = s{.html\$}{.pdf}"; say " -f --force Overwrite out if exists"; exit $err; } # usage use Data::Peek; use PDF::WebKit; use Getopt::Long qw(:config bundling); GetOptions ( "help|?" => sub { usage (0); }, "V|version" => sub { say "$CMD [$VERSION]"; exit 0; }, "f|force!" => \ my $opt_f, "p|page-size=s" => \(my $page_size = "A4"), "o|out|pdf=s" => \ my $pdff, "v|verbose:1" => \(my $opt_v = 0), ) or usage (1); my $html = shift or usage (1); $pdff ||= $html =~ s{\.html?$}{.pdf}ri =~ s{.*/}{}r; -s $pdff && !$opt_f and die "$pdff already exists\n"; unlink $pdff; PDF::WebKit->new ($html, page_size => $page_size)->to_file ($pdff);

Images, colors *and* fonts are correct, which I cannot say for the very broken htmldoc and html2ps tools.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: printing metacpan
by marto (Cardinal) on Dec 10, 2019 at 10:56 UTC

    Very happy this gave you a pointer to build on, and now that this can run headless it is obviously far more useful :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11109904]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-19 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found