dragonfly_pdf 2.1.0 → 2.2.2

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/lib/dragonfly_pdf/analysers/pdf_properties.rb +41 -12
  4. data/lib/dragonfly_pdf/processors/append.rb +3 -2
  5. data/lib/dragonfly_pdf/processors/convert.rb +9 -8
  6. data/lib/dragonfly_pdf/processors/page.rb +3 -2
  7. data/lib/dragonfly_pdf/processors/page_thumb.rb +3 -2
  8. data/lib/dragonfly_pdf/processors/remove_password.rb +3 -2
  9. data/lib/dragonfly_pdf/processors/rotate.rb +3 -2
  10. data/lib/dragonfly_pdf/processors/stamp.rb +3 -2
  11. data/lib/dragonfly_pdf/processors/subset_fonts.rb +3 -2
  12. data/lib/dragonfly_pdf/version.rb +1 -1
  13. data/lib/dragonfly_pdf.rb +11 -1
  14. metadata +9 -43
  15. data/.gitignore +0 -23
  16. data/.travis.yml +0 -28
  17. data/Gemfile +0 -4
  18. data/Guardfile +0 -8
  19. data/LICENSE +0 -21
  20. data/dragonfly_pdf.gemspec +0 -31
  21. data/samples/sample_pages.pdf +0 -0
  22. data/samples/sample_pages_rotated.pdf +0 -0
  23. data/samples/sample_pages_with_bleed.pdf +0 -0
  24. data/samples/sample_pages_with_password.pdf +0 -0
  25. data/samples/sample_stamp.pdf +0 -0
  26. data/test/dragonfly_pdf/analysers/pdf_properties_test.rb +0 -16
  27. data/test/dragonfly_pdf/plugin_test.rb +0 -30
  28. data/test/dragonfly_pdf/processors/append_test.rb +0 -16
  29. data/test/dragonfly_pdf/processors/convert_test.rb +0 -25
  30. data/test/dragonfly_pdf/processors/page_test.rb +0 -19
  31. data/test/dragonfly_pdf/processors/page_thumb_test.rb +0 -27
  32. data/test/dragonfly_pdf/processors/remove_password_test.rb +0 -15
  33. data/test/dragonfly_pdf/processors/rotate_test.rb +0 -22
  34. data/test/dragonfly_pdf/processors/stamp_test.rb +0 -18
  35. data/test/dragonfly_pdf/processors/subset_fonts_test.rb +0 -17
  36. data/test/test_helper.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76f9364c0e260943bd144490065c03b31df16566dfc5edfbdfb8a43a201a5bd7
4
- data.tar.gz: 9d632fb7d1f1d52bae8f2be9b1aabc850d6f2581fdb0ef3502bb1d408df200f1
3
+ metadata.gz: 82ce144970343c6de53384e1b1cf1a6c1844d25007c9afda222fcdc1105db747
4
+ data.tar.gz: 5467a0f818a38d111edd3045e5a6d7b022f1c6926d540b30fbc1b2a2fa1efae2
5
5
  SHA512:
6
- metadata.gz: 40d25571ea32a0b72e253cfd3db2efed9fa22d4e1d7cfc06a5d53101887f3cb058ecc28d9c2445561842a89c062434b9b632d3d075667b7c2cdeb17d089eab73
7
- data.tar.gz: a7c119532f70acbd4b0dad5e329aacc9ab0cfb5ae5750f21742837b98d799225904c33017c03ac81c80fee0f6c3e3fdb0c989c1086ce72af3558bf0495c7fa6c
6
+ metadata.gz: b55595af48d2d58bff454245b96c3c0362388c26ec902603e31189444339f95d5ecf7d3b5d3f3c9d8163913080b02fa9c2b71c5e4468a5e228da5624df94b279
7
+ data.tar.gz: 8c744fca929302ca9c7a8d592a8c9faff67de7fee5af373ad40650f8e1e37d7e142201ff53bb5ee90add7339eba67f00c0a7d6c294a08cbd5dee40b7dee183f8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## Next
4
+
5
+ ## 2.2.2
6
+
7
+ * removed `tga` from `SUPPORTED_OUTPUT_FORMATS`
8
+ * fixed `page_dimensions` calculation for sizes larger than 1000 pts
9
+
10
+ ## 2.2.1
11
+
12
+ * all paths in quotes
13
+
14
+ ## 2.2.0
15
+
16
+ * upgrade `dragonfly_libvips` to `~> 2.4.0`
17
+ * symbolize keys passed to `ruby-vips`
18
+
19
+ ## 2.1.1
20
+
21
+ * improved `SUPPORTED_FORMATS` matching that ignores case
22
+
3
23
  ## 2.1.0
