Thanks for directing me to the Poppler module. I'm going to test it out. In the meantime, I don't know about putting a CairoSurface on a Canvas ( I would use Goo::Canvas), but normally it is just put in a DrawingArea. I'll let you know if I figure a way with a Canvas. You might also want to ask on the gtk-perl maillist. The archives there may have an example too.

UPDATE: changed Cairo code example to one that actually uses Poppler

#!/usr/bin/perl use Cairo; use Gtk2 '-init'; use Glib qw(TRUE FALSE); use Poppler; my $path = 'file:///home/zentara/perlplay/Gtk2/cairo/z.pdf'; my $o = Poppler::Document->new_from_file($path); # or if you want to open the pdf in perl, or use some othe source: # open (PDF, "<FILE.PDF"); # read (PDF, my $data, -s "FILE.PDF"); # close (PDF); # my $o = Poppler::Document->new_from_data($data, length($data)); my $page = $o->get_page( 0 ); my $dimension = $page->get_size; warn $dimension->get_width; warn $dimension->get_height; my ( $width, $height ) = ( $dimension->get_width, $dimension->get_heig +ht ); my $window = Gtk2::Window->new( 'toplevel' ); $window->signal_connect( 'delete_event' => sub { Gtk2->main_quit; } ); my $surface = Cairo::ImageSurface->create ('argb32', $width, $height); my $cr = Cairo::Context->create ($surface); # make a background rectangle filled white so screenshot is legible $cr->rectangle( 0, 0, $width, $height ); $cr->set_source_rgb( 1, 1, 1 ); #white $cr->fill; $page->render_to_cairo( $cr ); $cr->show_page; # make a visible widget to display the CairoSurface my $drawable = Gtk2::DrawingArea->new; $drawable->size( $width, $height ); $drawable->signal_connect( 'expose_event' => \&on_expose_event, $surface ); $window->add( $drawable ); $window->show_all; # take a screenshot $surface->write_to_png ("$0.png"); Gtk2->main; sub on_expose_event { my ( $widget, $event, $surface ) = @_; my $cr = Gtk2::Gdk::Cairo::Context->create( $widget->window ); $cr->set_source_surface( $surface, 0, 0 ); $cr->paint; $cr->show_page; return FALSE; } __END__

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

In reply to Re^3: Including a PDF in Perl/Tk by zentara
in thread Including a PDF in Perl/Tk by Joe_

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.