0
0

More than 3 years have passed since last update.

how can I convert pdf to image using pdf2image in python on Mac OS X?

Last updated at Posted at 2020-05-27

I want to convert pdf to image using pdf2image in python on Mac OS X.

from pdf2image.exceptions import (
    PDFInfoNotInstalledError,
    PDFPageCountError,
    PDFSyntaxError
)
# define pdf path
pdf_path = "./pdf_file/ooo.pdf"

# convert pdf to image(1200dpi)
images = convert_from_path(str(pdf_path), 1200)
# save image files one by one
image_dir = "./image_file"
for i, image in enumerate(images):
    file_name = pdfpath + "{:02d}".format(i + 1) + ".jpeg"
    image_path = image_dir / file_name
    # save JPEG
    image.save(str(image_path), "JPEG")

then I get the error message like

TypeError                                 Traceback (most recent call last)
<ipython-input-19-26e2710189ca> in <module>
     13 for i, image in enumerate(images):
     14     file_name = pdfpath + "{:02d}".format(i + 1) + ".jpeg"
---> 15     image_path = image_dir / file_name
     16     # save JPEG
     17     image.save(str(image_path), "JPEG")

TypeError: unsupported operand type(s) for /: 'str' and 'str'

I cannot understand what is happening. Please help!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0