Combine multiple PDF files on Linux using script?

I want to save / download pdf files from the X website, and then merge all these pdf files into one, so it’s easy for me to see everyone at once.

What I've done,

  • get pdf files from website

    wget -r -l1 -A.pdf --no-parent http: // linktoX

  • merge PDF files into one

    gs -dNOPAUSE -sDEVICE = pdfwrite -sOUTPUTFILE = Combined_ date +%F.pdf -dBATCH file1.pdf file2.pdf file3.pdf

My question / problem is that I was thinking about automating all of this in a single script, so I don't need to do this every day. Here new PDF files are added daily in X.

So, how can I do step 2 above without giving a complete list of all PDF files, I tried to do file*.pdfin step 2; but he combined all the pdf files in random order.

The next problem is that the total number of * .pdf files is not the same everyday, sometimes 5 PDF sometimes 10 ... but it's nice that this is the name in file1.pdf file2.pdf ...

So, I need help to complete the above step 2, so that all pdf files are combined in order, and I should not explicitly specify the name of each pdf

Thanks.

UPDATE: This resolved the issue.

pdftk `ls -rt kanti*.pdf` cat output Kanti.pdf

I did ls -rt because file1.pdf was downloaded first, and then file2.pdf, etc .... just did ls -t put file 20.pdf at the beginning and file1.pdf at the last ...

+5
source share
3 answers

I also used pdftk in the past with good results.

sort $n - 1 , :

ls | sort -n -k 1.$n

, *.pdf:

$ ls | sort -n -k 1.5
file1.pdf
file2.pdf
file3.pdf
file4.pdf
file10.pdf
file11.pdf
file20.pdf
file21.pdf
+3

pdftk , pdftk, , Debian/Ubuntu.

+2

- :

GSCOMMAND="gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Combined_date +%F.pdf -dBATCH"
FILES=`ls file*.pdf | sort -n -k 1.5`

$GSCOMMAND $FILES

, "file.pdf". . alberge.

, escaping, .

, , , :)

FILES, alberge.

+1

All Articles