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; } #### 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-- --nostringval-- 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 --nostringval-- --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)-- --dict: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