pdf_thumbnailer 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/pdf_thumbnailer/pdf_thumbs.rb +6 -5
- data/lib/pdf_thumbnailer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b3ace09d0d839ca7d61380e29c4039403a6087f
|
4
|
+
data.tar.gz: 02788591f6b4270a4618637e46545939ae23fa26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3f154315dae197aa8970aa3a2b9c63642f461566453235aed2243f677318ebb0ab320295ee6bbaaccea9ecc9293d932dbbdb930be75399e9c42a05a4b77cf03
|
7
|
+
data.tar.gz: b1d20204d5aa675e0e111f2126d1b5ae7c294031c9185a53f676e8fbde5aee79612edc2d9a4f41eedf6d048b4455c4dd2cc7bbca96339f40638fe89cc08ccebd
|
data/README.md
CHANGED
@@ -43,14 +43,14 @@ end
|
|
43
43
|
|
44
44
|
`thumbnail!` optionally accepts a code block with one argument. This argument (`thumb_dir` in the above example) will be a string representing the path of the newly created directory containing page images for a particular pdf. The folder structure `img_dir` will be identical to that of `pdf_dir` but for every `.pdf` file there will instead be a directory of the same name containing `.png` iamges.
|
45
45
|
|
46
|
-
Alternatively a single pdf file can have its pages converted to images using the `thumbnail_single!` method:
|
46
|
+
Alternatively a single pdf file can have its pages converted to images using the `thumbnail_single!` method. Note that this method will return the number of pages in the pdf that were converted to images:
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
PdfThumbs.configure img_dir: '/where/to/save/page/images', thumb_sizes: 500
|
50
50
|
|
51
|
-
|
51
|
+
num_pages = PdfThumbs.thumbnail_single! '/pdf/root/dir', 'relative/path/to/My File.pdf'
|
52
52
|
|
53
|
-
puts "
|
53
|
+
puts "Number of pages extracted = #{num_pages}"
|
54
54
|
```
|
55
55
|
|
56
56
|
|
@@ -16,9 +16,8 @@ class PdfThumbs
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
# TODO: add spec and document in README.md
|
20
19
|
def self.thumbnail_single! pdf_dir, relative_pdf_path
|
21
|
-
thumbnail_pdf pdf_dir, relative_pdf_path
|
20
|
+
thumbnail_pdf pdf_dir, relative_pdf_path, true
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
@@ -34,18 +33,20 @@ class PdfThumbs
|
|
34
33
|
img_dir
|
35
34
|
end
|
36
35
|
|
37
|
-
def self.thumbnail_pdf pdf_dir, relative_pdf_path
|
36
|
+
def self.thumbnail_pdf pdf_dir, relative_pdf_path, return_num_pages = false
|
38
37
|
img_dir = clear_img_dir relative_pdf_path
|
38
|
+
num_pages = 0
|
39
39
|
|
40
|
-
@@thumb_sizes.
|
40
|
+
@@thumb_sizes.each_with_index do |thumb_size, idx|
|
41
41
|
`pdftoppm -png -scale-to #{thumb_size} "#{File.join(pdf_dir, relative_pdf_path)}" "#{img_dir}"`
|
42
42
|
|
43
43
|
Dir.glob(File.join(img_dir, '-*.png')) do |img_path|
|
44
44
|
page_num = File.basename(img_path, '.png').split('-')[-1].to_i
|
45
45
|
File.rename(img_path, File.join(img_dir, "#{thumb_size}_#{page_num}.png"))
|
46
|
+
num_pages += 1 if return_num_pages && idx == 0
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
img_dir
|
50
|
+
return_num_pages ? num_pages : img_dir
|
50
51
|
end
|
51
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf_thumbnailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|