pdftoimage 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eebf9a790b95c556d3b47ba87bd69998ccd15529
4
+ data.tar.gz: bc3a5653ae433aee369c98325f0358c1fec53d47
5
+ SHA512:
6
+ metadata.gz: 7d13c5805d512c7bceba7f9da7bab1f74fcc9e5fbbca9f1c951abc08614818ce97835b44b8f5cf33eddb903fc1b7ee042d453cc7cbb9742943425616504bc634
7
+ data.tar.gz: b4c38f9539b6050e52c4b5cca7971bfb78f5357dae0b17807be779832e3706f062b7a6bf65dd740648c1ac9b7e951b516ef6f6da1d7985409685792a17a0f157
File without changes
@@ -1,117 +1,115 @@
1
- require 'tmpdir'
2
1
  require 'pdftoimage/version'
3
2
  require 'pdftoimage/image'
3
+
4
+ require 'tmpdir'
4
5
  require 'iconv'
5
6
 
6
7
  module PDFToImage
7
- class PDFError < RuntimeError; end
8
+ class PDFError < RuntimeError; end
8
9
  end
9
10
 
10
11
  module PDFToImage
11
- # A class variable for storing the location of our temp folder
12
- @@pdf_temp_dir = File.join(Dir.tmpdir())
13
-
14
- begin
15
- tmp = `pdftoppm -v 2>&1`
16
- raise(PDFToImage::PDFError, "poppler_utils not installed") unless tmp.index('Poppler')
17
- rescue Errno::ENOENT
18
- raise PDFToImage::PDFError, "poppler_utils not installed"
19
- end
20
-
21
- begin
22
- tmp = `identify -version 2>&1`
23
- raise(PDFToImage::PDFError, "ImageMagick not installed") unless tmp.index('ImageMagick')
24
- rescue Errno::ENOENT
25
- raise PDFToImage::PDFError, "ImageMagick not installed"
26
- end
27
-
28
- class << self
12
+ # A class variable for storing the location of our temp folder
13
+ @@pdf_temp_dir = File.join(Dir.tmpdir())
14
+
15
+ begin
16
+ tmp = `pdftoppm -v 2>&1`
17
+ raise(PDFToImage::PDFError, "poppler_utils not installed") unless tmp.index('Poppler')
18
+ rescue Errno::ENOENT
19
+ raise PDFToImage::PDFError, "poppler_utils not installed"
20
+ end
29
21
 
30
- # Opens a PDF document and prepares it for splitting into images.
31
- #
32
- # @param [filename] The filename of the PDF to open
33
- # @return [Array] An array of images
34
- def open(filename, &block)
35
- if not File.exists?(filename)
36
- raise PDFError, "File '#{filename}' not found."
37
- end
22
+ begin
23
+ tmp = `identify -version 2>&1`
24
+ raise(PDFToImage::PDFError, "ImageMagick not installed") unless tmp.index('ImageMagick')
25
+ rescue Errno::ENOENT
26
+ raise PDFToImage::PDFError, "ImageMagick not installed"
27
+ end
38
28
 
39
- pages = page_count(filename)
29
+ class << self
30
+ # Opens a PDF document and prepares it for splitting into images.
31
+ #
32
+ # @param filename [String] The filename of the PDF to open
33
+ #
34
+ # @return [Array] An array of images
35
+ def open(filename, &block)
36
+ if not File.exists?(filename)
37
+ raise PDFError, "File '#{filename}' not found."
38
+ end
40
39
 
41
- # Array of images
42
- images = []
40
+ pages = page_count(filename)
43
41
 
44
- 1.upto(pages) { |n|
45
- dimensions = page_size(filename, n)
46
- image = Image.new(filename, random_filename, n, dimensions, pages)
47
- images << image
48
- }
42
+ # Array of images
43
+ images = []
49
44
 
50
- images.each(&block) if block_given?
45
+ 1.upto(pages) { |n|
46
+ dimensions = page_size(filename, n)
47
+ image = Image.new(filename, random_filename, n, dimensions, pages)
48
+ images << image
49
+ }
51
50
 
52
- return images
51
+ images.each(&block) if block_given?
53
52
 
