in reply to PDF::API2::Simple - pass parameter to header

Please show some relevant code - without it, it's quite hard where you try to pass parameters to the callback. I think that PDF::API2::Simple calls your callback, so if you want to have additional information in your callback, you will have to store that information in your callback before it gets called.

  • Comment on Re: PDF::API2::Simple - pass parameter to header

Replies are listed 'Best First'.
Re^2: PDF::API2::Simple - pass parameter to header
by constantin.iliescu (Initiate) on Mar 11, 2010 at 15:33 UTC
    Thanks, Corion! I define the pdf object like this:
    my $pdf = PDF::API2::Simple->new( header => \&header, footer =>\&footer, margin_left => 15, margin_top => 15, margin_right => 15, margin_bottom => 45 );
    and I want to pass a string parameter, which will appear in my header, depending on page.

      I'm not sure whether your callback ever gets passed the current page number. The best is to wrap the header subroutine with your own header:

      sub my_header { # ... do your own stuff: print "Got parameters @_\n"; # Call old header routine to output other stuff header(); }; my $pdf = PDF::API2::Simple->new( header => \&my_header, footer =>\&footer, margin_left => 15, margin_top => 15, margin_right => 15, margin_bottom => 45 );
        Still can't pass the parameter. I'm trying this:
        my $pdf = PDF::API2::Simple->new( header => \&my_header($CategoryName), footer => \&footer, margin_left => 15, margin_top => 15, margin_right => 15, margin_bottom => 45 ); sub my_header { my $pdf = shift; my $cat = shift; print $cat; header($pdf); } sub header { my $pdf = shift; # do my stuff }
        Erorr: Not a CODE reference at...