It's good you have solution that finally works, but we don't know what 'main_table', 'main_table2' (and 'newpage2', 'footer2'), that you keep mentioning, are about, and how they would react to empty array refs or undefined scalars ('empty variable' - what's that?).

But, looking at source of PDF::Table, passing an empty array ref, as data, to its table method is, indeed, fatal error in 0.10.0, though it wasn't so in 0.9.7. Not sure what you expect to be placed, as a table, on that 'last page', if you pass no data. I haven't used this module before, but from documentation,

my ($final_page, $number_of_pages, $final_y) = table($pdf, $page, $dat +a, %settings)

perhaps means that table fills as many pages as required, automatically.

-------

A side-note: PDF::Table's POD, and then your code, pass an '-encoding' parameter to corefont method of PDF::API2. It's not a meaningful parameter and is just ignored. Perhaps '-encode' was supposed instead, but you shouldn't use it.

Looking at source, it only makes sense if it is some single-byte encoding for a single-byte encoded font. Passing 'utf8' results in indices 129..255 in Encoding dictionary to stand for the same 'uniFFFD' name. Consider:

use strict;
use warnings;
use utf8;
use PDF::API2;

my $pdf  = PDF::API2-> new;
my $page = $pdf-> page;
my $font = $pdf-> corefont( 'Helvetica', '-encode' => 'utf8' );
my $text = $page-> text;

$text-> font( $font, 20 );
$text-> translate( 200, 700 );
$text-> text( 'рсту' );

$pdf-> saveas( 'test.pdf' );

Oops, broken PDF file with '.notdef' glyphs rendered. Just remove the '-encode' parameter, and file becomes OK.

For 'core' fonts, single-byte encoding other than 'latin1' would be useless. For arbitrary unicode texts and TTFs which support required codepoints (i.e. ttfont method is called to create a double-byte encoded font), it looks like '-encode' parameter is ignored anyway. The PDF::API2's psfont method, and PostScript Type1 custom-encoded fonts are very retro, and of historical interest only.

TL;DR -- don't use '-encode' (nor '-encoding'), its obsolete.


In reply to Re: PDF::Table last page by vr
in thread PDF::Table last page by PierreForget

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.