54
- end
55
-
56
- # Executes the specified command, returning the output.
57
- #
58
- # @param [cmd] The command to run
59
- # @return [String] The output of the command
60
- def exec(cmd, error = nil)
61
- output = `#{cmd}`
62
- if $? != 0
63
- if error == nil
64
- raise PDFError, "Error executing command: #{cmd}"
65
- else
66
- raise PDFError, error
53
+ return images
67
54
  end
68
- end
69
55
 
70
- return output
71
- end
56
+ # Executes the specified command, returning the output.
57
+ #
58
+ # @param cmd [String] The command to run
59
+ # @return [String] The output of the command
60
+ def exec(cmd, error = nil)
61
+ output = `#{cmd}`
62
+ if $? != 0
63
+ if error == nil
64
+ raise PDFError, "Error executing command: #{cmd}"
65
+ else
66
+ raise PDFError, error
67
+ end
68
+ end
69
+
70
+ return output
71
+ end
72
72
 
73
- private
73
+ private
74
74
 
75
- def page_size(filename, page)
76
- cmd = "pdfinfo -f #{page} -l #{page} #{filename} | grep Page"
77
- output = exec(cmd)
75
+ def page_size(filename, page)
76
+ cmd = "pdfinfo -f #{page} -l #{page} #{filename} | grep Page"
77
+ output = exec(cmd)
78
78
 
79
- matches = /^Page.*?size:.*?(\d+).*?(\d+)/.match(output)
80
- if matches.nil?
81
- raise PDFError, "Unable to determine page size."
82
- end
79
+ matches = /^Page.*?size:.*?(\d+).*?(\d+)/.match(output)
80
+ if matches.nil?
81
+ raise PDFError, "Unable to determine page size."
82
+ end
83
83
 
84
- scale = 2.08333333333333333
85
- dimension = {
86
- :width => (matches[1].to_i * scale).to_i,
87
- :height => (matches[2].to_i * scale).to_i
88
- }
84
+ scale = 2.08333333333333333
85
+ dimension = {
86
+ width: (matches[1].to_i * scale).to_i,
87
+ height: (matches[2].to_i * scale).to_i
88
+ }
89
89
 
90
- dimension
91
- end
90
+ dimension
91
+ end
92
92
 
93
- def page_count(filename)
94
- cmd = "pdfinfo #{filename} | grep Pages"
95
- output = exec(cmd)
96
- matches = /^Pages:.*?(\d+)$/.match(output)
97
- if matches.nil?
98
- raise PDFError, "Error determining page count."
99
- end
93
+ def page_count(filename)
94
+ cmd = "pdfinfo #{filename} | grep Pages"
95
+ output = exec(cmd)
96
+ matches = /^Pages:.*?(\d+)$/.match(output)
97
+ if matches.nil?
98
+ raise PDFError, "Error determining page count."
99
+ end
100
100
 
101
- return matches[1].to_i
102
- end
101
+ return matches[1].to_i
102
+ end
103
103
 
104
- # Generate a random file name in the system's tmp folder
105
- def random_filename
106
- File.join(@@pdf_temp_dir, random_name)
107
- end
104
+ # Generate a random file name in the system's tmp folder
105
+ def random_filename
106
+ File.join(@@pdf_temp_dir, random_name)
107
+ end
108
108
 
109
- # Generate a random name of {#length} characters.
110
- def random_name(length = 15)
111
- @@chars ||= ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a
112
- return 'pdftoimage-' + Array.new(length, '').collect{@@chars[rand(@@chars.size)]}.join
109
+ # Generate a random name of {#length} characters.
110
+ def random_name(length = 15)
111
+ @@chars ||= ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a
112
+ return 'pdftoimage-' + Array.new(length, '').collect { @@chars[rand(@@chars.size)] }.join
113
+ end
113
114
  end
114
-
115
- end
116
-
117
115
  end
@@ -1,115 +1,116 @@
1
1
  module PDFToImage
