Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Gtk2::PrintOperation problem

by mst3000 (Novice)
on Jan 26, 2012 at 06:30 UTC ( #950029=perlquestion: print w/replies, xml ) Need Help??
mst3000 has asked for the wisdom of the Perl Monks concerning the following question:

Hopefully one of the Monks can help with this one...I'm under a deadline and can't get this working properly at all.

I found this code somewhere online (tried to find it in my history but I'm frazzled and can't find it right now)

#!/usr/bin/perl use strict; use warnings; use Glib qw(TRUE FALSE); use Gtk2 -init; use Gtk2::MozEmbed; Gtk2::MozEmbed -> set_profile_path($ENV{ HOME } . "/.mybrowser", "MyBrowser"); my $moz = Gtk2::MozEmbed -> new(); $moz -> load_url("file:///root/gtk/test.html"); my $window = Gtk2::Window -> new(); $window -> signal_connect( delete_event => sub { Gtk2 -> main_quit; return FALSE; }); $window -> set_title("MyBrowser"); $window -> set_default_size(600, 400); $window -> add($moz); $window -> show_all(); my $op = Gtk2::PrintOperation->new; $moz->signal_connect( net_stop => sub { print "Document start\n"; print "Create a PDF ...\n"; $op->set_export_filename ("test.pdf"); $op -> set_allow_async(FALSE); $op->run ("export", $window); }); $op->signal_connect( status_changed => sub{ print "status changé en " . $op->get_status . "\n"; if ($op->is_finished ){ print "PDF Done\n"; } }); Gtk2 -> main; loads up the html file PERFECTLY. However, afterwards, the program begins churning out a PDF file that will fill the disk. Looking at the PDF file in a text editor, it's just blank page after blank page.

After doing some troubleshooting, I realized that if I do $op->run('export',undef); this results in exactly the same thing.

However, $window is definitely assigned. So, what is the problem with this? Google has been no help whatsoever, as I can find next to nothing usable concerning Gtk's PrintOperation

Any help would be VERY appreciated!!

Replies are listed 'Best First'.
Re: Gtk2::PrintOperation problem
by sam_bakki (Pilgrim) on Jan 28, 2012 at 13:05 UTC


    I also great fan of perl GTK2. But the perl Gtk2's documentation is not complete and not good to refer.

    Since, perl gtk2 maintains the APIs as close to its underlaying C APIs, we can just refer the PyGtk's documentation, which is really good and complete. Once you know about the API, you can then write it in perl

    Coming to your issue, try use, ,

     'GTK_PRINT_OPERATION_ACTION_EXPORT' instead of export

    you can read some info about this printoperation class here +kprintoperation--run +_Gtk2_PrintOpera

    i dont not have printer to try myself, I will try this code and update you.

    -Bakki - A perl Gtk2 project

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://950029]
Approved by Corion
Front-paged by Corion
and the leaves swirl about...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2017-09-23 17:36 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (273 votes). Check out past polls.