Skip to content

Instantly share code, notes, and snippets.

@rwp0
Last active March 14, 2023 05:26
Show Gist options
  • Save rwp0/410d4a3792dcbfbcd2998a719b8c73c4 to your computer and use it in GitHub Desktop.
Save rwp0/410d4a3792dcbfbcd2998a719b8c73c4 to your computer and use it in GitHub Desktop.
Merge PDF Documents using PDF-API2 Perl Distribution
#! /usr/bin/env perl
use v5.37.9;
use PDF::API2;
chdir 'PATH_WITH_PDFS';
my $pdf = PDF::API2 -> new;
my $source1 = PDF::API2 -> open( '1.pdf' );
my $source2 = PDF::API2 -> open( '2.pdf' );
my $page1 = $pdf -> import_page( $source1 );
my $page2 = $pdf -> import_page( $source2 );
$pdf -> save( 'all.pdf' );
# Method: https://metacpan.org/pod/PDF::API2#import_page
# cf. mutool merge -o all.pdf 1.pdf 2.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment