manykarim / robotframework-doctestlibrary

Robot Framework DocTest library. Simple Automated Visual Document Testing.
Apache License 2.0
46 stars 20 forks source link

File could not be converted by ImageMagick to OpenCV Image #12

Closed mydeveloperplanet closed 3 years ago

mydeveloperplanet commented 3 years ago

I have some problems running the test samples. The image comparison tests just work fine, the pdf comparison tests all fail due to the following error:

File could not be converted by ImageMagick to OpenCV Image: testdata/sample_1_page.pdf

Any idea what is wrong or how I can analyse this further? It seems that an exception is thrown from within convert_document_to_opencv_image.

Thanks for your answer and for this great library!

manykarim commented 3 years ago

Thanks a lot for your question regarding the PDF comparison. If the PDF comparison throws an exception, it is most likely caused by imagemagick or ghostscript. Common mistakes are:

Have you executed the installation steps to install the respective binaries (after installing the python packages)? https://github.com/manykarim/robotframework-doctestlibrary#installation-instructions In case you're using windows, please check the additional steps for the windows installation.

If that doesn't help: Which operation system are you using? Do you see any detailed error message in the robot log file?

mydeveloperplanet commented 3 years ago

Thanks for your fast answer (I now realize I did not provide some basic information):

log.zip

manykarim commented 3 years ago

One thing you can try - just to ensure that the binaries are installed properly: Try to convert a pdf file from the command line using imagemagick. I think on Linux it's the convert command. On windows it's magick.exe

convert file.pdf test.jpg

manykarim commented 3 years ago

One other thing: In some cases I had to modify a policy file, before imagemagick 'allows' the conversion of pdf files. Have a look at this thread and search for 'policy' https://stackoverflow.com/questions/43085889/how-to-convert-a-pdf-into-jpg-with-command-line-in-linux

I added a policy file to the repository and use it in the Dockerfile to build the container image. Maybe it also helps to check it out.

mydeveloperplanet commented 3 years ago

Tried to convert it via the command line, this gave the following error: $ convert sample.pdf sample.jpg convert-im6.q16: attempt to perform an operation not allowed by the security policyPDF' @ error/constitute.c/IsCoderAuthorized/408. convert-im6.q16: no images defined sample.jpg' @ error/convert.c/ConvertImageCommand/3258. I used the policy.xml file you provided and now it works ;-)

Is it ok if I add this to the readme? I think others will bump to this issue as well.

manykarim commented 3 years ago

Awesome, happy that it works for you now :) Honestly I wasn't sure how important that policy thing is, as I understood that it's not relevant for the latest imagemagick versions. But maybe I was wrong. I included it in the Dockerfile to be on the safe side.

It would be great if you could update the readme with that step. Thanks in advance!