grim icon indicating copy to clipboard operation
grim copied to clipboard

Grim::UnprocessablePage convert PDF to Images images empty

Open bastoune opened this issue 7 years ago • 4 comments

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 avatar Oct 31 '18 16:10 bastoune

@bastoune thank you for reporting your issue. Could you open a Pull Request with a failing test case demonstrating the problem?

jonmagic avatar Nov 01 '18 06:11 jonmagic

Hi thanks for your reply, I can't find a way to make such a PR ?

bastoune avatar Nov 05 '18 10:11 bastoune

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

jonmagic avatar Nov 08 '18 00:11 jonmagic

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

clbustos avatar Jan 09 '19 04:01 clbustos