4
24
 
5
25
  * add `SUPPORTED_FORMATS` and `SUPPORTED_OUTPUT_FORMATS` and raise errors when formats are not matching
@@ -1,34 +1,63 @@
1
1
  module DragonflyPdf
2
2
  module Analysers
3
3
  class PdfProperties
4
+ NUMBER_OF_PAGES_REGEX = /NumberOfPages:\s*(\d+)/
5
+ PAGE_MEDIA_NUMBER_REGEX = /PageMediaNumber:\s*(\d+)/
6
+ PAGE_MEDIA_DIMENSIONS_REGEX = /PageMediaDimensions:\s*(\d+\,?\d+\.?\d+)\s*(\d+\,?\d+\.?\d+)/
7
+ PAGE_MEDIA_ROTATIONS_REGEX = /PageMediaRotation:\s*(\d+)/
8
+
4
9
  def call(content, options = {})
5
- return {} unless SUPPORTED_FORMATS.include?(content.ext)
10
+ return {} unless content.ext
11
+ return {} unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
12
 
7
- data = `pdftk #{content.path} dump_data`
13
+ data = `pdftk "#{content.path}" dump_data`
8
14
 
9
- page_count = data.scan(/NumberOfPages: (\d+)/).flatten.first.to_i
10
- page_numbers = data.scan(/PageMediaNumber: (\d+)/).flatten.map(&:to_i)
11
- page_dimensions = data.scan(/PageMediaDimensions:\s*(\d+\.?\d+)\s*(\d+\.?\d+)/).map do |width_height|
12
- width_height.map(&:to_f).map { |dim| pt2mm(dim) }
13
- end
14
- page_rotations = data.scan(/PageMediaRotation: (\d+)/).flatten.map(&:to_f)
15
- aspect_ratios = page_dimensions.inject([]) { |res, page| res << (page.first / page.last) }
15
+ page_count = extract_page_count(data)
16
+ page_numbers = extract_page_numbers(data)
17
+ page_dimensions = extract_page_dimensions(data)
18
+ page_rotations = extract_page_rotations(data)
19
+ aspect_ratios = calculate_aspect_ratios(page_dimensions)
16
20
 
17
21
  {
18
- 'format' => content.ext.downcase,
19
22
  'aspect_ratios' => aspect_ratios,
23
+ 'format' => content.ext.downcase,
20
24
  'page_count' => page_count,
21
25
  'page_dimensions' => page_dimensions,
22
26
  'page_numbers' => page_numbers,
23
- 'page_rotations' => page_rotations
27
+ 'page_rotations' => page_rotations,
24
28
  }
25
29
  end
26
30
 
27
31
  private
28
32
 
29
- def pt2mm(pt)
33
+ def extract_page_count(data)
34
+ data.scan(NUMBER_OF_PAGES_REGEX).flatten.first.to_i
35
+ end
36
+
37
+ def extract_page_numbers(data)
38
+ data.scan(PAGE_MEDIA_NUMBER_REGEX).flatten.map(&:to_i)
39
+ end
40
+
41
+ def extract_page_dimensions(data)
42
+ data.scan(PAGE_MEDIA_DIMENSIONS_REGEX).map do |width, height|
43
+ [pt_to_mm(width), pt_to_mm(height)]
44
+ end
45
+ end
46
+
47
+ def pt_to_mm(length)
48
+ pt = length.gsub(",", "").to_f
30
49
  (pt / 72.0) * 25.4
