Grim::UnprocessablePage convert PDF to Images images empty
I am using Grim to convert PDF to images, here is my code :
class PdfToImagesService
def initialize(pdf_file)
@pdf_file = pdf_file
end
def call
res = []
Grim.reap(@pdf_file.path).each_with_index do |page, index|
input_page = Tempfile.new([index.to_s, '.png'])
page.save(input_page.path, {
alpha: 'remove',
density: 300
})
res << input_page
end
res
end
end It does create an image in the /tmp folder of my server but it's a 0 octet one and so then it crashes with the
convert: not authorized /home/api/source/tmp/uploads/RackMultipart20181031-42206-6lqz8a_aea0ee662b.pdf' @ error/constitute.c/ReadImage/412. convert: no images defined/tmp/020181031-42176-xkzpxu.png' @ error/convert.c/ConvertImageCommand/3210.
So the "020181031-42176-xkzpxu.png" exists but 0 octet.
@bastoune thank you for reporting your issue. Could you open a Pull Request with a failing test case demonstrating the problem?
Hi thanks for your reply, I can't find a way to make such a PR ?
Hi thanks for your reply, I can't find a way to make such a PR ?
Here is a guide explaining how to create pull requests https://yangsu.github.io/pull-request-tutorial/
For the failing test case I would look at the existing tests in the spec folder, like these https://github.com/jonmagic/grim/blob/master/spec/lib/grim/image_magick_processor_spec.rb
I have the same issue on my Linux 16.04 and I could fix it changing the ImageMagick policy line in /etc/ImageMagick/policy.xml
<policy domain="coder" rights="none pattern="PDF" />
to
<policy domain="coder" rights="read" pattern="PDF" />
The fix is documented in StackOverflow