Guest User

Combine PDFs

a guest
Oct 1st, 2022
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use framework "Foundation"
  2.  
  3. on run {input, parameters}
  4.    
  5.     set output to PdfDocumentFromFile(item 1 of input)
  6.     repeat with doc in rest of input
  7.         set pdf to PdfDocumentFromFile(doc)
  8.         repeat with n from 1 to pdf's pageCount()
  9.             (output's insertPage:(pdf's pageAtIndex:(n - 1)) atIndex:(output's pageCount()))
  10.         end repeat
  11.     end repeat
  12.    
  13.     tell application "Finder"
  14.         move input to the trash
  15.     end tell
  16.    
  17.     output's writeToFile:(POSIX path of (item 1 of input))
  18.    
  19.     return item 1 of input
  20. end run
  21.  
  22. on PdfDocumentFromFile(fileName)
  23.     return current application's PDFDocument's alloc()'s initWithURL:(current application's NSURL's fileURLWithPath:(POSIX path of fileName))
  24. end PdfDocumentFromFile
Advertisement
Add Comment
Please, Sign In to add comment