Skip to content

Commit 97dc1e8

Browse files
committed
Add Create Thumbnail Image For A PDF as a ruby til
1 parent eaaf308 commit 97dc1e8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77
warrant a full blog post. These are mostly things I learn by pairing with
88
smart people at [Hashrocket](http://hashrocket.com/).
99

10-
_339 TILs and counting..._
10+
_340 TILs and counting..._
1111

1212
---
1313

@@ -236,6 +236,7 @@ _339 TILs and counting..._
236236
- [Comparing Arrays In RSpec](ruby/comparing-arrays-in-rspec.md)
237237
- [Construct A Constant From A String](ruby/construct-a-constant-from-a-string.md)
238238
- [Create an Array of Stringed Numbers](ruby/create-an-array-of-stringed-numbers.md)
239+
- [Create Thumbnail Image For A PDF](ruby/create-thumbnail-image-for-a-pdf.md)
239240
- [Defaulting To Frozen String Literals](ruby/defaulting-to-frozen-string-literals.md)
240241
- [Destructuring Arrays In Blocks](ruby/destructuring-arrays-in-blocks.md)
241242
- [Disassemble Some Codes](ruby/disassemble-some-codes.md)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Create Thumbnail Image For A PDF
2+
3+
The [`rmagick`](https://rmagick.github.io/) gem is a wrapper around the
4+
[ImageMagick](http://www.imagemagick.org/script/index.php) software suite.
5+
This gem can be used to create a thumbnail image of a PDF using the
6+
following snippet of code.
7+
8+
```ruby
9+
require 'rmagick'
10+
pdf = Magick::ImageList.new('document.pdf')
11+
first_page = pdf.first
12+
scaled_page = first_page.scale(300, 450)
13+
scaled_page.write('document-thumbnail.jpg')
14+
```
15+
16+
The scale can be adjust as necessary to the use case.
17+
18+
[source](http://stackoverflow.com/questions/65250/convert-a-doc-or-pdf-to-an-image-and-display-a-thumbnail-in-ruby)

0 commit comments

Comments
 (0)