I am succesfully able to convert PDF/DOC/DOCX to PNG using Rmagick gem in Ruby on Rails in my local system.
The algorithm I am following:
1. Fetch the PDF/DOC/DOCX from a given url.
2. Download that PDF/DOC/DOCX file in local project folder temporarily.
download_path_of_document = "#{Rails.root}/path/to/my/local/download_folder"
open("https://my-url.com") do |doc|
File.open(File.join(download_path_of_document, ".#{extension according to file doc/docx/pdf}"), "wb") do |file|
file.write(doc.read)
end
end
3. Pass that file through the RMagick convertor code by mentioning the path of that locally downloaded file.
4. Get it converted to PNG successfully.
my_converted_pngs = Magick::ImageList.new(File.join(download_path_of_document, ".#{extension according to file doc/docx/pdf}"))
5. Delete the downloaded file that was downloaded in step 2.
This method is working absolutely fine in my local system (environment).
But something weird is happening in my staging server. I am getting an error like : unable to open image `/tmp/magick-14238gTk5-CaYAECT': No such file or directory @ error/blob.c/OpenBlob/2712. The weird thing is that I am getting this error only when I pass DOC and DOCX file in step 3; in case of PDF it is working fine.
Kindy please help. (If any doubt regarding questions please ask multiple times in comments)
ruby - 2.2.2 rails - 4.2.2 gem - rmagick