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

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

Replies are listed 'Best First'.
Re^4: Including a PDF in Perl/Tk
by Joe_ (Beadle) on Jun 26, 2012 at 19:15 UTC

    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...