daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Jan 3rd, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def mergePDF():
  2.  
  3.         rootPath = os.path.join(dir_path, 'copies_100')
  4.         jobNumbers = []
  5.         pdfList = []
  6.         merger = PdfFileMerger()
  7.  
  8.         for jobNumber in os.listdir(rootPath):
  9.  
  10.             print '{' + jobNumber + '}'
  11.  
  12.             os.chdir(os.path.join(rootPath, jobNumber))
  13.  
  14.             #for root, dirs, files in os.walk(os.getcwd()):
  15.             for dirpath, dirnames, filenames in os.walk(os.getcwd()):
  16.                     print '########################################################'
  17.                     current = os.getcwd()
  18.                     print current
  19.                     print '########################################################'
  20.                     for filename in filenames:
  21.                         # Search only pdfs
  22.                         if filename.endswith(('.pdf','.PDF')):
  23.                             pdf = os.path.abspath(filename)
  24.                             mergedJob = "{0}_merged.pdf".format(jobNumber)
  25.                             try:
  26.                                 ## merger.append(PdfFileReader(open(os.path.join('mypdfs', fname), 'rb')))
  27.                                 merger.append(PdfFileReader(pdf, "rb"))
  28.                                 merger.write(os.path.join(current,mergedJob))
  29.                                 pdfList.append(pdf)
  30.                             except:
  31.                                 print jobNumber + '\n'
  32.  
  33.                     merger = PdfFileMerger()
  34.                     print pdfList
  35.                     pdfList = []
  36.                     print ''
  37.                     print ''
  38.         count = 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top