31
50
  end
51
+
52
+ def extract_page_rotations(data)
53
+ data.scan(PAGE_MEDIA_ROTATIONS_REGEX).flatten.map(&:to_f)
54
+ end
55
+
56
+ def calculate_aspect_ratios(page_dimensions)
57
+ page_dimensions.map do |width, height|
58
+ width / height.to_f
59
+ end
60
+ end
32
61
  end
33
62
  end
34
63
  end
@@ -2,10 +2,11 @@ module DragonflyPdf
2
2
  module Processors
3
3
  class Append
4
4
  def call(content, pdfs_to_append, options = {})
5
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
5
+ raise UnsupportedFormat unless content.ext
6
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
7
 
7
8
  content.shell_update(ext: 'pdf') do |old_path, new_path|
8
- "#{pdftk_command} #{old_path} #{pdfs_to_append.map(&:path).join(' ')} cat output #{new_path}"
9
+ "#{pdftk_command} \"#{old_path}\" #{pdfs_to_append.map(&:path).join(' ')} cat output \"#{new_path}\""
9
10
  end
10
11
  end
11
12
 
@@ -7,26 +7,27 @@ module DragonflyPdf
7
7
  DPI = 600
8
8
 
9
9
  def call(content, page, geometry = nil, options = {})
10
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
10
+ raise UnsupportedFormat unless content.ext
11
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
11
12
 
12
- options = options.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
13
+ options = DragonflyPdf.stringify_keys(options)
13
14
  format = options.fetch('format', 'png').to_s
14
15
 
15
- raise UnsupportedOutputFormat unless SUPPORTED_OUTPUT_FORMATS.include?(format)
16
+ raise UnsupportedOutputFormat unless SUPPORTED_OUTPUT_FORMATS.include?(format.downcase)
16
17
 
17
18
  case format
18
19
  when 'pdf'
19
20
  pdf_options = options.fetch('pdf_options', 'compress,compress-fonts,compress-images,linearize,sanitize,garbage=deduplicate')
20
21
 
21
22
  content.shell_update(ext: format) do |old_path, new_path|
22
- "#{convert_command} -o #{new_path} -F #{format} -O #{pdf_options} #{old_path} #{page}"
23
+ "#{convert_command} -o \"#{new_path}\" -F #{format} -O #{pdf_options} \"#{old_path}\" #{page}"
23
24
  end
24
25
 
25
26
  when 'svg'
26
27
  text = options.fetch('text', 'path')
27
28
 
28
29
  content.shell_update(ext: format) do |old_path, new_path|
29
- "#{convert_command} -o #{new_path} -F #{format} -O text=#{text} #{old_path} #{page}"
30
+ "#{convert_command} -o \"#{new_path}\" -F #{format} -O text=#{text} \"#{old_path}\" #{page}"
30
31
  end
31
32
 
32
33
  # MuPDF appends 1 at the end of the filename, we need to rename it back
@@ -37,7 +38,7 @@ module DragonflyPdf
37
38
  input_options['access'] = input_options.fetch('access', 'sequential')
38
39
  input_options['dpi'] = input_options.fetch('dpi', DPI)
39
40
 
40
- img = ::Vips::Image.new_from_file(content.path, input_options)
41
+ img = ::Vips::Image.new_from_file(content.path, DragonflyPdf.symbolize_keys(input_options))
41
42
 
42
43
  dimensions = case geometry
43
44
  when DragonflyLibvips::Processors::Thumb::RESIZE_GEOMETRY
@@ -49,11 +50,11 @@ module DragonflyPdf
49
50
  width = dimensions.width.ceil
50
51
 
51
52
  content.shell_update(ext: format) do |old_path, new_path|
