#!/usr/bin/perl use 5.032; use warnings; use strict; use PDF::API2; use Test::More tests => 2; my ($stringy_bare_pdf, $stringy_outline_pdf); BARE_PDF: { my $pdf = PDF::API2->new(-compress => 0); my $page1 = $pdf->page(); $stringy_bare_pdf = $pdf->to_string(); } OUTLINE: { my $pdf = PDF::API2->new(-compress => 0); my $page1 = $pdf->page(); my $outlines = $pdf->outlines(); my $outline = $outlines->outline(); $outline->title('Test Outline 1'); $outline->dest(1); $stringy_outline_pdf = $pdf->to_string(); } DELETE_OUTLINE: { my $pdf = PDF::API2->from_string($stringy_outline_pdf, -compress => 0) or die $!; my $root = $pdf->outlines(); my $outline = $root->outline(); $outline->delete(); is($pdf->to_string(), $stringy_bare_pdf, 'Make sure the outline actually got deleted from the PDF'); } MODIFY_OUTLINE: { my $pdf = PDF::API2->from_string($stringy_outline_pdf, -compress => 0) or die $!; my $root = $pdf->outlines(); my $outline = $root->outline(); $outline->title('Test Outline 2'); $outline->dest(1); is($pdf->to_string(), $stringy_outline_pdf, 'Make sure the outline text actually got changed in the PDF'); } done_testing(); #### perl pdf_test.pl 1..2 not ok 1 - Make sure the outline actually got deleted from the PDF # Failed test 'Make sure the outline actually got deleted from the PDF' # at pdf_test.pl line 36. # got: '%PDF-1.4 # %╞══╡ # 1 0 obj << /Type /Catalog /Outlines 6 0 R /PageMode /SinglePage /Pages 2 0 R /ViewerPreferences << /NonFullScreenPageMode /UseNone >> >> endobj # 2 0 obj << /Type /Pages /Count 1 /Kids [ 5 0 R ] /Resources 3 0 R >> endobj # 3 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> endobj # 4 0 obj << /Producer (PDF::API2 2.043 \(MSWin32\)) >> endobj # 5 0 obj << /Type /Page /Parent 2 0 R /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> >> endobj # 6 0 obj << /Type /Outlines /Count 1 /First 7 0 R /Last 7 0 R >> endobj # 7 0 obj << /Dest (1) /Parent 6 0 R /Title (Test Outline 1) >> endobj # xref # 0 8 # 0000000000 65535 f # 0000000015 00000 n # 0000000159 00000 n # 0000000235 00000 n # 0000000304 00000 n # 0000000365 00000 n # 0000000477 00000 n # 0000000548 00000 n # trailer # << /Info 4 0 R /Root 1 0 R /Size 8 >> # startxref # 617 # %%EOF # 9 0 obj << /Parent 6 0 R >> endobj # xref # 0 1 # 0000000000 65535 f # 9 1 # 0000000852 00000 n # trailer # << /Info 4 0 R /Prev 617 /Root 1 0 R /Size 10 >> # startxref # 887 # %%EOF # ' # expected: '%PDF-1.4 # %╞══╡ # 1 0 obj << /Type /Catalog /PageMode /SinglePage /Pages 2 0 R /ViewerPreferences << /NonFullScreenPageMode /UseNone >> >> endobj # 2 0 obj << /Type /Pages /Count 1 /Kids [ 5 0 R ] /Resources 3 0 R >> endobj # 3 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> endobj # 4 0 obj << /Producer (PDF::API2 2.043 \(MSWin32\)) >> endobj # 5 0 obj << /Type /Page /Parent 2 0 R /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> >> endobj # xref # 0 6 # 0000000000 65535 f # 0000000015 00000 n # 0000000143 00000 n # 0000000219 00000 n # 0000000288 00000 n # 0000000349 00000 n # trailer # << /Info 4 0 R /Root 1 0 R /Size 6 >> # startxref # 461 # %%EOF # ' not ok 2 - Make sure the outline text actually got changed in the PDF # Failed test 'Make sure the outline text actually got changed in the PDF' # at pdf_test.pl line 47. # got: '%PDF-1.4 # %╞══╡ # 1 0 obj << /Type /Catalog /Outlines 6 0 R /PageMode /SinglePage /Pages 2 0 R /ViewerPreferences << /NonFullScreenPageMode /UseNone >> >> endobj # 2 0 obj << /Type /Pages /Count 1 /Kids [ 5 0 R ] /Resources 3 0 R >> endobj # 3 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> endobj # 4 0 obj << /Producer (PDF::API2 2.043 \(MSWin32\)) >> endobj # 5 0 obj << /Type /Page /Parent 2 0 R /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> >> endobj # 6 0 obj << /Type /Outlines /Count 1 /First 7 0 R /Last 7 0 R >> endobj # 7 0 obj << /Dest (1) /Parent 6 0 R /Title (Test Outline 1) >> endobj # xref # 0 8 # 0000000000 65535 f # 0000000015 00000 n # 0000000159 00000 n # 0000000235 00000 n # 0000000304 00000 n # 0000000365 00000 n # 0000000477 00000 n # 0000000548 00000 n # trailer # << /Info 4 0 R /Root 1 0 R /Size 8 >> # startxref # 617 # %%EOF # 9 0 obj << /Dest (1) /Parent 6 0 R /Title (Test Outline 2) >> endobj # xref # 0 1 # 0000000000 65535 f # 9 1 # 0000000852 00000 n # trailer # << /Info 4 0 R /Prev 617 /Root 1 0 R /Size 10 >> # startxref # 921 # %%EOF # ' # expected: '%PDF-1.4 # %╞══╡ # 1 0 obj << /Type /Catalog /Outlines 6 0 R /PageMode /SinglePage /Pages 2 0 R /ViewerPreferences << /NonFullScreenPageMode /UseNone >> >> endobj # 2 0 obj << /Type /Pages /Count 1 /Kids [ 5 0 R ] /Resources 3 0 R >> endobj # 3 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> endobj # 4 0 obj << /Producer (PDF::API2 2.043 \(MSWin32\)) >> endobj # 5 0 obj << /Type /Page /Parent 2 0 R /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> >> endobj # 6 0 obj << /Type /Outlines /Count 1 /First 7 0 R /Last 7 0 R >> endobj # 7 0 obj << /Dest (1) /Parent 6 0 R /Title (Test Outline 1) >> endobj # xref # 0 8 # 0000000000 65535 f # 0000000015 00000 n # 0000000159 00000 n # 0000000235 00000 n # 0000000304 00000 n # 0000000365 00000 n # 0000000477 00000 n # 0000000548 00000 n # trailer # << /Info 4 0 R /Root 1 0 R /Size 8 >> # startxref # 617 # %%EOF # ' # Looks like you failed 2 tests of 2.