Below for you to share a Python pdf into a picture of the method, has a good reference value, I hope to be helpful to everyone. Come and see it together.
This article records how to use Python to slice a PDF file into a single picture, including environment configuration, version compatibility issues.
Environment configuration (MAC)
Installing ImageMagick
Brew Install ImageMagick
Here is a pit, brew installation is 7.x version, using wand error, you need to install 6.x version.
Workaround:
1. Install the 6.x version
Brew Install Imagemagick@6
2. Unlink 7.x version
Brew Unlink imagemagickunlinking/usr/local/cellar/imagemagick/7.0.7-4 ... Symlinks removed
3. Mandatory Link 6.x version
Brew Link imagemagick@6--forcelinking/usr/local/cellar/imagemagick@6/6.9.9-15 ... Symlinks created
4.export Environment variables
echo ' Export path= '/usr/local/opt/imagemagick@6/bin: $PATH ' >> ~/.bash_profile
OK, the above resolves the ImageMagick version issue.
Install GS
The GS must be installed, otherwise the PDF cannot be converted.
Brew Install GS
Installing Wand
PIP3 Install Wand
I use Python3 here, so I need to use PIP3.
Code implementation
From wand.image import imagedef convert_pdf_to_jpg (filename): With image (Filename=filename) as IMG: print (' pages = ' , Len (img.sequence)) with Img.convert (' jpeg ') as converted: converted.save (filename= ' image/page.jpeg ')
Effect
I will be a book more than 400 pages have been turned out, we can also go to try it.