[pdftex] Batch Page Extraction of PDFs

Michael T Metz mtmetz at swbell.net
Thu Jun 5 18:18:06 CEST 2003


Thank you Anthony. Your solutions were just what I needed.

-----Original Message-----
From: Anthony Wood [mailto:woody+pdftex at switchonline.com.au]
Sent: Wednesday, June 04, 2003 6:57 PM
To: Michael T Metz
Cc: pdftex at tug.org
Subject: Re: [pdftex] Batch Page Extraction of PDFs


On Wed, Jun 04, 2003 at 09:09:36AM -0500, Michael T Metz wrote:
> Dear list:
> 
> I'm looking for a way to extract the same page
> from many similar pdf files and put them in a
> single file. Has anyone done this or know a 
> possible avenue for me to investigate?

There are many ways to skin a cat :-)

pdflatex:

\documentclass[a4paper]{minimal}
\usepackage{geometry}
\geometry{top=0cm,bottom=0cm,left=0cm,right=0cm,nohead,nofoot}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={5}]{file1.pdf}
\includepdf[pages={5}]{file2.pdf}
\includepdf[pages={5}]{file3.pdf}
\includepdf[pages={5}]{file4.pdf}
\includepdf[pages={5}]{file5.pdf}
\includepdf[pages={5}]{file6.pdf}
\includepdf[pages={5}]{file7.pdf}
\includepdf[pages={5}]{file8.pdf}
\end{document}


Perl has a PDF::API2 module

here is a short program (merge.pl):

#! /usr/bin/perl -w

use strict;
use PDF::API2;

# last argument is the target PDF
my $merge = pop @ARGV;

# 1st argument is the page number
my $page = shift @ARGV

# other arguments are the source pdfs
my @pdfs = @ARGV;

# create new file
my $new = PDF::API2->new(-file => $merge);

# go through the source files
foreach my $spdf (map PDF::API2->open($_), at pdfs) {
  # add the page to the new file
  $new->importpage($spdf,$page-1,0);
}

# save the new file
$new->save;

so to get page 5 from all the pdfs in your directory and
put it into all5.pdf:

merge.pl 5 *.pdf all5.pdf


> 
> Regards,
> Mike
> 
> _______________________________________________
> pdftex mailing list
> pdftex at tug.org
> http://tug.org/mailman/listinfo/pdftex

-- 
Woody


More information about the pdftex mailing list