Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Including a PDF in Perl/Tk

by Joe_ (Beadle)
on Jun 26, 2012 at 10:38 UTC ( [id://978383]=note: print w/replies, xml ) Need Help??


in reply to Re: Including a PDF in Perl/Tk
in thread Including a PDF in Perl/Tk

Forking xpdf or okular from within Tk seems a better option for me. Can you please offer me hints (or point me to the proper documentation) on how I can do this? Or maybe I misunderstood and you actually mean opening an xpdf window independent of Perl altogether? This obviously won't work because I want it to be tied to my GUI.

Replies are listed 'Best First'.
Re^3: Including a PDF in Perl/Tk
by zentara (Archbishop) on Jun 26, 2012 at 11:26 UTC
    Well, this fork is still controlled by Tk, in that you can open and kill it, so it is still tied to the GUI. This example is as simple as they come, and there may be other pdf viewers which allow you to open them with a piped open, allowing you to send load and control signals to their STDIN, but I havn't found one like that yet. Probably a Poppler based viewer would be needed for that. However, this method, shown below, would be quite usable. You could make thumbnails of your pdf's as I described earlier, then have click blindings on each thumbnail to open that pdf with xpdf. Xpdf works quite well from my experience. You could even open multiple pdf's simultaneously with this method, by storing filenames and pids in a hash, but I will leave that complexity to you. :-)
    #!/usr/bin/perl -w use Tk; use strict; use Proc::Killfam; my $mw = MainWindow->new; my $pid; # global for killing viewer my $pdf = 'z.pdf'; my $button = $mw->Button(-text => 'Open PDF Viewer', -command => [\&xpdf_test, $pdf] )->pack; my $button1 = $mw->Button(-text => 'Close PDF Viewer', -command => \&xpdf_close )->pack; MainLoop(); sub xpdf_test { my $pdf = shift; $pid = fork; if ( $pid < 0 ) { die "Fork failed: $!\n" } elsif ( $pid == 0 ) { # forked code system ("xpdf -g '400x500+100+100' $pdf"); } } sub xpdf_close{ killfam 9, $pid; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Thanks. I get the idea. It's not exactly what I wanted, but it's a useful trick nonetheless. I guess the best thing about it is that it can work with any application, not just PDF viewers...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-18 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found