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.


In reply to Re^3: PDF, annotation method using Perl by almut
in thread PDF, annotation method using Perl by Anonymous Monk

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.