Guest User

Untitled

a guest
Oct 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. Parent folder
  2. - printPDFfolder.py
  3. - pdf_to_merge
  4. -- cat.pdf
  5. -- dog.pdf
  6. - other_cool_pdfs
  7. -- a wrinkle in time.pdf
  8. -- baseball.pdf
  9.  
  10. fileDir = os.path.dirname(os.path.realpath(__file__))
  11. print "Your file directory is: " + fileDir
  12. for root, dirs, files in os.walk(fileDir):
  13. merger = PdfFileMerger()
  14. print "The files to merge are:"
  15. print files
  16. for filename in files:
  17. print "file name is: " + filename
  18. if filename.endswith(".pdf"):
  19. print "file names: " + filename
  20. filepath = os.path.join(root, filename)
  21. print "Your file path to append to is: " + filepath
  22. # with open(filepath)
  23. merger.append(PdfFileReader(open(filepath, 'rb')))
  24. print "merger is: "
  25. print merger
  26. #merger.write(str(filename))
  27. # write file path of the sub folder
  28. # test folder name is: pdf_to_merge
  29. print "what is dirs"
  30. print dirs
  31. merger.write(os.path.join(fileDir, dirs + '.pdf'))
  32.  
  33. C:Python27ArcGISx6410.5python.exe C:/Workspace-TT/GeneratePdfBinderPython/test/combinePDFFolder.py
  34. Traceback (most recent call last):
  35. Your file directory is: C:Workspace-TTGeneratePdfBinderPythontest
  36. File "C:/Workspace-TT/GeneratePdfBinderPython/test/combinePDFFolder.py", line 45, in <module>
  37. The files to merge are:
  38. merger.append(PdfFileReader(open(filepath, 'rb')))
  39. ['combinePDFFolder.py']
  40. file name is: combinePDFFolder.py
  41. The files to merge are:
  42. File "C:Python27ArcGISx6410.5libsite-packagesPyPDF2pdf.py", line 1084, in __init__
  43. ['WV__FRI-AY-28-07-CUT.pdf', 'WV__FRI-AY-29-06-CUT.pdf', 'WV__FRI-AY-29-07-CUT.pdf', 'WV__FRI-AY-30-05-CUT.pdf', 'WV__FRI-AY-30-07-CUT.pdf', 'WV__FRI-AY-31-04-CUT.pdf', 'WV__FRI-AY-31-05-CUT.pdf', 'WV__FRI-AY-31-06-CUT.pdf']
  44. self.read(stream)
  45. file name is: WV__FRI-AY-28-07-CUT.pdf
  46. File "C:Python27ArcGISx6410.5libsite-packagesPyPDF2pdf.py", line 1689, in read
  47. file names: WV__FRI-AY-28-07-CUT.pdf
  48. Your file path to append to is: C:Workspace-TTGeneratePdfBinderPythontestpdf_to_mergeWV__FRI-AY-28-07-CUT.pdf
  49. stream.seek(-1, 2)
  50. IOError: [Errno 22] Invalid argument
Add Comment
Please, Sign In to add comment