main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2023/12/09 14:57:36
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : enter point
  8. recycle read all files in a directory, and find *.pdf files, then convert x.pdf to x.html
  9. '''
  10. import os,sys,re,shutil
  11. def convert():
  12. ''''''
  13. current_dir = os.getcwd()
  14. if not os.path.exists(os.path.join(current_dir,'htmls')):
  15. os.mkdir(os.path.join(current_dir,'htmls'))
  16. for root, dirs, files in os.walk(current_dir):
  17. for file in files:
  18. if file.endswith('.pdf'):
  19. try:
  20. os.system('pdf2htmlEX --zoom 1.3 --process-outline 0 --page-filename %s.html %s'%(file,file))
  21. print('convert %s to %s.html'%(file,file))
  22. except Exception as e:
  23. print(f'convert failed: {e}')
  24. # move all .html to htmls diretory
  25. for root, dirs, files in os.walk(current_dir):
  26. for file in files:
  27. if file.endswith('.html'):
  28. try:
  29. shutil.move(os.path.join(root,file),os.path.join(current_dir,'htmls'))
  30. except Exception as e:
  31. print(f'move failed: {e}')
  32. if __name__=='__main__':
  33. convert()