LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using pdftk to get all first pages of many pdf's into one pdf document (https://www.linuxquestions.org/questions/linux-newbie-8/using-pdftk-to-get-all-first-pages-of-many-pdfs-into-one-pdf-document-613665/)

zest n zeal 01-15-2008 05:12 AM

Using pdftk to get all first pages of many pdf's into one pdf document
 
Hallo all,

I have about 100 randomly named pdfs in a directory and I wish to compile a document consisting of the first page of every one.


I normally use pdftk with a command like this:

pdftk A=first.pdf B=second.pdf C=third.pdf cat A1 B1 C1 output combined_firstpages.pdf

Could you please help me with the correct syntax to get output from

ls *.pdf

into that command? I been trying with the 'read' command which is what I normally use in this kind of circumstance but it just ain't working and I currently feel as if my head is going to explode.

many thanks to anyone who can help sort this.

Adam

Guttorm 01-15-2008 09:07 AM

Hi

pdftk is not very good for this task. The handles can be only one letter and must be an uppercase letter, so only A-Z is possible.

But it can be done by making a temporary directory, extract page 1 of every PDF into a separate file in that directory, and then join all those PDF files into a big one. Here is a little script that does the job:

Code:

#!/bin/sh

#Set the filename on the line below:
DESTINATION="firstpages.pdf"

#Here is the temporary directory:
tempdir="/tmp/pdfpage1"
mkdir $tempdir
for name in *.pdf ; do
        pdftk "A=$name" cat A1 output "$tempdir/$name"
done
pdftk $tempdir/*.pdf cat output "$DESTINATION"
rm -r $tempdir



All times are GMT -5. The time now is 05:48 AM.