Step shown below are for MacOS/Linux
-
Create and activate virtual environment (optional)
python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Install ImageMagick
brew install imagemagick
or
sudo apt update && sudo apt install imagemagick
-
Then, run the script
python3 main.py <filename>
Replace
<filename>
with actual filename, eg:sample.pdf
. Output will be saved inoutput
folder.
Build the image
docker build -t pdf_to_image .
Run the image and using it
docker run -it --rm -v $(pwd):/app pdf_to_image python3 main.py <path_to_file>
Replace <path_to_file>
with actual filename, eg: /app/sample.pdf
. Output will be saved in output
folder.
Error: ImportError: MagickWand shared library not found. You probably had not installed ImageMagick library. Try to install: brew install freetype imagemagick
Try run the following command on the same terminal session where you run your python file:
export MAGICK_HOME=/opt/homebrew/opt/imagemagick
wand.exceptions.PolicyError: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/421
Run command below to turn off security setting
sudo mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.off
When you are done with the tool, revert the setting to its original
sudo mv /etc/ImageMagick-6/policy.xml.off /etc/ImageMagick-6/policy.xml
sample.pdf
is provided for you to test right away. You can get more sample pdf from: