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

前端 未结 6 2276
陌清茗
陌清茗 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:49

    Sample code to answer the comment by @aisensiy above :

    require 'rmagick'
    pdf_path = "/path/to/interesting/file.pdf"
    page_index_path = pdf_path + "[0]" # first page in PDF
    pdf_page = Magick::Image.read( page_index_path ).first # first item in Magick::ImageList
    pdf_page.write( "/tmp/indexed-page.png" ) # implicit conversion based on file extension
    

    Based on the path clue in answer to another question :

    https://stackoverflow.com/a/6369524/765063

提交回复
热议问题