Advertisement
Guest User

Untitled

a guest
Jan 20th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #/bin/bash
  2.  
  3. # First we remove the pdfmarks file, since we'll be building it from scratch
  4. rm pdfmarks
  5.  
  6. # ChapterNumber is simple the number of the chapter, one chapter per pdf
  7. ChapterNumber=0
  8. NumberOfPages=1
  9.  
  10. # This loops over all the pdf files in the current directory
  11. for f in $(ls *.pdf)
  12. do
  13.     # We add one to the chapter number
  14.     ChapterNumber=$(($ChapterNumber+1))
  15.     # And we print this weird line into our pdfmarks file
  16.     echo "[/Title (Chapter $ChapterNumber) /Page $NumberOfPages /OUT pdfmark" >> pdfmarks
  17.  
  18.     # We get the number of pages from a small utility called pdfinfo, check if it's installed
  19.     # We add the number of pages in the current file to the NumberOfPages counter
  20.     NumberOfPages=$(($NumberOfPages + $(pdfinfo $f | grep -i "Pages:" | awk '{print $2}') ))
  21.  
  22.     # now we're finished with this file.. on to the next
  23. done
  24.  
  25. gs -dBATCH -dNOPAUSE -sPAPERSIZE=a4 -sDEVICE=pdfwrite -sOutputFile="MASTER.pdf" $(ls *.pdf) pdfmarks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement