Convert a .doc or .pdf to an image and display a thumbnail in Ruby?

前端 未结 6 2284
陌清茗
陌清茗 2020-12-12 21:35

Convert a .doc or .pdf to an image and display a thumbnail in Ruby?
Does anyone know how to generate document thumbnails in Ruby (or C, python...)

6条回答
  •  粉色の甜心
    2020-12-12 21:50

    A simple RMagick example to convert a PDF to a PNG would be:

    require 'RMagick'
    pdf = Magick::ImageList.new("doc.pdf")
    thumb = pdf.scale(300, 300)
    thumb.write "doc.png"
    

    To convert a MS Word document, it won't be as easy. Your best option may be to first convert it to a PDF before generating the thumbnail. Your options for generating the PDF depend heavily on the OS you're running on. One might be to use OpenOffice and the Python Open Document Converter. There are also online conversion services you could try, including http://Zamzar.com.

提交回复
热议问题