2
-
3
- # A class which is instantiated by PDFToImage when a PDF document
4
- # is opened.
5
- class Image
6
- attr_reader :pdf_name
7
- attr_reader :filename
8
- attr_reader :width
9
- attr_reader :height
10
- attr_reader :page
11
- attr_reader :args
12
- attr_reader :opened
13
-
14
- # ImageMagick methods that we currently support.
15
- CUSTOM_IMAGE_METHODS = [
16
- "resize",
17
- "quality"
18
- ]
19
-
20
- CUSTOM_IMAGE_METHODS.each do |method|
21
- define_method(method.to_sym) do |*args|
22
- @args << "-#{method} #{args.join(' ')}"
23
-
24
- self
25
- end
26
- end
27
-
28
- # Image constructor
29
- #
30
- # @param [filename] The name of the image file to open
31
- def initialize(pdf_name, filename, page, page_size, page_count)
32
- @args = []
33
-
34
- @pdf_name = pdf_name
35
- @filename = filename
36
- @opened = false
37
- @width = page_size[:width]
38
- @height = page_size[:height]
39
- @page_count = page_count
40
-
41
- @page = page
42
- end
43
-
44
- # Saves the converted image to the specified location
45
- #
46
- # @param [outname] The output filename of the image
47
- #
48
- def save(outname)
49
-
50
- generate_temp_file
51
-
52
- cmd = "convert "
53
-
54
- if not @args.empty?
55
- cmd += "#{@args.join(' ')} "
56
- end
57
-
58
- cmd += "#{@filename} #{outname}"
59
-
60
- PDFToImage::exec(cmd)
61
-
62
- return true
63
- end
64
-
65
- def <=>(img)
66
- if @page == img.page
67
- return 0
68
- elsif @page < img.page
69
- return -1
70
- else
71
- return 1
72
- end
2
+ # A class which is instantiated by PDFToImage when a PDF document
3
+ # is opened.
4
+ class Image
5
+ attr_reader :pdf_name
6
+ attr_reader :filename
7
+ attr_reader :width
8
+ attr_reader :height
9
+ attr_reader :page
10
+ attr_reader :args
11
+ attr_reader :opened
12
+
13
+ # ImageMagick methods that we currently support.
14
+ CUSTOM_IMAGE_METHODS = [
15
+ "resize",
16
+ "quality"
17
+ ]
18
+
19
+ CUSTOM_IMAGE_METHODS.each do |method|
20
+ define_method(method.to_sym) do |*args|
21
+ @args << "-#{method} #{args.join(' ')}"
22
+
23
+ self
24
+ end
25
+ end
26
+
27
+ # Image constructor
28
+ #
29
+ # @param pdf_name [String] The name of the PDF
30
+ # @param filename [String] The name of the image for the specified page
31
+ # @param page [Integer] The page number of the PDF
32
+ # @param page_size [Hash] Hash containing width and height dimensions of the page
33
+ # @param page_count [integer] The number of pages in the PDF
34
+ #
35
+ def initialize(pdf_name, filename, page, page_size, page_count)
36
+ @args = []
37
+
38
+ @pdf_name = pdf_name
39
+ @filename = filename
40
+ @opened = false
41
+ @width = page_size[:width]
42
+ @height = page_size[:height]
43
+ @page_count = page_count
44
+
45
+ @page = page
46
+ end
47
+
48
+ # Saves the converted image to the specified location
49
+ #
50
+ # @param outname [String] The output filename of the image
51
+ #
52
+ def save(outname)
53
+ generate_temp_file
54
+
55
+ cmd = "convert "
56
+
57
+ if not @args.empty?
58
+ cmd += "#{@args.join(' ')} "
59
+ end
60
+
61
+ cmd += "#{@filename} #{outname}"
62
+
63
+ PDFToImage.exec(cmd)
64
+
65
+ return true
66
+ end
67
+
68
+ def <=>(img)
69
+ if @page == img.page
70
+ return 0
71
+ elsif @page < img.page
72
+ return -1
73
+ else
74
+ return 1
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def generate_temp_file
81
+ if @opened == false
82
+ cmd = "pdftoppm -png -f #{@page} -l #{@page} #{@pdf_name} #{@filename}"
83
+ PDFToImage.exec(cmd)
84
+ @filename = "#{@filename}-#{page_suffix}.png"
85
+ @opened = true
86
+ end
87
+
88
+ return true
89
+ end
90
+
91
+ def page_suffix
92
+ cur_page_len = @page.to_s.length
93
+ total_page_len = @page_count.to_s.length
94
+
95
+ num_zeroes = total_page_len - cur_page_len
96
+
97
+ # This is really weird. Basically, poppler_utils does not
98
+ # prepend a '0' to the page count when the total number of
99
+ # pages is 10, 100, 1000, 10000, etc. I hate putting this here,
100
+ # but whatever...
101
+
102
+ # TODO: Keep an eye on this. This suddenly started causing problems.
103
+ # Did poppler_utils change?
104
+ # if @page_count.to_s.reverse.to_i == 1 && num_zeroes > 0
105
+ # num_zeroes = num_zeroes - 1
106
+ # end
107
+
108
+ if cur_page_len == total_page_len
109
+ @page
110
+ end
111
+
112
+ padded = '0' * num_zeroes + @page.to_s
113
+ padded
114
+ end
73
115
  end