52
- "#{convert_command} -o #{new_path} -F #{format} -O width=#{width},colorspace=rgb #{old_path} #{page}"
53
+ "#{convert_command} -o \"#{new_path}\" -F #{format} -O width=#{width},colorspace=rgb \"#{old_path}\" #{page}"
53
54
  end
54
55
 
55
56
  # MuPDF appends 1 at the end of the filename, we need to rename it back
56
- `mv #{content.path.sub(".#{format}", "1.#{format}")} #{content.path}`
57
+ `mv \"#{content.path.sub(".#{format}", "1.#{format}")}\" \"#{content.path}\"`
57
58
  end
58
59
 
59
60
  content.meta['format'] = format
@@ -4,13 +4,14 @@ module DragonflyPdf
4
4
  module Processors
5
5
  class Page
6
6
  def call(content, page_number = 1, _opts = {})
7
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
7
+ raise UnsupportedFormat unless content.ext
8
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
8
9
 
9
10
  pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
10
11
  raise DragonflyPdf::PageNotFound unless pdf_properties['page_numbers'].include?(page_number)
11
12
 
12
13
  content.shell_update(ext: 'pdf') do |old_path, new_path|
13
- "#{gs_command} -dFirstPage=#{page_number} -dLastPage=#{page_number} -o #{new_path} -f #{old_path}"
14
+ "#{gs_command} -dFirstPage=#{page_number} -dLastPage=#{page_number} -o \"#{new_path}\" -f \"#{old_path}\""
14
15
  end
15
16
  end
16
17
 
@@ -2,9 +2,10 @@ module DragonflyPdf
2
2
  module Processors
3
3
  class PageThumb
4
4
  def call(content, page, geometry = nil, options = {})
5
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
5
+ raise UnsupportedFormat unless content.ext
6
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
7
 
7
- options = options.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
8
+ options = DragonflyPdf.stringify_keys(options)
8
9
  format = options.delete('format') { 'jpg' }.to_s
9
10
 
10
11
  convert(content, page, geometry, format)
@@ -2,10 +2,11 @@ module DragonflyPdf
2
2
  module Processors
3
3
  class RemovePassword
4
4
  def call(content, _options = {})
5
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
5
+ raise UnsupportedFormat unless content.ext
6
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
7
 
7
8
  content.shell_update(ext: 'pdf') do |old_path, new_path|
8
- "#{gs_command} -q -sOutputFile=#{new_path} -c .setpdfwrite -f #{old_path}"
9
+ "#{gs_command} -q -sOutputFile=\"#{new_path}\" -c .setpdfwrite -f \"#{old_path}\""
9
10
  end
10
11
  end
11
12
 
@@ -2,7 +2,8 @@ module DragonflyPdf
2
2
  module Processors
3
3
  class Rotate
4
4
  def call(content, arg)
5
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
5
+ raise UnsupportedFormat unless content.ext
6
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
7
 
7
8
  rotate_args = case arg
8
9
  when String, Symbol
@@ -14,7 +15,7 @@ module DragonflyPdf
14
15
  end
15
16
 
16
17
  content.shell_update(ext: 'pdf') do |old_path, new_path|
17
- "#{pdftk_command} #{old_path} cat #{rotate_args} output #{new_path}"
18
+ "#{pdftk_command} \"#{old_path}\" cat #{rotate_args} output #{new_path}"
18
19
  end
19
20
  end
20
21
 
@@ -2,10 +2,11 @@ module DragonflyPdf
2
2
  module Processors
3
3
  class Stamp
4
4
  def call(content, stamp_pdf, _options = {})
5
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
5
+ raise UnsupportedFormat unless content.ext
6
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
7
 
7
8
  content.shell_update(ext: 'pdf') do |old_path, new_path|
8
- "#{pdftk_command} #{old_path} stamp #{stamp_pdf.path} output #{new_path}"
9
+ "#{pdftk_command} \"#{old_path}\" stamp \"#{stamp_pdf.path}\" output \"#{new_path}\""
9
10
  end
10
11
  end
11
12
 
