Help language development. Donate to The Perl Foundation

PDF::Class zef:dwarring last updated on 2023-08-20

use v6;
use Test;
use PDF::Class;
use PDF::Page;

my PDF::Class $pdf .= open('t/update.pdf');
my $new-page = $pdf.Pages.add-page;
$new-page.gfx.say( 'New Last Page!!' );

# ensure consistant document ID generation
my $id = $*PROGRAM-NAME.fmt('%-16.16s');

$ = $id++;
ok $pdf.update(:!info), 'update';

$pdf .= open('t/update.pdf');
is $, 2, 'pdf now has two pages';

$ = $id++;
ok $'tmp/update-resaved.json', :!info), 'save-as json';

$pdf .= open('tmp/update-resaved.json');
ok $pdf<Info><Author>.ends-with("helloworld.t"), '$pdf<Info><Author>';
ok my PDF::Page $p2 = $, 'pdf reload from json';

my PDF::Page $p2-again;
lives-ok {$p2-again = $pdf.delete-page(2)}, 'delete-page lives';
ok $p2 === $p2-again, 'deleted page returned';
is $, 1, 'pages after deletion';