pdftoimage 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog.rdoc +10 -1
- data/README.rdoc +11 -3
- data/lib/pdftoimage/image.rb +19 -2
- data/lib/pdftoimage/version.rb +1 -1
- data/lib/pdftoimage.rb +4 -3
- metadata +20 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a7ff47bfe4c829a2912d1e88413d06ffe3e4d321896d2a3f5d2ab571d98e863
|
4
|
+
data.tar.gz: 641ae71e08ce8b7f7e011836169feec866be1a7edb1c194995008bf582b8b3e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6ac26519e1ad5f28e904cf609113d9c5c4c52c26786e668f82511b139f8bcc55a6320623367e4738e4aa5a734625e1fb76e8a6e6ec07c01a4ad38db49869192
|
7
|
+
data.tar.gz: bcec5c69d21c6abd963e4a8c7003246969b8dc5c19e57059489ebc244e589c797c1e03108c96f24349f33bedb2b0087851d8a5421bc315e5a5bc7d721c6fb22f
|
data/ChangeLog.rdoc
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
=== 0.1.7 / 2018-05-01
|
2
|
+
* Fixed use of deprecated File.exists? method (pr#4 from Thornolf)
|
3
|
+
* File paths are now escaped to properly handle spaces and special characters (pr#3 from drnic)
|
4
|
+
* Specifying dpi resolution is now supported (pr#5 from lehf)
|
5
|
+
|
6
|
+
=== 0.1.7 / 2018-05-01
|
7
|
+
* Updated yard to resolve a vulnerability.
|
8
|
+
|
1
9
|
=== 0.1.6 / 2011-07-13
|
2
10
|
* Buggy PDF generators try to encode CreationDate and ModDate as UTF-16 as opposed to ASCII. This leads to parsing errors where the code was assuming UTF-8 encoding was in use.
|
11
|
+
|
3
12
|
=== 0.1.5 / 2011-03-08
|
4
13
|
* Fixed a bug due to the fact that poppler_utils no longer leaves off the extra padded zero.
|
14
|
+
|
5
15
|
=== 0.1.4 / 2010-11-15
|
6
16
|
* Fixed a bug concerning documents with page counts that are exact powers of 10. poppler_utils prepends one less zero to the page counts when a document count is a power of 10. This is now fixed in PDFToImage.
|
7
17
|
|
@@ -16,4 +26,3 @@
|
|
16
26
|
=== 0.1.1 / 2010-11-10
|
17
27
|
|
18
28
|
* Initial release:
|
19
|
-
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
== Description
|
6
6
|
|
7
|
-
PDFToImage is a ruby gem which allows for conversion of a PDF document into
|
7
|
+
PDFToImage is a ruby gem which allows for conversion of a PDF document into
|
8
8
|
images. It uses poppler_utils to first convert the document to PNG and then
|
9
9
|
allows usage of ImageMagick to convert the image into other formats.
|
10
10
|
|
@@ -25,6 +25,14 @@ to be able to parse without error.
|
|
25
25
|
page.resize('150').quality('80%').save('out/thumbnail-#{page.page}.jpg")
|
26
26
|
end
|
27
27
|
|
28
|
+
require 'pdftoimage'
|
29
|
+
PDFToImage.open('anotherpdf.pdf') do |page|
|
30
|
+
# Set the resolution to 350dpi
|
31
|
+
page.r(350).save('out/thumbnail-#{page.page}.jpg")
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
28
36
|
== Requirements
|
29
37
|
|
30
38
|
poppler_utils
|
@@ -38,6 +46,6 @@ ImageMagick
|
|
38
46
|
|
39
47
|
== Copyright
|
40
48
|
|
41
|
-
Copyright (c)
|
49
|
+
Copyright (c) 2023 Rob Flynn
|
42
50
|
|
43
|
-
See LICENSE
|
51
|
+
See LICENSE for details.
|
data/lib/pdftoimage/image.rb
CHANGED
@@ -8,6 +8,7 @@ module PDFToImage
|
|
8
8
|
attr_reader :height
|
9
9
|
attr_reader :page
|
10
10
|
attr_reader :args
|
11
|
+
attr_reader :pdf_args
|
11
12
|
attr_reader :opened
|
12
13
|
|
13
14
|
# ImageMagick methods that we currently support.
|
@@ -16,6 +17,13 @@ module PDFToImage
|
|
16
17
|
"quality"
|
17
18
|
]
|
18
19
|
|
20
|
+
# pdftoppm methods that we currently support.
|
21
|
+
PDF_IMAGE_METHODS = [
|
22
|
+
"r",
|
23
|
+
"rx",
|
24
|
+
"ry"
|
25
|
+
]
|
26
|
+
|
19
27
|
CUSTOM_IMAGE_METHODS.each do |method|
|
20
28
|
define_method(method.to_sym) do |*args|
|
21
29
|
@args << "-#{method} #{args.join(' ')}"
|
@@ -24,6 +32,14 @@ module PDFToImage
|
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
35
|
+
PDF_IMAGE_METHODS.each do |method|
|
36
|
+
define_method(method.to_sym) do |*args|
|
37
|
+
@pdf_args << "-#{method} #{args.join(' ')}"
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
27
43
|
# Image constructor
|
28
44
|
#
|
29
45
|
# @param pdf_name [String] The name of the PDF
|
@@ -34,6 +50,7 @@ module PDFToImage
|
|
34
50
|
#
|
35
51
|
def initialize(pdf_name, filename, page, page_size, page_count)
|
36
52
|
@args = []
|
53
|
+
@pdf_args = []
|
37
54
|
|
38
55
|
@pdf_name = pdf_name
|
39
56
|
@filename = filename
|
@@ -58,7 +75,7 @@ module PDFToImage
|
|
58
75
|
cmd += "#{@args.join(' ')} "
|
59
76
|
end
|
60
77
|
|
61
|
-
cmd += "#{@filename} #{outname}"
|
78
|
+
cmd += "#{Shellwords.escape(@filename)} #{Shellwords.escape(outname)}"
|
62
79
|
|
63
80
|
PDFToImage.exec(cmd)
|
64
81
|
|
@@ -79,7 +96,7 @@ module PDFToImage
|
|
79
96
|
|
80
97
|
def generate_temp_file
|
81
98
|
if @opened == false
|
82
|
-
cmd = "pdftoppm -png -f #{@page} -l #{@page} #{@pdf_name} #{@filename}"
|
99
|
+
cmd = "pdftoppm -png -f #{@page} #{@pdf_args.join(" ")} -l #{@page} #{Shellwords.escape(@pdf_name)} #{Shellwords.escape(@filename)}"
|
83
100
|
PDFToImage.exec(cmd)
|
84
101
|
@filename = "#{@filename}-#{page_suffix}.png"
|
85
102
|
@opened = true
|
data/lib/pdftoimage/version.rb
CHANGED
data/lib/pdftoimage.rb
CHANGED
@@ -3,6 +3,7 @@ require 'pdftoimage/image'
|
|
3
3
|
|
4
4
|
require 'tmpdir'
|
5
5
|
require 'iconv'
|
6
|
+
require 'shellwords'
|
6
7
|
|
7
8
|
module PDFToImage
|
8
9
|
class PDFError < RuntimeError; end
|
@@ -33,7 +34,7 @@ module PDFToImage
|
|
33
34
|
#
|
34
35
|
# @return [Array] An array of images
|
35
36
|
def open(filename, &block)
|
36
|
-
if not File.
|
37
|
+
if not File.exist?(filename)
|
37
38
|
raise PDFError, "File '#{filename}' not found."
|
38
39
|
end
|
39
40
|
|
@@ -73,7 +74,7 @@ module PDFToImage
|
|
73
74
|
private
|
74
75
|
|
75
76
|
def page_size(filename, page)
|
76
|
-
cmd = "pdfinfo -f #{page} -l #{page} #{filename} | grep Page"
|
77
|
+
cmd = "pdfinfo -f #{page} -l #{page} #{Shellwords.escape(filename)} | grep Page"
|
77
78
|
output = exec(cmd)
|
78
79
|
|
79
80
|
matches = /^Page.*?size:.*?(\d+).*?(\d+)/.match(output)
|
@@ -91,7 +92,7 @@ module PDFToImage
|
|
91
92
|
end
|
92
93
|
|
93
94
|
def page_count(filename)
|
94
|
-
cmd = "pdfinfo #{filename} | grep Pages"
|
95
|
+
cmd = "pdfinfo #{Shellwords.escape(filename)} | grep Pages"
|
95
96
|
output = exec(cmd)
|
96
97
|
matches = /^Pages:.*?(\d+)$/.match(output)
|
97
98
|
if matches.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdftoimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Flynn
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iconv
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: shellwords
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
27
41
|
description: A ruby gem for converting PDF documents into a series of images. This
|
28
42
|
module is based off poppler_utils and ImageMagick.
|
29
43
|
email: rob@thingerly.com
|
@@ -43,7 +57,7 @@ licenses:
|
|
43
57
|
metadata:
|
44
58
|
changelog_uri: https://github.com/robflynn/pdftoimage/blob/master/ChangeLog.rdoc
|
45
59
|
source_code_uri: https://github.com/robflynn/pdftoimage/
|
46
|
-
post_install_message:
|
60
|
+
post_install_message:
|
47
61
|
rdoc_options: []
|
48
62
|
require_paths:
|
49
63
|
- lib
|
@@ -58,9 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
72
|
- !ruby/object:Gem::Version
|
59
73
|
version: '0'
|
60
74
|
requirements: []
|
61
|
-
|
62
|
-
|
63
|
-
signing_key:
|
75
|
+
rubygems_version: 3.0.9
|
76
|
+
signing_key:
|
64
77
|
specification_version: 4
|
65
78
|
summary: A ruby gem for converting PDF documents into a series of images.
|
66
79
|
test_files: []
|