in reply to Re^2: PDF, annotation method using Perl
in thread PDF, annotation method using Perl
it will generate an error
What is the error? It works for me (if I uncomment the respective lines), i.e. it creates an annotation link to www.somewhere.com at the specified position on page 2.
OTOH, as I'm reading your ...have the first column "Content 1" to be a link, you would like to have every cell of column 1 be a link to some URL (not just one link per page). Unfortunately, PDF::Table does not make this easy. What you would want is a configurable callback/hook function that's being called when a cell is rendered, so you can easily get at its current coordinates, etc. As it is, there is no such thing... But you could patch PDF/Table.pm like this
} # line 615 ### insert this if (ref $arg{cell_render_hook} eq 'CODE') { $arg{cell_render_hook}->( $page, $rows_counter, $j, $cur_x, $cur_y-$row_h, $calc_column_widths->[$j], $row_h ); } ### $cur_x += $calc_column_widths->[$j]; # orig. line 616 }#End of for(my $j.... # orig. line 617
This would add a new option 'cell_render_hook', which you set to a function that gets called whenever a cell has been rendered. The function is being passed the following arguments:
page-obj, row-index, column-index, x, y, width, height
Your code would then look something like this:
use strict; use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "table-1.pdf"); $pdf->preferences( -thumbs => 1, ); sub newpage { my $page = $pdf->page; $page->mediabox(792,612); return $page; } my $page = newpage(); # some data to layout my $some_data =[ # same data as in your code... (not duplicated for brevity) ]; # build the table layout $pdftable->table( # required params $pdf, $page, $some_data, x => 70, w => 650, start_y => 550, next_y => 550, start_h => 500, next_h => 500, # some optional params padding => 5, padding_right => 10, background_color_odd => "gray", background_color_even => "lightblue", #cell background color for e +ven rows new_page_func => \&newpage, # as defined above cell_render_hook => sub { # this is our newly introduced callba +ck function my ($page, $row, $col, $x, $y, $w, $h) = @_; if ($col == 0) { # do nothing except for first column my $url = "http://www.somewhere.com/my.php?row=$row"; my $annot = $page->annotation(); $annot->url( $url, -rect => [$x, $y, $x+$w, $y+$h], -border => [1,1,1] ); } }, ), # do other stuff with $pdf $pdf->saveas();
which would produce this PDF.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: PDF, annotation method using Perl
by Anonymous Monk on Apr 02, 2009 at 12:27 UTC | |
by almut (Canon) on Apr 02, 2009 at 12:34 UTC | |
by Anonymous Monk on Apr 02, 2009 at 14:05 UTC | |
by almut (Canon) on Apr 02, 2009 at 14:30 UTC | |
by Anonymous Monk on Apr 02, 2009 at 15:17 UTC | |
by Anonymous Monk on Apr 02, 2009 at 18:25 UTC |