Convert Pdf to Image as per the pdf page

2019-09-05 02:35发布

问题:

I want to upload a pdf then after I want to convert to image as per the pdf page means that If pdf have 2 pages then 2 images will generate.

After generate this image I want to store into table.

For example

I have a pdf table in that I upload a PDF and another table is image that I want to store pdf's images that newly generated.

I just need help for how to generate images from pdf as per the page

so How can i do this?

Please Help me?

Thanks

回答1:

You can accomplish it using RMagick lib for ruby.

For example:

require 'RMagick'

pdf = Magick::ImageList.new("file.pdf")

pdf.each_with_index do |page_img, i|
  page_img.write "#{i}_pdf_page.jpg"
end