Fellow monasterians, i am about to go crazy. The task is to merge multiple PDF-Files to one. Seems easy enough (hey, there is CPAN) and so i wrote the following algorithm:
use strict; use PDF::API2; my $pdf = PDF::API2->new( -file => "path/to/outfile.pdf" ); my @files = glob ("path/to/somewhere/else/*.pdf"); merge (@files); # some stuff sub merge { my ( $file, $root, ); $root = $pdf->outlines; my $import_page = 0; my $document_page = 0; foreach $file ( @_ ) { my ($inputpdf, $inputdir) = fileparse ($file); my $input = PDF::API2->open( $file ); my @pages = 1 .. $input->pages; if ( scalar @pages > 0 ) { my $outline; $outline = $root->outline if $bookmark; foreach ( @pages ) { ++$import_page; ++$document_page; my $page = $pdf->importpage($input, $_, $import_page); if ( $bookmark ) { my ($bmtext) = ($inputpdf =~ /([^\.]+)/ ); $outline->title($bmtext); my $bm = $outline->outline; $bm->title("Seite $document_page"); $bm->dest($page); $outline->dest($page) if $document_page == 1; $outline->closed; } } } } $pdf->preferences( -outlines => 1 ) if $bookmark; $pdf->update; $pdf->end; }
This works for the first iteration of the merging. For example i merge first x/1.pdf and x/2.pdf to ./x.pdf. Second y/1.pdf and y/2.pdf to ./y.pdf. Both resulting files look fine in Acrobat Reader and Ghostview. I can print, copy&paste, etc.

The problem arises when i trie to merge x.pdf and y.pdf to z.pdf. Doing so will result in a new file with the expected number of pages, but all pages are blank and i get 2 error-messages (from Acrobat Reader):
1) A problem occured while reading the document (14)
2) A font is not listed in the resource-dictionary. Using Helvetica

Sometimes it also complains "Graphical Resource AR+B9 not found.

Opening the file with Ghostview i get this error:
GSview 4.6 2004-01-11 AFPL Ghostscript 8.14 (2004-02-20) Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Scanning PDF file %GSVIEW_PDF_PAGES: 1 19 Displaying PDF page 1 %GSVIEW_PDF_PAGE: 1 %GSVIEW_PDF_MEDIA: [0 0 594.9 841.36] %GSVIEW_PDF_ROTATE: 0 Error: /invalidfont in /AB+F0 Operand stack: --dict:4/4(L)-- AB+F0 7.92 Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --no +stringval-- 2 %stopped_push --nostringval-- --nostringval-- + false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_ +pop 1 3 %oparray_pop 1 3 %oparray_pop .runexec2 --nos +tringval-- --nostringval-- --nostringval-- 2 %stopped_push +--nostringval-- --nostringval-- --nostringval-- --nostringval-- + --nostringval-- %array_continue --nostringval-- false 1 +%stopped_push --nostringval-- %loop_continue --nostringval-- Dictionary stack: --dict:1120/1686(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)-- + --dict:104/127(ro)(G)-- --dict:238/347(ro)(G)-- --dict:20/24(L)- +- --dict:4/6(L)-- --dict:20/20(L)-- --dict:1/1(ro)(G)-- --dic +t:1/1(ro)(G)-- --dict:1/1(ro)(G)-- --dict:9/13(L)-- Current allocation mode is local Last OS error: No such file or directory pdf_page failed
Can somenone help me to solve this issue? I have no clue where to start.

Update:
Corrected copy&paste errors
Update:
Followed dragonchilds critics

holli, regexed monk

In reply to repeated merging of PDF-Files by holli

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.