Advertisement
steve-shambles-2109

PDF to images

Apr 3rd, 2020
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. """Code snippets vol-48-snippet-236
  2.   PDF to images
  3.  
  4. Download all snippets so far:
  5. https://wp.me/Pa5TU8-1yg
  6.  
  7. Blog: stevepython.wordpress.com
  8.  
  9. requirements:
  10. pip install PyMuPDF
  11. https://pypi.org/project/PyMuPDF/
  12.  
  13. origin:
  14. https://www.tutorialexample.com/best-practice-to-python-convert-pdf-to-images-for-beginners-python-tutorial/
  15. """
  16. import webbrowser as wb
  17. import fitz
  18.  
  19. PDF = 'test.pdf'
  20. DOC = fitz.open(PDF)
  21.  
  22. for page in DOC:                          # iterate through the pages
  23.     pix = page.getPixmap(alpha=False)     # render page to an image
  24.     pix.writePNG('page-%i.png' % page.number)
  25.  
  26. wb.open('page-0.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement