dragonfly_pdf 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3564818b6fdd4b3ef01e4bbcd252d662951cf447
4
- data.tar.gz: 55c1cf69673d57a4bc5552a5fcc7b3f788398052
3
+ metadata.gz: b5dab11367b3cdef13ca762005b3a860557f37f2
4
+ data.tar.gz: 074c0aebc12f4f39a18f538a1d9e71aff311e396
5
5
  SHA512:
6
- metadata.gz: fe8978ec5003eacc7922fdef3eb47f1186cae1553c0db804866516f9fa3c8d68fe275518eb97fa575a1733f90216057c5f82c2ef8863f0b18c94d349be8151dd
7
- data.tar.gz: e2a2e9cfee824167690afbb6ce98f7da326c5801f06930690698dfccfc0bcdc056641e3337b11a71cf62403ab8c87dc8a1ff64a08a3105c9d0d6924a17a48070
6
+ metadata.gz: 7d20ce89e113cd9023e67b9b48fc72ae93025e25cefe354273ffa68522777840766176ad4a79d799e3deace276c15b9055fd3ec4f9b03a04732c983c479c1a94
7
+ data.tar.gz: a91341b7bea0267ea9043eb04118a0fbeec0943274c1c0be80ec9d2780831f649bf041fefe0ad4206e7c0394c1594a7a3ca650d8f94f651d6a4496ad52e2fa23
data/.travis.yml CHANGED
@@ -8,11 +8,14 @@ rvm:
8
8
 
9
9
  before_install:
10
10
  - gem update bundler
11
+ - sudo add-apt-repository -y ppa:ubuntuhandbook1/apps
11
12
  - sudo apt-get update
12
13
  - sudo apt-get install -y pdftk
14
+ - sudo apt-get install -y ghostscript
15
+ - sudo apt-get install -y mupdf-tools
13
16
  - sudo apt-get install -y gobject-introspection libgirepository1.0-dev libglib2.0-dev libpoppler-glib-dev
14
- - curl -O http://www.vips.ecs.soton.ac.uk/supported/8.4/vips-8.4.5.tar.gz
15
- - tar zvxf vips-8.4.5.tar.gz && cd vips-8.4.5 && ./configure && sudo make && sudo make install
17
+ - curl -OL https://github.com/jcupitt/libvips/releases/download/v8.5.8/vips-8.5.8.tar.gz
18
+ - tar zvxf vips-8.5.8.tar.gz && cd vips-8.5.8 && ./configure && sudo make && sudo make install
16
19
  - export GI_TYPELIB_PATH=/usr/local/lib/girepository-1.0/
17
20
  - sudo ldconfig