74
-
75
- private
76
-
77
- def generate_temp_file
78
- if @opened == false
79
- cmd = "pdftoppm -png -f #{@page} -l #{@page} #{@pdf_name} #{@filename}"
80
- PDFToImage::exec(cmd)
81
- @filename = "#{@filename}-#{page_suffix}.png"
82
- @opened = true
83
- end
84
-
85
- return true
86
- end
87
-
88
- def page_suffix
89
- cur_page_len = @page.to_s.length
90
- total_page_len = @page_count.to_s.length
91
-
92
- num_zeroes = total_page_len - cur_page_len
93
-
94
- # This is really weird. Basically, poppler_utils does not
95
- # prepend a '0' to the page count when the total number of
96
- # pages is 10, 100, 1000, 10000, etc. I hate putting this here,
97
- # but whatever...
98
-
99
- # TODO: Keep an eye on this. This suddenly started causing problems.
100
- # Did poppler_utils change?
101
- # if @page_count.to_s.reverse.to_i == 1 && num_zeroes > 0
102
- # num_zeroes = num_zeroes - 1
103
- # end
104
-
105
- if cur_page_len == total_page_len
106
- @page
107
- end
108
-
109
- padded = '0' * num_zeroes + @page.to_s
110
- padded
111
- end
112
-
113
- end
114
-
115
116
  end
@@ -1,4 +1,4 @@
1
1
  module PDFToImage
2
- # pdftoimage version
3
- VERSION = "0.1.6"
2
+ # pdftoimage version
3
+ VERSION = "0.1.7"
4
4
  end
metadata CHANGED
@@ -1,99 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pdftoimage
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Rob Flynn
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-07-13 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: bundler
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: iconv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
18
21
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
22
- - - ~>
23
- - !ruby/object:Gem::Version
24
- version: 1.0.0
25
- type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: yard
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
33
- - - ~>
34
- - !ruby/object:Gem::Version
35
- version: 0.6.0
36
- type: :development
37
- version_requirements: *id002
38
- description: A ruby gem for converting PDF documents into a series of images. This module is based off poppler_utils and ImageMagick.
39
- email:
40
- - rob@thingerly.com
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: A ruby gem for converting PDF documents into a series of images. This
28
+ module is based off poppler_utils and ImageMagick.
29
+ email: rob@thingerly.com
41
30
  executables: []
42
-
43
31
  extensions: []
44
-
45
- extra_rdoc_files:
46
- - README.rdoc
47
- - ChangeLog.rdoc
48
- - LICENSE.txt
49
- files:
50
- - .bundle/config
51
- - .document
52
- - .rspec
53
- - .yardopts
32
+ extra_rdoc_files: []
33
+ files:
54
34
  - ChangeLog.rdoc
55
- - Gemfile
56
- - Gemfile.lock
57
- - LICENSE.txt
35
+ - LICENSE
58
36
  - README.rdoc
59
- - Rakefile
60
- - gemspec.yml
61
37
  - lib/pdftoimage.rb
62
38
  - lib/pdftoimage/image.rb
63
39
  - lib/pdftoimage/version.rb
