Last active
December 24, 2015 01:19
-
-
Save vividsnow/6722750 to your computer and use it in GitHub Desktop.
perl html to pdf printer using gtk3 bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example usage: xvfb-run -a -s '-screen 0, 34x34x24' perl pdfshot.pl OUTFILE URL [ WAIT] | |
use v5.16; | |
use Gtk3 -init; | |
use Gtk3::WebKit; | |
(my $view = Gtk3::WebKit::WebView->new)->set_transparent(Glib::FALSE); | |
(my $window = Gtk3::OffscreenWindow->new)->add($view); | |
$view->signal_connect('notify::load-status' => sub { if ($view->get_uri && $view->get_load_status eq 'finished') { | |
Glib::Timeout->add( $ARGV[2] // 5, sub { | |
$view->get_main_frame->print_full((map { | |
$_->set_export_filename($ARGV[0]); | |
$_->set_use_full_page(Glib::TRUE); | |
$_ } Gtk3::PrintOperation->new), 'export'); | |
exit 0 } ) } } ); | |
$window->show_all; | |
$view->load_uri($ARGV[1]); | |
Gtk3->main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment