pdftoimage 0.1.7 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: eebf9a790b95c556d3b47ba87bd69998ccd15529
4
- data.tar.gz: bc3a5653ae433aee369c98325f0358c1fec53d47
2
+ SHA256:
3
+ metadata.gz: 7385d5aaa8f461f7214d25b9972e5b3cdfd528da1da7c7dfd18b61309e9dd010
4
+ data.tar.gz: ed6c231fa756f90c9330d9f68fcec469aa447b5446ded5074d711ddee9579d04
5
5
  SHA512:
6
- metadata.gz: 7d13c5805d512c7bceba7f9da7bab1f74fcc9e5fbbca9f1c951abc08614818ce97835b44b8f5cf33eddb903fc1b7ee042d453cc7cbb9742943425616504bc634
7
- data.tar.gz: b4c38f9539b6050e52c4b5cca7971bfb78f5357dae0b17807be779832e3706f062b7a6bf65dd740648c1ac9b7e951b516ef6f6da1d7985409685792a17a0f157
6
+ metadata.gz: 182bac990daff942767ca44b8cd56e3979fa39f334f565a2b7efabb8497b8be042b04e0abfafc735ba0f2023440732093c6bc77edb7ac12ed1ebbb8fc7287634
7
+ data.tar.gz: 37df49043986c6c02720dec32d076144c199cac1b6b8fcf87c895f4fb1131e297eb85b91f0df1915a7571561076641c74527d18d9d2b74267b813eec4de63d51
data/ChangeLog.rdoc CHANGED
@@ -1,7 +1,17 @@
1
+ === 0.2.0 / 2023-04-20
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) 2010 Rob Flynn
49
+ Copyright (c) 2023 Rob Flynn
42
50
 
43
- See LICENSE.txt for details.
51
+ See LICENSE for details.
@@ -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
@@ -1,4 +1,4 @@
1
1
  module PDFToImage
2
2
  # pdftoimage version
3
- VERSION = "0.1.7"
3
+ VERSION = "0.2.1"
4
4
  end
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.exists?(filename)
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 -a 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 -a 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.1.7
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Flynn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-01 00:00:00.000000000 Z
11
+ date: 2025-04-08 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.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.2
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
@@ -58,8 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
72
  - !ruby/object:Gem::Version
59
73
  version: '0'
60
74
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.6.14.1
75
+ rubygems_version: 3.0.3.1
63
76
  signing_key:
64
77
  specification_version: 4
65
78
  summary: A ruby gem for converting PDF documents into a series of images.