dragonfly_pdf 0.2.7 → 0.3.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 +3 -1
- data/CHANGELOG.md +4 -0
- data/README.md +22 -22
- data/dragonfly_pdf.gemspec +4 -3
- data/lib/dragonfly_pdf/analysers/pdf_properties.rb +7 -22
- data/lib/dragonfly_pdf/plugin.rb +15 -3
- data/lib/dragonfly_pdf/version.rb +1 -1
- data/test/dragonfly_pdf/analysers/pdf_properties_test.rb +40 -48
- data/test/dragonfly_pdf/plugin_test.rb +9 -0
- data/test/dragonfly_pdf/processors/append_test.rb +8 -28
- data/test/dragonfly_pdf/processors/page_test.rb +12 -32
- data/test/dragonfly_pdf/processors/remove_password_test.rb +7 -21
- data/test/dragonfly_pdf/processors/rotate_test.rb +14 -33
- data/test/dragonfly_pdf/processors/stamp_test.rb +12 -30
- data/test/dragonfly_pdf/processors/subset_fonts_test.rb +12 -0
- metadata +30 -19
- data/lib/dragonfly_pdf/processors/page_thumb.rb +0 -45
- data/test/dragonfly_pdf/processors/page_thumb_test.rb +0 -34
- data/test/dragonfly_pdf/processors/subset_fonts.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 708b5f991d28126c6c374d503b4573c28879b8a9
|
4
|
+
data.tar.gz: 1d5d198c02b33d47d6318868da45a4cfdf896d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 907ca3ee3cdb14580edea1a20f11ecf7d571a69fa882409625924511434e811e47bb21ad4f3cf4739683377ed9a83cc45a0e81cc57c279b2a94d235d53234ef8
|
7
|
+
data.tar.gz: 26978346b3358fd27bcc0d7eb72bafb5ccbdfeaf5c6e2bdd8fa20c05a0e5f4703f840e368884df08a3c4e0d8b17bda749a5abe2df15a771b1d8204ae96405231
|
data/.travis.yml
CHANGED
@@ -5,11 +5,13 @@ sudo: required
|
|
5
5
|
dist: trusty
|
6
6
|
rvm:
|
7
7
|
- 2.2.5
|
8
|
+
env:
|
9
|
+
- LIBVIPS_VERSION_MAJOR=8 LIBVIPS_VERSION_MINOR=3 LIBVIPS_VERSION_PATCH=3 LIBVIPS_VERSION=$LIBVIPS_VERSION_MAJOR.$LIBVIPS_VERSION_MINOR.$LIBVIPS_VERSION_PATCH
|
8
10
|
before_install:
|
9
11
|
- gem update bundler
|
10
12
|
- sudo apt-get update
|
11
13
|
- sudo apt-get install -y pdftk
|
12
|
-
-
|
14
|
+
- curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | sudo bash -
|
13
15
|
notifications:
|
14
16
|
email:
|
15
17
|
recipients:
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,25 +6,32 @@
|
|
6
6
|
|
7
7
|
## Dependencies
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
- [libvips](https://github.com/jcupitt/libvips)
|
10
|
+
- [GhostScript](http://www.ghostscript.com)
|
11
|
+
- [pdftk](https://www.pdflabs.com/tools/pdftk-server)
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
17
|
-
|
17
|
+
```
|
18
|
+
gem 'dragonfly_pdf'
|
19
|
+
```
|
18
20
|
|
19
21
|
And then execute:
|
20
22
|
|
21
|
-
|
23
|
+
```
|
24
|
+
$ bundle
|
25
|
+
```
|
22
26
|
|
23
27
|
Or install it yourself as:
|
24
28
|
|
25
|
-
|
29
|
+
```
|
30
|
+
$ gem install dragonfly_pdf
|
31
|
+
```
|
26
32
|
|
27
33
|
## Usage
|
34
|
+
|
28
35
|
The analyser and processors are added by configuring the plugin
|
29
36
|
|
30
37
|
```ruby
|
@@ -49,14 +56,6 @@ pdf.pdf_properties # => {
|
|
49
56
|
}
|
50
57
|
```
|
51
58
|
|
52
|
-
Optionally pass box type (`MediaBox|CropBox|BleedBox|TrimBox`):
|
53
|
-
|
54
|
-
```ruby
|
55
|
-
pdf.pdf_properties(box_type: 'MediaBox')
|
56
|
-
```
|
57
|
-
|
58
|
-
By default `TrimBox`, with a fallback to `MediaBox`.
|
59
|
-
|
60
59
|
## Processors
|
61
60
|
|
62
61
|
### Append
|
@@ -77,21 +76,22 @@ pdf.page(page_number=1)
|
|
77
76
|
|
78
77
|
### Page Thumb
|
79
78
|
|
80
|
-
Generates thumbnail of a specified page
|
79
|
+
Generates thumbnail of a specified page using the `thumb` processor of [DragonflyLibvips](https://github.com/tomasc/dragonfly_libvips).
|
81
80
|
|
82
81
|
```ruby
|
83
|
-
pdf.page_thumb(page_number=1, opts={})
|
82
|
+
pdf.page_thumb(page_number=1, '500x', opts={})
|
84
83
|
```
|
85
84
|
|
86
|
-
The
|
85
|
+
The default format is `png`, others can be specified
|
87
86
|
|
88
87
|
```ruby
|
89
88
|
{
|
90
|
-
|
91
|
-
format: :png,
|
89
|
+
'format' => 'jpg',
|
92
90
|
}
|
93
91
|
```
|
94
92
|
|
93
|
+
For more options see the [`thumb` doc](https://github.com/tomasc/dragonfly_libvips#thumb).
|
94
|
+
|
95
95
|
### Remove password
|
96
96
|
|
97
97
|
Remove password from password protected PDF.
|
@@ -109,12 +109,12 @@ pdf.rotate(:left)
|
|
109
109
|
```
|
110
110
|
|
111
111
|
Rotate selected pages.
|
112
|
+
|
112
113
|
```ruby
|
113
114
|
pdf.rotate(1 => :left, 3 => :right)
|
114
115
|
```
|
115
116
|
|
116
|
-
absolute: `north|south|east|west`
|
117
|
-
relative: `left|right|down`
|
117
|
+
absolute: `north|south|east|west` relative: `left|right|down`
|
118
118
|
|
119
119
|
### Stamp
|
120
120
|
|
@@ -134,7 +134,7 @@ pdf.subset_fonts
|
|
134
134
|
|
135
135
|
## Contributing
|
136
136
|
|
137
|
-
1. Fork it ( https://github.com/tomasc/dragonfly_pdf/fork )
|
137
|
+
1. Fork it ( <https://github.com/tomasc/dragonfly_pdf/fork> )
|
138
138
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
139
139
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
140
140
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/dragonfly_pdf.gemspec
CHANGED
@@ -19,11 +19,12 @@ 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', '>= 0.1.1'
|
22
23
|
|
23
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
24
25
|
spec.add_development_dependency 'guard'
|
25
26
|
spec.add_development_dependency 'guard-minitest'
|
26
|
-
spec.add_development_dependency 'minitest'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
29
|
spec.add_development_dependency 'pdf-reader'
|
28
|
-
spec.add_development_dependency 'rake'
|
29
30
|
end
|
@@ -1,31 +1,16 @@
|
|
1
1
|
module DragonflyPdf
|
2
2
|
module Analysers
|
3
3
|
class PdfProperties
|
4
|
-
def call(content,
|
5
|
-
|
4
|
+
def call(content, _options = {})
|
5
|
+
data = `pdftk #{content.path} dump_data`
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
rotate_data += item.scan(/\/Rotate\s(\d+?)\s/)
|
7
|
+
page_count = data.scan(/NumberOfPages: (\d+)/).flatten.first.to_i
|
8
|
+
page_numbers = data.scan(/PageMediaNumber: (\d+)/).flatten.map(&:to_i)
|
9
|
+
page_dimensions = data.scan(/PageMediaDimensions:\s*(\d+\.?\d+)\s*(\d+\.?\d+)/).map do |width_height|
|
10
|
+
width_height.map(&:to_f).map { |dim| pt2mm(dim) }
|
12
11
|
end
|
13
|
-
|
14
|
-
media_box = box_data.select { |d| d.first =~ /mediabox/i }
|
15
|
-
desired_box = box_data.select { |d| d.first =~ /#{box_type}/i }
|
16
|
-
|
17
|
-
# drop last value, since that comes from data about all pages
|
18
|
-
media_box = media_box[0..-2] if media_box.length > 1
|
19
|
-
|
20
|
-
page_dimensions = (!desired_box.empty? ? desired_box : media_box).map do |dim|
|
21
|
-
i = dim[1..-1].map(&:to_f).map { |d| pt2mm(d) }
|
22
|
-
[i[2] - i[0], i[3] - i[1]]
|
23
|
-
end
|
24
|
-
|
25
|
-
page_count = page_dimensions.count
|
12
|
+
page_rotations = data.scan(/PageMediaRotation: (\d+)/).flatten.map(&:to_f)
|
26
13
|
aspect_ratios = page_dimensions.inject([]) { |res, page| res << (page.first / page.last) }
|
27
|
-
page_numbers = (1..page_count).to_a
|
28
|
-
page_rotations = rotate_data.flatten.map(&:to_f)
|
29
14
|
|
30
15
|
{
|
31
16
|
aspect_ratios: aspect_ratios,
|
data/lib/dragonfly_pdf/plugin.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
require 'dragonfly_pdf/analysers/pdf_properties'
|
2
2
|
require 'dragonfly_pdf/processors/append'
|
3
3
|
require 'dragonfly_pdf/processors/page'
|
4
|
-
require 'dragonfly_pdf/processors/page_thumb'
|
5
4
|
require 'dragonfly_pdf/processors/remove_password'
|
6
5
|
require 'dragonfly_pdf/processors/rotate'
|
7
6
|
require 'dragonfly_pdf/processors/stamp'
|
8
7
|
require 'dragonfly_pdf/processors/subset_fonts'
|
9
8
|
|
9
|
+
require 'dragonfly_libvips/analysers/image_properties'
|
10
|
+
require 'dragonfly_libvips/processors/thumb'
|
11
|
+
require 'dragonfly_libvips/processors/vipsthumbnail'
|
12
|
+
|
10
13
|
module DragonflyPdf
|
11
14
|
class Plugin
|
12
15
|
def call(app, _opts = {})
|
16
|
+
app.add_analyser :image_properties, DragonflyLibvips::Analysers::ImageProperties.new
|
13
17
|
app.add_analyser :pdf_properties, DragonflyPdf::Analysers::PdfProperties.new
|
14
18
|
|
15
19
|
app.add_analyser :page_count do |content|
|
@@ -29,18 +33,26 @@ module DragonflyPdf
|
|
29
33
|
end
|
30
34
|
|
31
35
|
app.add_analyser :aspect_ratios do |content|
|
32
|
-
|
36
|
+
content.analyse(:pdf_properties)[:aspect_ratios]
|
33
37
|
end
|
34
38
|
|
35
39
|
# ---------------------------------------------------------------------
|
36
40
|
|
37
41
|
app.add_processor :append, DragonflyPdf::Processors::Append.new
|
38
42
|
app.add_processor :page, DragonflyPdf::Processors::Page.new
|
39
|
-
app.add_processor :page_thumb, DragonflyPdf::Processors::PageThumb.new
|
40
43
|
app.add_processor :remove_password, DragonflyPdf::Processors::RemovePassword.new
|
41
44
|
app.add_processor :rotate, DragonflyPdf::Processors::Rotate.new
|
42
45
|
app.add_processor :stamp, DragonflyPdf::Processors::Stamp.new
|
43
46
|
app.add_processor :subset_fonts, DragonflyPdf::Processors::SubsetFonts.new
|
47
|
+
|
48
|
+
app.add_processor :thumb, DragonflyLibvips::Processors::Thumb.new
|
49
|
+
app.add_processor :vipsthumbnail, DragonflyLibvips::Processors::Vipsthumbnail.new
|
50
|
+
app.add_processor :page_thumb do |content, page_number, dimensions, options|
|
51
|
+
options ||= {}
|
52
|
+
options['format'] ||= 'png'
|
53
|
+
options['input_args'] = [options['input_args'], "page=#{page_number - 1}"].compact.join(',')
|
54
|
+
content.process!(:thumb, dimensions, options)
|
55
|
+
end
|
44
56
|
end
|
45
57
|
end
|
46
58
|
end
|
@@ -1,53 +1,45 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#page_rotations' do
|
47
|
-
it 'returns correct page count' do
|
48
|
-
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]
|
49
|
-
end
|
50
|
-
end
|
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
|
+
# =====================================================================
|
11
|
+
|
12
|
+
it 'returns Hash' do
|
13
|
+
analyser.call(sample_pages).must_be_kind_of Hash
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#page_numbers' do
|
17
|
+
it 'returns one-dimensional array' do
|
18
|
+
analyser.call(sample_pages)[:page_numbers].must_equal (1..10).to_a
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#page_count' do
|
23
|
+
it 'returns correct page count' do
|
24
|
+
analyser.call(sample_pages)[:page_count].must_equal 10
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#page_dimensions' do
|
29
|
+
it 'returns array of page dimensions' do
|
30
|
+
analyser.call(sample_pages)[:page_dimensions].map { |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(10)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#aspect_ratios' do
|
35
|
+
it 'returns aspect ratios' do
|
36
|
+
analyser.call(sample_pages)[:aspect_ratios].map { |i| i.round(2) }.must_equal [0.71].cycle.take(10)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#page_rotations' do
|
41
|
+
it 'returns correct page count' do
|
42
|
+
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]
|
51
43
|
end
|
52
44
|
end
|
53
45
|
end
|
@@ -62,5 +62,14 @@ module DragonflyPdf
|
|
62
62
|
pdf.must_respond_to :subset_fonts
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
describe 'DragonflyLibvips proxy' do
|
67
|
+
describe 'page_thumb' do
|
68
|
+
it 'encodes the image to the correct format' do
|
69
|
+
pdf.page_thumb!(1, '600x')
|
70
|
+
`file --mime-type #{pdf.path}`.must_include 'image/png'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
@@ -1,34 +1,14 @@
|
|
1
|
-
require 'pdf-reader'
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
let(:sample_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
10
|
-
let(:sample_2) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages_with_bleed.pdf')) }
|
11
|
-
let(:result) { PDF::Reader.new(sample_1.path) }
|
3
|
+
describe DragonflyPdf::Processors::Append do
|
4
|
+
let(:app) { test_app.configure_with(:pdf) }
|
5
|
+
let(:processor) { DragonflyPdf::Processors::Append.new }
|
6
|
+
let(:sample_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
7
|
+
let(:sample_2) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages_with_bleed.pdf')) }
|
12
8
|
|
13
|
-
|
9
|
+
before { processor.call(sample_1, [sample_2]) }
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns PDF by default' do
|
20
|
-
get_mime_type(sample_1.path).must_include 'application/pdf'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'has total number of pages' do
|
24
|
-
result.pages.count.must_equal 11
|
25
|
-
end
|
26
|
-
|
27
|
-
# ---------------------------------------------------------------------
|
28
|
-
|
29
|
-
def get_mime_type(file_path)
|
30
|
-
`file --mime-type #{file_path}`.delete("\n")
|
31
|
-
end
|
32
|
-
end
|
11
|
+
it 'has total number of pages' do
|
12
|
+
sample_1.analyse(:page_count).must_equal 11
|
33
13
|
end
|
34
14
|
end
|
@@ -1,39 +1,19 @@
|
|
1
|
-
require 'pdf-reader'
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
let(:processor) { DragonflyPdf::Processors::Page.new }
|
9
|
-
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
10
|
-
let(:result) { PDF::Reader.new(sample_pages.path) }
|
3
|
+
describe DragonflyPdf::Processors::Page do
|
4
|
+
let(:app) { test_app.configure_with(:pdf) }
|
5
|
+
let(:processor) { DragonflyPdf::Processors::Page.new }
|
6
|
+
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
get_mime_type(sample_pages.path).must_include 'application/pdf'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'raises PageNotFound error' do
|
20
|
-
proc { processor.call(sample_pages, 0) }.must_raise DragonflyPdf::PageNotFound
|
21
|
-
proc { processor.call(sample_pages, 11) }.must_raise DragonflyPdf::PageNotFound
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'single pages' do
|
25
|
-
it 'renders page' do
|
26
|
-
processor.call(sample_pages, 1)
|
27
|
-
result.pages.count.must_equal 1
|
28
|
-
result.pages.first.text.must_equal '1'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# ---------------------------------------------------------------------
|
8
|
+
it 'raises PageNotFound error' do
|
9
|
+
proc { processor.call(sample_pages, 0) }.must_raise DragonflyPdf::PageNotFound
|
10
|
+
proc { processor.call(sample_pages, 11) }.must_raise DragonflyPdf::PageNotFound
|
11
|
+
end
|
33
12
|
|
34
|
-
|
35
|
-
|
36
|
-
|
13
|
+
describe 'single pages' do
|
14
|
+
it 'renders page' do
|
15
|
+
processor.call(sample_pages, 1)
|
16
|
+
sample_pages.analyse(:page_count).must_equal 1
|
37
17
|
end
|
38
18
|
end
|
39
19
|
end
|
@@ -1,26 +1,12 @@
|
|
1
|
-
require 'pdf-reader'
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
let(:processor) { DragonflyPdf::Processors::RemovePassword.new }
|
9
|
-
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages_with_password.pdf')) }
|
10
|
-
let(:result) { PDF::Reader.new(sample_pages.path) }
|
3
|
+
describe DragonflyPdf::Processors::RemovePassword do
|
4
|
+
let(:app) { test_app.configure_with(:pdf) }
|
5
|
+
let(:processor) { DragonflyPdf::Processors::RemovePassword.new }
|
6
|
+
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages_with_password.pdf')) }
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
processor.call(sample_pages, 1)
|
16
|
-
get_mime_type(sample_pages.path).must_include 'application/pdf'
|
17
|
-
end
|
18
|
-
|
19
|
-
# ---------------------------------------------------------------------
|
20
|
-
|
21
|
-
def get_mime_type(file_path)
|
22
|
-
`file --mime-type #{file_path}`.delete("\n")
|
23
|
-
end
|
24
|
-
end
|
8
|
+
it 'returns PDF by default' do
|
9
|
+
processor.call(sample_pages, 1)
|
10
|
+
`pdftk #{sample_pages.path} dump_data`.wont_include 'OWNER PASSWORD REQUIRED'
|
25
11
|
end
|
26
12
|
end
|
@@ -1,40 +1,21 @@
|
|
1
|
-
require 'pdf-reader'
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
let(:processor) { DragonflyPdf::Processors::Rotate.new }
|
9
|
-
let(:sample_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
10
|
-
let(:result) { PDF::Reader.new(sample_1.path) }
|
3
|
+
describe DragonflyPdf::Processors::Rotate do
|
4
|
+
let(:app) { test_app.configure_with(:pdf) }
|
5
|
+
let(:processor) { DragonflyPdf::Processors::Rotate.new }
|
6
|
+
let(:sample_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
describe 'arg is String|Symbol' do
|
20
|
-
it 'rotates all pages' do
|
21
|
-
processor.call(sample_1, :left)
|
22
|
-
result.pages.map { |p| p.attributes[:Rotate] }.must_equal [270, 270, 270, 270, 270, 270, 270, 270, 270, 270]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'arg is Hash' do
|
27
|
-
it 'rotates only defined pages' do
|
28
|
-
processor.call(sample_1, 1 => :left, 3 => :right)
|
29
|
-
result.pages.map { |p| p.attributes[:Rotate] }.must_equal [270, nil, 90, nil, nil, nil, nil, nil, nil, nil]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# ---------------------------------------------------------------------
|
8
|
+
describe 'arg is String|Symbol' do
|
9
|
+
it 'rotates all pages' do
|
10
|
+
processor.call(sample_1, :left)
|
11
|
+
sample_1.analyse(:page_rotations).must_equal [270, 270, 270, 270, 270, 270, 270, 270, 270, 270]
|
12
|
+
end
|
13
|
+
end
|
34
14
|
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
describe 'arg is Hash' do
|
16
|
+
it 'rotates only defined pages' do
|
17
|
+
processor.call(sample_1, 1 => :left, 3 => :right)
|
18
|
+
sample_1.analyse(:page_rotations).must_equal [270, 0.0, 90, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
38
19
|
end
|
39
20
|
end
|
40
21
|
end
|
@@ -1,38 +1,20 @@
|
|
1
1
|
require 'pdf-reader'
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
let(:sample_stamp) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_stamp.pdf')) }
|
11
|
-
let(:result) { PDF::Reader.new(sample_1.path) }
|
4
|
+
describe DragonflyPdf::Processors::Stamp do
|
5
|
+
let(:app) { test_app.configure_with(:pdf) }
|
6
|
+
let(:processor) { DragonflyPdf::Processors::Stamp.new }
|
7
|
+
let(:sample_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
8
|
+
let(:sample_stamp) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_stamp.pdf')) }
|
9
|
+
let(:text) { PDF::Reader.new(sample_1.path).pages.map(&:text) }
|
12
10
|
|
13
|
-
|
11
|
+
before { processor.call(sample_1, sample_stamp) }
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
it 'returns PDF by default' do
|
20
|
-
get_mime_type(sample_1.path).must_include 'application/pdf'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'has same number of pages' do
|
24
|
-
result.pages.count.must_equal 10
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'has the stamp' do
|
28
|
-
result.pages.map(&:text).must_equal %w(STAMP).cycle(10).to_a
|
29
|
-
end
|
30
|
-
|
31
|
-
# ---------------------------------------------------------------------
|
13
|
+
it 'has same number of pages' do
|
14
|
+
sample_1.analyse(:page_count).must_equal 10
|
15
|
+
end
|
32
16
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
17
|
+
it 'has the stamp' do
|
18
|
+
text.must_equal %w(STAMP).cycle(10).to_a
|
37
19
|
end
|
38
20
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe DragonflyPdf::Processors::SubsetFonts do
|
4
|
+
let(:app) { test_app.configure_with(:pdf) }
|
5
|
+
let(:processor) { DragonflyPdf::Processors::SubsetFonts.new }
|
6
|
+
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
7
|
+
|
8
|
+
it 'returns PDF by default' do
|
9
|
+
skip 'not sure how to test this'
|
10
|
+
processor.call(sample_pages, 1)
|
11
|
+
end
|
12
|
+
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: 0.
|
4
|
+
version: 0.3.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: 2016-08-
|
11
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dragonfly_libvips
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
47
|
+
version: '1.12'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
54
|
+
version: '1.12'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: guard
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,32 +84,32 @@ dependencies:
|
|
70
84
|
name: minitest
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
89
|
+
version: '5.0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
96
|
+
version: '5.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: rake
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
103
|
+
version: '10.0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
110
|
+
version: '10.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: pdf-reader
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -130,7 +144,6 @@ files:
|
|
130
144
|
- lib/dragonfly_pdf/plugin.rb
|
131
145
|
- lib/dragonfly_pdf/processors/append.rb
|
132
146
|
- lib/dragonfly_pdf/processors/page.rb
|
133
|
-
- lib/dragonfly_pdf/processors/page_thumb.rb
|
134
147
|
- lib/dragonfly_pdf/processors/remove_password.rb
|
135
148
|
- lib/dragonfly_pdf/processors/rotate.rb
|
136
149
|
- lib/dragonfly_pdf/processors/stamp.rb
|
@@ -145,11 +158,10 @@ files:
|
|
145
158
|
- test/dragonfly_pdf/plugin_test.rb
|
146
159
|
- test/dragonfly_pdf/processors/append_test.rb
|
147
160
|
- test/dragonfly_pdf/processors/page_test.rb
|
148
|
-
- test/dragonfly_pdf/processors/page_thumb_test.rb
|
149
161
|
- test/dragonfly_pdf/processors/remove_password_test.rb
|
150
162
|
- test/dragonfly_pdf/processors/rotate_test.rb
|
151
163
|
- test/dragonfly_pdf/processors/stamp_test.rb
|
152
|
-
- test/dragonfly_pdf/processors/
|
164
|
+
- test/dragonfly_pdf/processors/subset_fonts_test.rb
|
153
165
|
- test/test_helper.rb
|
154
166
|
homepage: https://github.com/tomasc/dragonfly_pdf
|
155
167
|
licenses:
|
@@ -180,9 +192,8 @@ test_files:
|
|
180
192
|
- test/dragonfly_pdf/plugin_test.rb
|
181
193
|
- test/dragonfly_pdf/processors/append_test.rb
|
182
194
|
- test/dragonfly_pdf/processors/page_test.rb
|
183
|
-
- test/dragonfly_pdf/processors/page_thumb_test.rb
|
184
195
|
- test/dragonfly_pdf/processors/remove_password_test.rb
|
185
196
|
- test/dragonfly_pdf/processors/rotate_test.rb
|
186
197
|
- test/dragonfly_pdf/processors/stamp_test.rb
|
187
|
-
- test/dragonfly_pdf/processors/
|
198
|
+
- test/dragonfly_pdf/processors/subset_fonts_test.rb
|
188
199
|
- test/test_helper.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require_relative '../analysers/pdf_properties'
|
2
|
-
|
3
|
-
module DragonflyPdf
|
4
|
-
module Processors
|
5
|
-
class PageThumb
|
6
|
-
attr_reader :content, :density, :page_number, :format
|
7
|
-
|
8
|
-
def call(content, page_number = 1, opts = {})
|
9
|
-
@content = content
|
10
|
-
@page_number = page_number
|
11
|
-
@format = opts['format'] || :png
|
12
|
-
@density = opts['density'] || 150
|
13
|
-
|
14
|
-
content.shell_update(ext: @format) do |old_path, new_path|
|
15
|
-
"#{gs_command} -o '#{new_path}' -f '#{old_path}'"
|
16
|
-
end
|
17
|
-
|
18
|
-
@content.meta['format'] = @format.to_s
|
19
|
-
@content.ext = @format
|
20
|
-
end
|
21
|
-
|
22
|
-
def update_url(attrs, page_number, opts = {})
|
23
|
-
format = opts['format']
|
24
|
-
attrs.page_number = page_number
|
25
|
-
attrs.ext = format if format
|
26
|
-
end
|
27
|
-
|
28
|
-
private # =============================================================
|
29
|
-
|
30
|
-
def gs_command
|
31
|
-
"gs -sDEVICE=#{gs_format} -r#{density} -dTextAlphaBits=4 -dUseArtBox -dFirstPage=#{page_number} -dLastPage=#{page_number}"
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def gs_format
|
36
|
-
case @format
|
37
|
-
when :png then :png16m
|
38
|
-
when :jpg, :jpeg then :jpeg
|
39
|
-
when :tif, :tiff then :tiff48nc
|
40
|
-
else :jpeg
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module DragonflyPdf
|
4
|
-
module Processors
|
5
|
-
describe PageThumb do
|
6
|
-
let(:app) { test_app.configure_with(:pdf) }
|
7
|
-
let(:processor) { DragonflyPdf::Processors::PageThumb.new }
|
8
|
-
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
9
|
-
|
10
|
-
# =====================================================================
|
11
|
-
|
12
|
-
it 'returns PNG by default' do
|
13
|
-
processor.call(sample_pages, 1, density: 72)
|
14
|
-
get_mime_type(sample_pages.path).must_include 'image/png'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'raises PageNotFound error' do
|
18
|
-
skip 'calling the page properties slows evrything down'
|
19
|
-
proc { processor.call(sample_pages, 0) }.must_raise DragonflyPdf::PageNotFound
|
20
|
-
proc { processor.call(sample_pages, 11) }.must_raise DragonflyPdf::PageNotFound
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'renders page' do
|
24
|
-
processor.call(sample_pages, 1, density: 72)
|
25
|
-
end
|
26
|
-
|
27
|
-
# ---------------------------------------------------------------------
|
28
|
-
|
29
|
-
def get_mime_type(file_path)
|
30
|
-
`file --mime-type #{file_path}`.delete("\n")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module DragonflyPdf
|
2
|
-
module Processors
|
3
|
-
describe SubsetFonts do
|
4
|
-
let(:app) { test_app.configure_with(:pdf) }
|
5
|
-
let(:processor) { DragonflyPdf::Processors::SubsetFonts.new }
|
6
|
-
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
7
|
-
|
8
|
-
# =====================================================================
|
9
|
-
|
10
|
-
it 'returns PDF by default' do
|
11
|
-
processor.call(sample_pages, 1)
|
12
|
-
get_mime_type(sample_pages.path).must_include 'application/pdf'
|
13
|
-
end
|
14
|
-
|
15
|
-
private # =============================================================
|
16
|
-
|
17
|
-
def get_mime_type(file_path)
|
18
|
-
`file --mime-type #{file_path}`.delete("\n")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|