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 +4 -4
- data/.travis.yml +5 -2
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/dragonfly_pdf.gemspec +1 -1
- data/lib/dragonfly_pdf/analysers/pdf_properties.rb +1 -1
- data/lib/dragonfly_pdf/plugin.rb +19 -5
- data/lib/dragonfly_pdf/processors/append.rb +1 -1
- data/lib/dragonfly_pdf/processors/convert.rb +70 -0
- data/lib/dragonfly_pdf/processors/page.rb +1 -1
- data/lib/dragonfly_pdf/processors/remove_password.rb +1 -1
- data/lib/dragonfly_pdf/processors/rotate.rb +1 -1
- data/lib/dragonfly_pdf/processors/stamp.rb +1 -1
- data/lib/dragonfly_pdf/processors/subset_fonts.rb +1 -1
- data/lib/dragonfly_pdf/version.rb +1 -1
- data/test/dragonfly_pdf/plugin_test.rb +11 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5dab11367b3cdef13ca762005b3a860557f37f2
|
4
|
+
data.tar.gz: 074c0aebc12f4f39a18f538a1d9e71aff311e396
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 -
|
15
|
-
- tar zvxf vips-8.
|
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
data/README.md
CHANGED
data/dragonfly_pdf.gemspec
CHANGED
@@ -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', '
|
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'
|
data/lib/dragonfly_pdf/plugin.rb
CHANGED
@@ -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
|
-
|
52
|
-
|
53
|
-
options
|
54
|
-
options[
|
55
|
-
|
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
|
@@ -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
|
@@ -65,10 +65,20 @@ module DragonflyPdf
|
|
65
65
|
|
66
66
|
describe 'DragonflyLibvips proxy' do
|
67
67
|
describe 'page_thumb' do
|
68
|
-
it '
|
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:
|
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:
|
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
|
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
|
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
|