constantin.iliescu has asked for the wisdom of the Perl Monks concerning the following question:

Hi, monks! Can somebody tell me how can I pass a parameter to the header function when creating PDFs with PDF::API2:Simple? It's problably basic perl, but I can't find any solution. Thanks!
  • Comment on PDF::API2::Simple - pass parameter to header

Replies are listed 'Best First'.
Re: PDF::API2::Simple - pass parameter to header
by Corion (Patriarch) on Mar 11, 2010 at 09:19 UTC

    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.

      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 );