18
21
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0
4
+
5
+ * PDF rendering to use `mupdf` which results in siginificant performance boost
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  * match `dragonfly_libvips` dependency
data/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  - [libvips](https://github.com/jcupitt/libvips)
10
10
  - [GhostScript](http://www.ghostscript.com)
11
+ - [mupdf](https://mupdf.com)
11
12
  - [pdftk](https://www.pdflabs.com/tools/pdftk-server)
12
13
 
13
14
  ## Installation
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'dragonfly', '~> 1.0'
22
- spec.add_dependency 'dragonfly_libvips', '>= 1.0.2'
22
+ spec.add_dependency 'dragonfly_libvips', '~> 2.1.0'
23
23
  spec.add_dependency 'activesupport', '>= 4.0'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.12'
@@ -21,7 +21,7 @@ module DragonflyPdf
21
21
  }
22
22
  end
23
23
 
24
- private # =============================================================
24
+ private
25
25
 
26
26
  def pt2mm(pt)
27
27
  (pt / 72.0) * 25.4
@@ -1,7 +1,9 @@
1
1
  require 'active_support/core_ext/hash'
2
2
 
3
3
  require 'dragonfly_pdf/analysers/pdf_properties'
4
+
4
5
  require 'dragonfly_pdf/processors/append'
6
+ require 'dragonfly_pdf/processors/convert'
5
7
  require 'dragonfly_pdf/processors/page'
6
8
  require 'dragonfly_pdf/processors/remove_password'
7
9
  require 'dragonfly_pdf/processors/rotate'
@@ -41,6 +43,7 @@ module DragonflyPdf
41
43
  # ---------------------------------------------------------------------
42
44
 
43
45
  app.add_processor :append, DragonflyPdf::Processors::Append.new
46
+ app.add_processor :convert, DragonflyPdf::Processors::Convert.new
44
47
  app.add_processor :page, DragonflyPdf::Processors::Page.new
45
48
  app.add_processor :remove_password, DragonflyPdf::Processors::RemovePassword.new
46
49
  app.add_processor :rotate, DragonflyPdf::Processors::Rotate.new
@@ -48,11 +51,22 @@ module DragonflyPdf
48
51
  app.add_processor :subset_fonts, DragonflyPdf::Processors::SubsetFonts.new
49
52
 
50
53
  app.add_processor :thumb, DragonflyLibvips::Processors::Thumb.new
51
- app.add_processor :page_thumb do |content, page_number, geometry, options = {}|
52
- options = options.deep_stringify_keys
53
- options.fetch('input_options', {})['page'] = page_number-1
54
- options['format'] ||= 'jpg'
55
- content.process!(:thumb, geometry, options)
54
+
55
+ app.add_processor :page_thumb do |content, page, geometry = nil, options = {}|
56
+ options = options.deep_symbolize_keys
57
+ options[:format] = options.fetch(:format, :jpg)
58
+
59
+ convert_options = {}
60
+ convert_options[:format] = case options[:format]
61
+ when :pdf, :svg then options[:format]
62
+ else :png
63
+ end
64
+
65
+ content.process!(:convert, page, geometry, convert_options)
66
+
67
+ unless %i[pdf png svg].include?(options[:format].to_sym)
68
+ content.process!(:thumb, geometry, options)
69
+ end
56
70
  end
57
71
  end
58
72
  end
@@ -7,7 +7,7 @@ module DragonflyPdf
7
7
  end
8
8
  end
9
9
 
10
- private # =============================================================
10
+ private
11
11
 
12
12
  def pdftk_command
13
13
  'pdftk'
@@ -0,0 +1,70 @@
1
+ require 'dragonfly_libvips/dimensions'
2
+ require 'vips'
3
+
4
+ module DragonflyPdf
5
+ module Processors
6
+ class Convert
7
+ DPI = 600
8
+
9
+ def call(content, page, geometry=nil, options = {})
10
+ options = options.deep_symbolize_keys
11
+ format = options.fetch(:format, :png)
12
+
13
+ case format.to_sym
14
+ when :pdf
15
+ pdf_options = options.fetch(:pdf_options, "compress,compress-fonts,compress-images,linearize,sanitize,garbage=deduplicate")
16
+
17
+ content.shell_update(ext: format) do |old_path, new_path|
18
+ "#{convert_command} -o #{new_path} -F #{format} -O #{pdf_options} #{old_path} #{page}"
19
+ end
20
+
21
+ when :svg
22
+ text = options.fetch(:text, :path)
23
+
24
+ content.shell_update(ext: format) do |old_path, new_path|
25
+ "#{convert_command} -o #{new_path} -F #{format} -O text=#{text} #{old_path} #{page}"
26
+ end
27
+
28
+ # MuPDF appends 1 at the end of the filename, we need to rename it back
29
+ `mv #{content.path.sub(".#{format}", "1.#{format}")} #{content.path}`
30
+
31
+ else
32
+ input_options = options.fetch(:input_options, {})
33
+ input_options[:access] = input_options.fetch(:access, 'sequential')
34
+ input_options[:dpi] = input_options.fetch(:dpi, DPI)
35
+
36
+ img = ::Vips::Image.new_from_file(content.path, input_options)
37
+
38
+ dimensions = case geometry
39
+ when DragonflyLibvips::Processors::Thumb::RESIZE_GEOMETRY then DragonflyLibvips::Dimensions.call(geometry, img.width, img.height)
40
+ else raise ArgumentError, "Didn't recognise the geometry string: #{geometry}"
41
+ end
42
+
43
+ width = dimensions.width.ceil
44
+
45
+ content.shell_update(ext: format) do |old_path, new_path|
46
+ "#{convert_command} -o #{new_path} -F #{format} -O width=#{width},colorspace=rgb #{old_path} #{page}"
47
+ end
48
+
49
+ # MuPDF appends 1 at the end of the filename, we need to rename it back
50
+ `mv #{content.path.sub(".#{format}", "1.#{format}")} #{content.path}`
51
+ end
52
+
53
+ content.ext = format
54
+ end
55
+
56
+ def update_url(url_attributes, _, options = {})
57
+ options = options.deep_symbolize_keys
58
+ format = options.fetch(:format, :png)
59
+
60
+ url_attributes.ext = format
61
+ end
62
+
63
+ private
64
+
65
+ def convert_command
66
+ 'mutool convert'
67
+ end
68
+ end
69
+ end
70
+ end
@@ -13,7 +13,7 @@ module DragonflyPdf
13
13
  end
14
14
  end
15
15
 
16
- private # =============================================================
16
+ private
17
17
 
18
18
  def gs_command
19
19
  'gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH'
@@ -7,7 +7,7 @@ module DragonflyPdf
7
7
  end
8
8
  end
9
9
 
10
- private # =============================================================
10
+ private
11
11
 
12
12
  def gs_command
13
13
  'gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite'
@@ -16,7 +16,7 @@ module DragonflyPdf
16
16
  end
17
17
  end
18
18
 
19
- private # =============================================================
19
+ private
20
20
 
21
21
  def pdftk_command
22
22
  'pdftk'
@@ -7,7 +7,7 @@ module DragonflyPdf
7
7
  end
8
8
  end
9
9
 
10
- private # =============================================================
10
+ private
11
11
 
12
12
  def pdftk_command
13
13
  'pdftk'
@@ -7,7 +7,7 @@ module DragonflyPdf
7
7
  end
8
8
  end
9
9
 
10
- private # =============================================================
10
+ private
11
11
 
12
12
  def gs_command
13
13
  'gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSubsetFonts=true'
@@ -1,3 +1,3 @@
1
1
  module DragonflyPdf
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -65,10 +65,20 @@ module DragonflyPdf
65
65
 
66
66
  describe 'DragonflyLibvips proxy' do
67
67
  describe 'page_thumb' do
68
- it 'encodes the image to the correct format' do
68
+ it 'converts PDF to JPG format' do
69
69
  pdf.page_thumb!(1, '600x')
70
70
  `file --mime-type #{pdf.path}`.must_include 'image/jpeg'
71
71
  end
72
+
73
+ # it 'converts PDF page to SVG format' do
74
+ # pdf.page_thumb!(1, nil, format: :svg)
75
+ # `file --mime-type #{pdf.path}`.must_include 'image/svg+xml'
76
+ # end
77
+ #
78
+ # it 'converts PDF page to PDF format' do
79
+ # pdf.page_thumb!(1, nil, format: :pdf)
80
+ # `file --mime-type #{pdf.path}`.must_include 'application/pdf'
81
+ # end
72
82
  end
73
83
  end
74
84
  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: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: dragonfly_libvips
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.2
33
+ version: 2.1.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: 1.0.2
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,7 @@ files:
157
157
  - lib/dragonfly_pdf/errors.rb
158
158
  - lib/dragonfly_pdf/plugin.rb
159
159
  - lib/dragonfly_pdf/processors/append.rb
160
+ - lib/dragonfly_pdf/processors/convert.rb
160
161
  - lib/dragonfly_pdf/processors/page.rb
161
162
  - lib/dragonfly_pdf/processors/remove_password.rb
162
163
  - lib/dragonfly_pdf/processors/rotate.rb