64
- - pdftoimage.gemspec
65
- - spec/10pages.pdf
66
- - spec/11pages.pdf
67
- - spec/3pages.pdf
68
- - spec/pdftoimage_spec.rb
69
- - spec/spec_helper.rb
70
- has_rdoc: yard
71
40
  homepage: https://github.com/robflynn/pdftoimage
72
- licenses:
41
+ licenses:
73
42
  - MIT
43
+ metadata:
44
+ changelog_uri: https://github.com/robflynn/pdftoimage/blob/master/ChangeLog.rdoc
45
+ source_code_uri: https://github.com/robflynn/pdftoimage/
74
46
  post_install_message:
75
47
  rdoc_options: []
76
-
77
- require_paths:
48
+ require_paths:
78
49
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
80
- none: false
81
- requirements:
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
82
52
  - - ">="
83
- - !ruby/object:Gem::Version
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
88
57
  - - ">="
89
- - !ruby/object:Gem::Version
90
- version: 1.3.6
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
91
60
  requirements: []
92
-
93
- rubyforge_project: pdftoimage
94
- rubygems_version: 1.6.2
61
+ rubyforge_project:
62
+ rubygems_version: 2.6.14.1
95
63
  signing_key:
96
- specification_version: 3
64
+ specification_version: 4
97
65
  summary: A ruby gem for converting PDF documents into a series of images.
