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;
}
| [reply] [d/l] |
| [reply] |