@@ -2,10 +2,11 @@ module DragonflyPdf
2
2
  module Processors
3
3
  class SubsetFonts
4
4
  def call(content, _opts = {})
5
- raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext)
5
+ raise UnsupportedFormat unless content.ext
6
+ raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
6
7
 
7
8
  content.shell_update(ext: 'pdf') do |old_path, new_path|
8
- "#{gs_command} -o #{new_path} -f #{old_path}"
9
+ "#{gs_command} -o \"#{new_path}\" -f \"#{old_path}\""
9
10
  end
10
11
  end
11
12
 
@@ -1,3 +1,3 @@
1
1
  module DragonflyPdf
2
- VERSION = '2.1.0'.freeze
2
+ VERSION = '2.2.2'.freeze
3
3
  end
data/lib/dragonfly_pdf.rb CHANGED
@@ -8,5 +8,15 @@ module DragonflyPdf
8
8
  class UnsupportedFormat < RuntimeError; end
9
9
 
10
10
  SUPPORTED_FORMATS = %w[pdf].freeze
11
- SUPPORTED_OUTPUT_FORMATS = %w[png pam pbm pkm pnm pdf tga svg].uniq.sort
11
+ SUPPORTED_OUTPUT_FORMATS = %w[png pam pbm pkm pnm pdf svg].uniq.sort
12
+
13
+ private
14
+
15
+ def self.stringify_keys(hash = {})
16
+ hash.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v }
17
+ end
18
+
19
+ def self.symbolize_keys(hash = {})
20
+ hash.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v }
21
+ end
12
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-14 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.0
33
+ version: 2.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.0
40
+ version: 2.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -143,15 +143,9 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".gitignore"
147
- - ".travis.yml"
148
146
  - CHANGELOG.md
149
- - Gemfile
150
- - Guardfile
151
- - LICENSE
152
147
  - README.md
153
148
  - Rakefile
154
- - dragonfly_pdf.gemspec
155
149
  - lib/dragonfly_pdf.rb
156
150
  - lib/dragonfly_pdf/analysers/pdf_properties.rb
157
151
  - lib/dragonfly_pdf/plugin.rb
@@ -164,27 +158,11 @@ files:
164
158
  - lib/dragonfly_pdf/processors/stamp.rb
165
159
  - lib/dragonfly_pdf/processors/subset_fonts.rb
166
160
  - lib/dragonfly_pdf/version.rb
167
- - samples/sample_pages.pdf
168
- - samples/sample_pages_rotated.pdf
169
- - samples/sample_pages_with_bleed.pdf
170
- - samples/sample_pages_with_password.pdf
171
- - samples/sample_stamp.pdf
172
- - test/dragonfly_pdf/analysers/pdf_properties_test.rb
173
- - test/dragonfly_pdf/plugin_test.rb
174
- - test/dragonfly_pdf/processors/append_test.rb
175
- - test/dragonfly_pdf/processors/convert_test.rb
176
- - test/dragonfly_pdf/processors/page_test.rb
177
- - test/dragonfly_pdf/processors/page_thumb_test.rb
178
- - test/dragonfly_pdf/processors/remove_password_test.rb
179
- - test/dragonfly_pdf/processors/rotate_test.rb
180
- - test/dragonfly_pdf/processors/stamp_test.rb
181
- - test/dragonfly_pdf/processors/subset_fonts_test.rb
182
- - test/test_helper.rb
183
161
  homepage: https://github.com/tomasc/dragonfly_pdf
184
162
  licenses:
185
163
  - MIT
186
164
  metadata: {}
187
- post_install_message:
165
+ post_install_message:
188
166
  rdoc_options: []
189
167
  require_paths:
190
168
  - lib
@@ -199,20 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
177
  - !ruby/object:Gem::Version
200
178
  version: '0'
201
179
  requirements: []
202
- rubyforge_project:
203
- rubygems_version: 2.7.6
204
- signing_key:
180
+ rubygems_version: 3.1.6
181
+ signing_key:
205
182
  specification_version: 4