98
- test_files:
99
- - spec/pdftoimage_spec.rb
66
+ test_files: []
@@ -1,2 +0,0 @@
1
- --- {}
2
-
data/.document DELETED
@@ -1,3 +0,0 @@
1
- -
2
- ChangeLog.*
3
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour --format documentation
data/.yardopts DELETED
@@ -1 +0,0 @@
1
- --markup rdoc --title "pdftoimage Documentation" --protected
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rake', '~> 0.8.7'
7
- gem 'ore-core', '~> 0.1.0'
8
- gem 'rspec', '>= 2.1.0'
9
- gem 'yard', '~> 0.6.0'
10
- gem 'autotest'
11
- gem 'spork'
12
- end
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- pdftoimage (0.1.6)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- autotest (4.4.4)
10
- diff-lcs (1.1.2)
11
- ore-core (0.1.5)
12
- rake (0.8.7)
13
- rspec (2.1.0)
14
- rspec-core (~> 2.1.0)
15
- rspec-expectations (~> 2.1.0)
16
- rspec-mocks (~> 2.1.0)
17
- rspec-core (2.1.0)
18
- rspec-expectations (2.1.0)
19
- diff-lcs (~> 1.1.2)
20
- rspec-mocks (2.1.0)
21
- spork (0.8.4)
22
- yard (0.6.2)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- autotest
29
- bundler (~> 1.0.0)
30
- ore-core (~> 0.1.0)
31
- pdftoimage!
32
- rake (~> 0.8.7)
33
- rspec (>= 2.1.0)
34
- spork
35
- yard (~> 0.6.0)
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- require 'rubygems'
2
-
3
- begin
4
- require 'bundler'
5
- rescue LoadError => e
6
- STDERR.puts e.message
7
- STDERR.puts "Run `gem install bundler` to install Bundler."
8
- exit e.status_code
9
- end
10
-
11
- begin
12
- Bundler.setup(:development)
13
- rescue Bundler::BundlerError => e
14
- STDERR.puts e.message
15
- STDERR.puts "Run `bundle install` to install missing gems."
16
- exit e.status_code
17
- end
18
-
19
- require 'rake'
20
-
21
- require 'rspec/core/rake_task'
22
- RSpec::Core::RakeTask.new
23
- task :default => :spec
24
-
25
- require 'yard'
26
- YARD::Rake::YardocTask.new
@@ -1,13 +0,0 @@
1
- name: pdftoimage
2
- summary: "A ruby gem for converting PDF documents into a series of images."
3
- description: "A ruby gem for converting PDF documents into a series of images. This module is based off poppler_utils and ImageMagick."
4
- license: MIT
5
- authors: Rob Flynn
6
- homepage: https://github.com/robflynn/pdftoimage
7
- email: rob@thingerly.com
8
- has_yard: true
9
-
10
- development_dependencies:
11
- bundler: ~> 1.0.0
12
- yard: ~> 0.6.0
13
-
@@ -1,15 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- begin
4
- Ore::Specification.new do |gemspec|
5
- # custom logic here
6
- end
7
- rescue NameError
8
- begin
9
- require 'ore/specification'
10
- retry
11
- rescue LoadError
12
- STDERR.puts "The 'my-project.gemspec' file requires Ore."
13
- STDERR.puts "Run `gem install ore-core` to install Ore."
14
- end
15
- end
Binary file
Binary file
Binary file
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
- require 'pdftoimage'
3
-
4
- describe PDFToImage do
5
- it "should have a VERSION constant" do
6
- PDFToImage.const_get('VERSION').should_not be_empty
7
- end
8
-
9
- # I will find a better solution for having this commented out. I do not
10
- # have permission to release the document that I used for this test case.
11
- # I will generate a sufficiently buggy version. Basically, buggy PDF software
12
- # sometimes corrupts CreationDate and/or ModDate such as discussed here: http://www.linuxquestions.org/questions/solaris-opensolaris-20/converting-utf-16-files-to-another-encoding-such-as-utf-8-a-630588/
13
- # I also need to come upw ith a better solution
14
-
15
- # describe "edge cases" do
16
- # it "should handle invalid utf-8 in headers without crashing" do
17
- # @pages = PDFToImage.open('spec/weird_utf8.pdf')
18
- # @pages.size.should equal 1
19
- # @pages[0].resize('50%').save('spec/tmp1.jpg')
20
- # File.exists?('spec/tmp1.jpg').should equal true
21
- # File.unlink('spec/tmp1.jpg')
22
- # end
23
- # end
24
-
25
- describe "3pages.pdf" do
26
- it "should have three pages" do
27
- @pages = PDFToImage.open('spec/3pages.pdf')
28
- @pages.size.should equal 3
29
- end
30
-
31
- it "should allow saving" do
32
- @pages = PDFToImage.open('spec/3pages.pdf')
33
- @pages.each do |page|
34
- page.save('spec/tmp.jpg')
35
- File.exists?('spec/tmp.jpg').should equal true
36
- File.unlink('spec/tmp.jpg')
37
- end
38
- end
39
-
40
- it "should allow resizing and quality control" do
41
- @pages = PDFToImage.open('spec/3pages.pdf')
42
- @pages[0].resize('50%').quality('80%').save('spec/tmp2.jpg')
43
- File.exists?('spec/tmp2.jpg').should equal true
44
- File.unlink('spec/tmp2.jpg')
45
- end
46
-
47
- it "should work with blocks" do
48
- counter = 0
49
- PDFToImage.open("spec/3pages.pdf") do |page|
50
- counter = counter + 1
51
- end
52
- counter.should equal 3
53
- end
54
- end
55
-
56
- describe "multi page documents" do
57
- it "should parse 10 page documents properly" do
58
- counter = 0
59
- PDFToImage.open('spec/10pages.pdf') do |page|
60
- result = page.save("spec/10pg-#{page.page}.jpg")
61
- File.exists?("spec/10pg-#{page.page}.jpg").should equal true
62
- File.unlink("spec/10pg-#{page.page}.jpg")
63
- counter = counter + 1
64
- end
65
-
66
- counter.should equal 10
67
- end
68
-
69
- it "should parse 11 page counts" do
70
- counter = 0
71
- PDFToImage.open('spec/11pages.pdf') do |page|
72
- result = page.save("spec/11pg-#{page.page}.jpg")
73
- File.exists?("spec/11pg-#{page.page}.jpg").should equal true
74
- File.unlink("spec/11pg-#{page.page}.jpg")
75
- counter = counter + 1
76
- end
77
-
78
- counter.should equal 11
79
- end
80
-
81
-
82
- end
83
- end
@@ -1,13 +0,0 @@
1
- require 'rubygems'
2
- require 'spork'
3
-
4
- Spork.prefork do
5
- require 'rspec'
6
- require 'pdftoimage/version'
7
-
8
- include PDFToImage
9
- end
10
-
11
- Spork.each_run do
12
- end
13
-