# How to transform a pdf document into an image..?

**URL:** <https://www.ruby-forum.com/t/how-to-transform-a-pdf-document-into-an-image/196671>\
**Category:** Rails\
**Created:** [May 6, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/how-to-transform-a-pdf-document-into-an-image/196671 "2008-05-06T20:36:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [May 6, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/how-to-transform-a-pdf-document-into-an-image/196671/1 "2008-05-06T20:36:00Z")

</div>

I would like to display in my app the image of the cover page af an  
pdf document produced internnally within my app ( wich plugin should  
be better … ? pdfwrite ?.. generally it will be a less than 2 pages  
document)  
on the home page I would like to display the cover pages as png or jpg  
with a link to the document or another action…

thanks for your suggestions

erwin

---

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [May 7, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/how-to-transform-a-pdf-document-into-an-image/196671/2 "2008-05-07T17:11:32Z")

</div>

1. We’re using PDF:Writer and it should be fine with a small, 2 page  
document that you’re describing.

2. We’re doing exactly the sort of image conversion that you’re  
describing via RMagick. We’d originally installed RMagick for use  
with the early versions of acts\_as\_attachment (necessary for image  
uploading). It has some well-documented memory leaks, though. The  
code below is based on attachment\_fu/acts\_as\_attachment but should be  
easily enough adapted:

file\_path = File.join(RAILS\_ROOT, “public”, @image.public\_filename)  
img = Magick::Image::read(file\_path)  
img[0].write File.join(RAILS\_ROOT, “public”, “images”, “temp\_pdf.jpg”)

(I’m off to get that last bit cleaned up… as is, each user will  
clobber the other ☹

---

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [May 7, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/how-to-transform-a-pdf-document-into-an-image/196671/3 "2008-05-07T20:12:39Z")

</div>

For image attachments and showing their thumbnails, Paperclip is a good  
alternative to attachment\_fu. It doesn’t need RMagick, but it does need  
ImageMagick. Here’s the introductory blog post:

> **[For Attaching Files, use Paperclip](https://thoughtbot.com/blog/for-attaching-files-use-paperclip)**
>
> Last Update: For archival reasons, I’m removing direct links to releases,...

Googling for

rails paperclip

produces lots of relevant hits.

Regards,  
Craig