206
183
  summary: Dragonfly PDF analysers and processors.
207
- test_files:
208
- - test/dragonfly_pdf/analysers/pdf_properties_test.rb
209
- - test/dragonfly_pdf/plugin_test.rb
210
- - test/dragonfly_pdf/processors/append_test.rb
211
- - test/dragonfly_pdf/processors/convert_test.rb
212
- - test/dragonfly_pdf/processors/page_test.rb
213
- - test/dragonfly_pdf/processors/page_thumb_test.rb
214
- - test/dragonfly_pdf/processors/remove_password_test.rb
215
- - test/dragonfly_pdf/processors/rotate_test.rb
216
- - test/dragonfly_pdf/processors/stamp_test.rb
217
- - test/dragonfly_pdf/processors/subset_fonts_test.rb
218
- - test/test_helper.rb
184
+ test_files: []
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- dragonfly.log
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- script: 'bundle exec rake'
4
- sudo: required
5
- dist: trusty
6
- rvm:
7
- - 2.2.5
8
-
9
- before_install:
10
- - gem update bundler
11
- - sudo add-apt-repository -y ppa:ubuntuhandbook1/apps
12
- - sudo apt-get update
13
- - sudo apt-get install -y pdftk
14
- - sudo apt-get install -y ghostscript
15
- - curl -OL https://mupdf.com/downloads/mupdf-1.13.0-source.tar.gz
16
- - tar zvxf mupdf-1.13.0-source.tar.gz && cd mupdf-1.13.0-source && sudo make HAVE_X11=no HAVE_GLUT=no prefix=/usr/local install
17
- - sudo apt-get install -y gobject-introspection libgirepository1.0-dev libglib2.0-dev libpoppler-glib-dev
18
- - curl -OL https://github.com/jcupitt/libvips/releases/download/v8.5.8/vips-8.5.8.tar.gz
19
- - tar zvxf vips-8.5.8.tar.gz && cd vips-8.5.8 && ./configure && sudo make && sudo make install
20
- - export GI_TYPELIB_PATH=/usr/local/lib/girepository-1.0/
21
- - sudo ldconfig
22
-
23
- notifications:
24
- email:
25
- recipients:
26
- - tomas.celizna@gmail.com
27
- on_failure: change
28
- on_success: never
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in dragonfly_pdf.gemspec
4
- gemspec
data/Guardfile DELETED
@@ -1,8 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard :minitest do
5
- watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
6
- watch(%r{^test/.+_test\.rb$})
7
- watch(%r{^test/test_helper\.rb$}) { 'test' }
8
- end
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Tomas Celizna
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,31 +0,0 @@
1
-
2
- lib = File.expand_path('lib', __dir__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'dragonfly_pdf/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'dragonfly_pdf'
8
- spec.version = DragonflyPdf::VERSION
9
- spec.authors = ['Tomas Celizna']
10
- spec.email = ['tomas.celizna@gmail.com']
11
- spec.summary = 'Dragonfly PDF analysers and processors.'
12
- spec.description = 'Dragonfly PDF analysers and processors.'
13
- spec.homepage = 'https://github.com/tomasc/dragonfly_pdf'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_dependency 'dragonfly', '~> 1.0'
22
- spec.add_dependency 'dragonfly_libvips', '~> 2.2.0'
23
-
24
- spec.add_development_dependency 'bundler', '~> 1.12'
25
- spec.add_development_dependency 'guard'
26
- spec.add_development_dependency 'guard-minitest'
27
- spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'minitest-reporters'
29
- spec.add_development_dependency 'rake', '~> 10.0'
30
- spec.add_development_dependency 'pdf-reader'
31
- end
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Analysers::PdfProperties do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:analyser) { DragonflyPdf::Analysers::PdfProperties.new }
6
- let(:sample_pages) { app.fetch_file(SAMPLES_DIR.join('sample_pages.pdf')) }
7
- let(:sample_pages_with_bleed) { app.fetch_file(SAMPLES_DIR.join('sample_pages_with_bleed.pdf')) }
8
- let(:sample_pages_rotated) { app.fetch_file(SAMPLES_DIR.join('sample_pages_rotated.pdf')) }
9
-
10
- it { analyser.call(sample_pages).must_be_kind_of Hash }
11
- it { analyser.call(sample_pages)['page_numbers'].must_equal (1..10).to_a }
12
- it { analyser.call(sample_pages)['page_count'].must_equal 10 }
13
- it { analyser.call(sample_pages)['page_dimensions'].map { |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(10) }
14
- it { analyser.call(sample_pages)['aspect_ratios'].map { |i| i.round(2) }.must_equal [0.71].cycle.take(10) }
15
- it { analyser.call(sample_pages_rotated)['page_rotations'].must_equal [0.0, 90.0, 180.0, 270.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] }
16
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- module DragonflyPdf
4
- describe Plugin do
5
- let(:app) { test_app.configure_with(:pdf) }
6
- let(:content) { app.fetch_file(SAMPLES_DIR.join('sample_pages.pdf')) }
7
-
8
- describe 'analysers' do
9
- it { content.must_respond_to :pdf_properties }
10
- it { content.pdf_properties.must_be_kind_of Hash }
11
- it { content.must_respond_to :page_count }
12
- it { content.must_respond_to :page_numbers }
13
- it { content.must_respond_to :page_dimensions }
14
- it { content.must_respond_to :aspect_ratios }
15
- it { content.must_respond_to :page_rotations }
16
- end
17
-
18
- describe 'processors' do
19
- it { content.must_respond_to :append }
20
- it { content.must_respond_to :convert }
21
- it { content.must_respond_to :encode }
22
- it { content.must_respond_to :page }
23
- it { content.must_respond_to :page_thumb }
24
- it { content.must_respond_to :remove_password }
25
- it { content.must_respond_to :rotate }
26
- it { content.must_respond_to :stamp }
27
- it { content.must_respond_to :subset_fonts }
28
- end
29
- end
30
- end
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::Append do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:processor) { DragonflyPdf::Processors::Append.new }
6
- let(:content_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
7
- let(:content_2) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages_with_bleed.pdf')) }
8
-
9
- before { processor.call(content_1, [content_2]) }
10
-
11
- it { content_1.analyse(:page_count).must_equal 11 }
12
-
13
- describe 'tempfile has extension' do
14
- it { content_1.tempfile.path.must_match /\.pdf\z/ }
15
- end
16
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::Convert do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:processor) { DragonflyPdf::Processors::Convert.new }
6
- let(:content) { app.fetch_file SAMPLES_DIR.join('sample_pages.pdf') }
7
-
8
- describe 'SUPPORTED_OUTPUT_FORMATS' do
9
- DragonflyPdf::SUPPORTED_OUTPUT_FORMATS.each do |format|
10
- it(format) do
11
- result = content.convert(1, '600x', format: format)
12
- result.ext.must_equal format
13
- result.mime_type.must_equal Rack::Mime.mime_type(".#{format}")
14
- result.size.must_be :>, 0
15
- result.tempfile.path.must_match /\.#{format}\z/
16
- end
17
- end
18
- end
19
-
20
- describe 'url' do
21
- let (:url_attributes) { OpenStruct.new }
22
- before { processor.update_url(url_attributes, 1) }
23
- it { url_attributes.ext.must_equal 'png' }
24
- end
25
- end
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::Page do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
6
- let(:processor) { DragonflyPdf::Processors::Page.new }
7
-
8
- it { proc { processor.call(content, 0) }.must_raise DragonflyPdf::PageNotFound }
9
- it { proc { processor.call(content, 11) }.must_raise DragonflyPdf::PageNotFound }
10
-
11
- describe 'single pages' do
12
- before { processor.call(content, 1) }
13
- it { content.analyse(:page_count).must_equal 1 }
14
- end
15
-
16
- describe 'tempfile has extension' do
17
- it { processor.call(content, 1).tempfile.path.must_match /\.pdf\z/ }
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::PageThumb do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
6
- let(:processor) { DragonflyPdf::Processors::PageThumb.new }
7
-
8
- describe 'formats' do
9
- let (:url_attributes) { OpenStruct.new }
10
-
11
- describe 'default' do
12
- before do
13
- processor.call(content, 1, '600x')
14
- processor.update_url(url_attributes, 1)
15
- end
16
-
17
- it { content.ext.must_equal 'jpg' }
18
- it { content.meta['format'].must_equal 'jpg' }
19
- it { url_attributes.ext.must_equal 'jpg' }
20
- end
21
- end
22
-
23
- describe 'tempfile has extension' do
24
- before { processor.call(content, 1, '600x') }
25
- it { content.tempfile.path.must_match /\.jpg\z/ }
26
- end
27
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::RemovePassword do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages_with_password.pdf')) }
6
- let(:processor) { DragonflyPdf::Processors::RemovePassword.new }
7
-
8
- before { processor.call(content, 1) }
9
-
10
- it { `pdftk #{content.path} dump_data`.wont_include 'OWNER PASSWORD REQUIRED' }
11
-
12
- describe 'tempfile has extension' do
13
- it { content.tempfile.path.must_match /\.pdf\z/ }
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::Rotate do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
6
- let(:processor) { DragonflyPdf::Processors::Rotate.new }
7
-
8
- describe 'String|Symbol' do
9
- before { processor.call(content, :left) }
10
- it { content.analyse(:page_rotations).must_equal [270, 270, 270, 270, 270, 270, 270, 270, 270, 270] }
11
- end
12
-
13
- describe 'arg is Hash' do
14
- before { processor.call(content, 1 => :left, 3 => :right) }
15
- it { content.analyse(:page_rotations).must_equal [270, 0.0, 90, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] }
16
- end
17
-
18
- describe 'tempfile has extension' do
19
- before { processor.call(content, :left) }
20
- it { content.tempfile.path.must_match /\.pdf\z/ }
21
- end
22
- end
@@ -1,18 +0,0 @@
1
- require 'pdf-reader'
2
- require 'test_helper'
3
-
4
- describe DragonflyPdf::Processors::Stamp do
5
- let(:app) { test_app.configure_with(:pdf) }
6
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
7
- let(:content_stamp) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_stamp.pdf')) }
8
- let(:processor) { DragonflyPdf::Processors::Stamp.new }
9
-
10
- before { processor.call(content, content_stamp) }
11
-
12
- it { content.analyse(:page_count).must_equal 10 }
13
- it { PDF::Reader.new(content.path).pages.map(&:text).must_equal %w(STAMP).cycle(10).to_a }
14
-
15
- describe 'tempfile has extension' do
16
- it { content.tempfile.path.must_match /\.pdf\z/ }
17
- end
18
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe DragonflyPdf::Processors::SubsetFonts do
4
- let(:app) { test_app.configure_with(:pdf) }
5
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
6
- let(:processor) { DragonflyPdf::Processors::SubsetFonts.new }
7
-
8
- it 'returns PDF by default' do
9
- skip 'not sure how to test this'
10
- processor.call(content, 1)
11
- end
12
-
13
- describe 'tempfile has extension' do
14
- before { processor.call(content, 1) }
15
- it { content.tempfile.path.must_match /\.pdf\z/ }
16
- end
17
- end
data/test/test_helper.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- require 'minitest'
4
- require 'minitest/autorun'
5
- require 'minitest/reporters'
6
- require 'minitest/spec'
7
-
8
- require 'dragonfly'
9
- require 'dragonfly_pdf'
10
-
11
- SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
12
-
13
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
14
-
15
- def test_app(name = nil)
16
- app = Dragonfly::App.instance(name).tap do |app|
17
- app.datastore = Dragonfly::MemoryDataStore.new
18
- app.secret = 'test secret'
19
- end
20
- end