dragonfly_pdf 0.1.3 → 0.2.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 -0
- data/CHANGELOG.md +8 -0
- data/README.md +42 -7
- data/dragonfly_pdf.gemspec +2 -2
- data/lib/dragonfly_pdf/analysers/pdf_properties.rb +20 -49
- data/lib/dragonfly_pdf/plugin.rb +8 -2
- data/lib/dragonfly_pdf/processors/append.rb +17 -0
- data/lib/dragonfly_pdf/processors/page.rb +3 -9
- data/lib/dragonfly_pdf/processors/rotate.rb +26 -0
- data/lib/dragonfly_pdf/processors/stamp.rb +17 -0
- data/lib/dragonfly_pdf/version.rb +1 -1
- data/samples/sample_stamp.pdf +0 -0
- data/test/dragonfly_pdf/analysers/pdf_properties_test.rb +1 -15
- data/test/dragonfly_pdf/processors/append_test.rb +34 -0
- data/test/dragonfly_pdf/processors/page_test.rb +4 -3
- data/test/dragonfly_pdf/processors/rotate_test.rb +40 -0
- data/test/dragonfly_pdf/processors/stamp_test.rb +38 -0
- data/test/test_helper.rb +0 -2
- metadata +27 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b630259edd321fc3a4972fc7c5cae40871e050b0
|
4
|
+
data.tar.gz: 57b09a13cd2c1b4099a56d284519873e792b0fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2185816838240ea29832527c758e9648a37038bdbd8f8d893eef372dd33941820730ebbe3faa1d7d082b47494ff9b1e563bddf2d5e11cadd4e414a0198233520
|
7
|
+
data.tar.gz: 52a19c0bddb5ce97f81a57ceb43f5e369b34343034af72b3af770b314303286318f21177d6bad56240cfe2cd5649ea40a9dec61c96220e9ceade68fd182c8ad1
|
data/.travis.yml
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
script: 'bundle exec rake'
|
4
|
+
sudo: required
|
5
|
+
dist: trusty
|
4
6
|
rvm:
|
5
7
|
- 2.1.2
|
6
8
|
before_install:
|
7
9
|
- gem update bundler
|
10
|
+
- sudo apt-get update
|
11
|
+
- sudo apt-get install -y pdftk
|
12
|
+
- pdftk --version
|
8
13
|
notifications:
|
9
14
|
email:
|
10
15
|
recipients:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
|
3
|
+
* refactor: read PDF attributes directly
|
4
|
+
* dependency: `pdftk` for adjustments to PDFs
|
5
|
+
* added: `append` to combine multiple PDFs together
|
6
|
+
* added: `rotate` to rotate pages of a PDF
|
7
|
+
* added: `stamp` to stamping pages with content of another PDF
|
8
|
+
|
1
9
|
## 0.1.0
|
2
10
|
|
3
11
|
* added: `page_dimensions`
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
|
9
9
|
* [ImageMagick](http://www.imagemagick.org)
|
10
10
|
* [GhostScript](http://www.ghostscript.com)
|
11
|
+
* [pdftk](https://www.pdflabs.com/tools/pdftk-server)
|
11
12
|
|
12
13
|
## Installation
|
13
14
|
|
@@ -39,13 +40,7 @@ end
|
|
39
40
|
Reads properties from a PDF.
|
40
41
|
|
41
42
|
```ruby
|
42
|
-
pdf.pdf_properties
|
43
|
-
```
|
44
|
-
|
45
|
-
It returns a hash of properties:
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
{
|
43
|
+
pdf.pdf_properties # => {
|
49
44
|
page_count: 4,
|
50
45
|
page_dimensions: [[210.0, 297.0], [210.0, 297.0], [210.0, 297.0], [210.0, 297.0]],
|
51
46
|
page_numbers: [1, 2, 3, 4],
|
@@ -55,8 +50,24 @@ It returns a hash of properties:
|
|
55
50
|
}
|
56
51
|
```
|
57
52
|
|
53
|
+
Optionally pass box type (`MediaBox|CropBox|BleedBox|TrimBox`):
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
pdf.pdf_properties(box_type: 'MediaBox')
|
57
|
+
```
|
58
|
+
|
59
|
+
By default `TrimBox`, with a fallback to `MediaBox`.
|
60
|
+
|
58
61
|
## Processors
|
59
62
|
|
63
|
+
### Append
|
64
|
+
|
65
|
+
Append PDFs.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
pdf.append([pdf_1, pdf_2, pdf_3])
|
69
|
+
```
|
70
|
+
|
60
71
|
### Page
|
61
72
|
|
62
73
|
Extracts page from PDF.
|
@@ -82,6 +93,30 @@ The available options and their default values are:
|
|
82
93
|
}
|
83
94
|
```
|
84
95
|
|
96
|
+
### Rotate
|
97
|
+
|
98
|
+
Rotate all pages.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
pdf.rotate(:left)
|
102
|
+
```
|
103
|
+
|
104
|
+
Rotate selected pages.
|
105
|
+
```ruby
|
106
|
+
pdf.rotate(1 => :left, 3 => :right)
|
107
|
+
```
|
108
|
+
|
109
|
+
absolute: `north|south|east|west`
|
110
|
+
relative: `left|right|down`
|
111
|
+
|
112
|
+
### Stamp
|
113
|
+
|
114
|
+
Stamp every page of a PDF with another PDF.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
pdf.stamp(stamp_pdf)
|
118
|
+
```
|
119
|
+
|
85
120
|
### Subset Fonts
|
86
121
|
|
87
122
|
Subset fonts in PDF.
|
data/dragonfly_pdf.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "dragonfly", "~> 1.0"
|
22
22
|
|
23
|
-
spec.add_development_dependency "pdf-reader"
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
-
spec.add_development_dependency "rake"
|
26
24
|
spec.add_development_dependency "guard"
|
27
25
|
spec.add_development_dependency "guard-minitest"
|
28
26
|
spec.add_development_dependency "minitest"
|
27
|
+
spec.add_development_dependency "pdf-reader"
|
28
|
+
spec.add_development_dependency "rake"
|
29
29
|
end
|
@@ -2,68 +2,39 @@ module DragonflyPdf
|
|
2
2
|
module Analysers
|
3
3
|
class PdfProperties
|
4
4
|
def call(content, options = {})
|
5
|
-
|
6
|
-
@use_cropbox = options.fetch :use_cropbox, true
|
7
|
-
@use_trimbox = options.fetch :use_trimbox, true
|
8
|
-
@page_dimensions = page_dimensions
|
9
|
-
{
|
10
|
-
aspect_ratios: aspect_ratios,
|
11
|
-
heights: heights,
|
12
|
-
page_count: page_count,
|
13
|
-
page_dimensions: @page_dimensions,
|
14
|
-
page_numbers: page_numbers,
|
15
|
-
widths: widths
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
private # =============================================================
|
20
|
-
|
21
|
-
def page_dimensions
|
22
|
-
res = @content.shell_eval do |path|
|
23
|
-
"#{identify_command} -format '%Wx%H,' #{path}"
|
24
|
-
end
|
25
|
-
res.to_s.split(/\s*,\s*/).compact.map do |page|
|
26
|
-
page = page.split(/\s*x\s*/).map(&:to_f).map { |n| pt2mm(n) }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# ---------------------------------------------------------------------
|
5
|
+
box_type = options.fetch :box_type, 'TrimBox'
|
31
6
|
|
32
|
-
|
33
|
-
|
34
|
-
|
7
|
+
box_data = []
|
8
|
+
IO.foreach(content.path, "\n\n", encoding: "ISO-8859-1") do |item|
|
9
|
+
box_data += item.scan(/(MediaBox|CropBox|BleedBox|TrimBox)\s?\[([\d\.]+?)\s([\d\.]+?)\s([\d\.]+?)\s([\d\.]+?)\]/)
|
35
10
|
end
|
36
|
-
end
|
37
11
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
12
|
+
# drop last value, since that comes from data about all pages
|
13
|
+
media_box = box_data.select { |d| d.first == 'MediaBox' }[0..-2]
|
14
|
+
desired_box = box_data.select { |d| d.first == box_type }
|
43
15
|
|
44
|
-
|
45
|
-
|
46
|
-
|
16
|
+
page_dimensions = (desired_box.length > 0 ? desired_box : media_box).map do |dim|
|
17
|
+
i = dim[1..-1].map(&:to_f).map{ |d| pt2mm(d) }
|
18
|
+
[ i[2]-i[0], i[3]-i[1] ]
|
47
19
|
end
|
48
|
-
end
|
49
20
|
|
50
|
-
|
51
|
-
|
52
|
-
|
21
|
+
page_count = page_dimensions.count
|
22
|
+
aspect_ratios = page_dimensions.inject([]) { |res, page| res << (page.first / page.last) }
|
23
|
+
page_numbers = (1..page_count).to_a
|
53
24
|
|
54
|
-
|
55
|
-
|
25
|
+
{
|
26
|
+
aspect_ratios: aspect_ratios,
|
27
|
+
page_count: page_count,
|
28
|
+
page_dimensions: page_dimensions,
|
29
|
+
page_numbers: page_numbers
|
30
|
+
}
|
56
31
|
end
|
57
32
|
|
58
|
-
#
|
33
|
+
private # =============================================================
|
59
34
|
|
60
35
|
def pt2mm(pt)
|
61
36
|
(pt / 72.0) * 25.4
|
62
37
|
end
|
63
|
-
|
64
|
-
def identify_command
|
65
|
-
"identify -define pdf:use-cropbox=#{@use_cropbox} -define pdf:use-trimbox=#{@use_trimbox}"
|
66
|
-
end
|
67
38
|
end
|
68
39
|
end
|
69
40
|
end
|
data/lib/dragonfly_pdf/plugin.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'dragonfly_pdf/analysers/pdf_properties'
|
2
|
+
require 'dragonfly_pdf/processors/append'
|
2
3
|
require 'dragonfly_pdf/processors/page'
|
3
4
|
require 'dragonfly_pdf/processors/page_thumb'
|
5
|
+
require 'dragonfly_pdf/processors/rotate'
|
6
|
+
require 'dragonfly_pdf/processors/stamp'
|
4
7
|
require 'dragonfly_pdf/processors/subset_fonts'
|
5
8
|
|
6
9
|
module DragonflyPdf
|
7
10
|
class Plugin
|
8
|
-
def call
|
11
|
+
def call(app, _opts = {})
|
9
12
|
app.add_analyser :pdf_properties, DragonflyPdf::Analysers::PdfProperties.new
|
10
13
|
|
11
14
|
app.add_analyser :page_count do |content|
|
@@ -34,8 +37,11 @@ module DragonflyPdf
|
|
34
37
|
|
35
38
|
# ---------------------------------------------------------------------
|
36
39
|
|
37
|
-
app.add_processor :
|
40
|
+
app.add_processor :append, DragonflyPdf::Processors::Append.new
|
38
41
|
app.add_processor :page, DragonflyPdf::Processors::Page.new
|
42
|
+
app.add_processor :page_thumb, DragonflyPdf::Processors::PageThumb.new
|
43
|
+
app.add_processor :rotate, DragonflyPdf::Processors::Rotate.new
|
44
|
+
app.add_processor :stamp, DragonflyPdf::Processors::Stamp.new
|
39
45
|
app.add_processor :subset_fonts, DragonflyPdf::Processors::SubsetFonts.new
|
40
46
|
end
|
41
47
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DragonflyPdf
|
2
|
+
module Processors
|
3
|
+
class Append
|
4
|
+
def call(content, pdfs_to_append, _options = {})
|
5
|
+
content.shell_update(ext: :pdf) do |old_path, new_path|
|
6
|
+
"#{pdftk_command} #{old_path} #{pdfs_to_append.map(&:path).join(' ')} cat output #{new_path}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private # =============================================================
|
11
|
+
|
12
|
+
def pdftk_command
|
13
|
+
"pdftk"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,13 +5,11 @@ module DragonflyPdf
|
|
5
5
|
module Processors
|
6
6
|
class Page
|
7
7
|
def call(content, page_number = 1, _opts = {})
|
8
|
-
|
9
|
-
@page_number = page_number
|
10
|
-
|
8
|
+
pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
|
11
9
|
fail DragonflyPdf::PageNotFound unless pdf_properties[:page_numbers].include?(page_number)
|
12
10
|
|
13
|
-
|
14
|
-
"#{gs_command} -dFirstPage=#{
|
11
|
+
content.shell_update(ext: :pdf) do |old_path, new_path|
|
12
|
+
"#{gs_command} -dFirstPage=#{page_number} -dLastPage=#{page_number} -o #{new_path} -f #{old_path}"
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
@@ -20,10 +18,6 @@ module DragonflyPdf
|
|
20
18
|
def gs_command
|
21
19
|
'gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH'
|
22
20
|
end
|
23
|
-
|
24
|
-
def pdf_properties
|
25
|
-
@pdf_properties ||= DragonflyPdf::Analysers::PdfProperties.new.call(@content)
|
26
|
-
end
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DragonflyPdf
|
2
|
+
module Processors
|
3
|
+
class Rotate
|
4
|
+
def call(content, arg)
|
5
|
+
rotate_args = case arg
|
6
|
+
when String, Symbol
|
7
|
+
fail ArgumentError.new unless arg =~ /north|south|east|west|left|right|down/i
|
8
|
+
"1-end#{arg}"
|
9
|
+
when Hash
|
10
|
+
pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
|
11
|
+
pdf_properties[:page_numbers].map { |page| [page, arg[page]].compact.join }.join(' ')
|
12
|
+
end
|
13
|
+
|
14
|
+
content.shell_update(ext: :pdf) do |old_path, new_path|
|
15
|
+
"#{pdftk_command} #{old_path} cat #{rotate_args} output #{new_path}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private # =============================================================
|
20
|
+
|
21
|
+
def pdftk_command
|
22
|
+
'pdftk'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DragonflyPdf
|
2
|
+
module Processors
|
3
|
+
class Stamp
|
4
|
+
def call(content, stamp_pdf, _options = {})
|
5
|
+
content.shell_update(ext: :pdf) do |old_path, new_path|
|
6
|
+
"#{pdftk_command} #{old_path} stamp #{stamp_pdf.path} output #{new_path}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private # =============================================================
|
11
|
+
|
12
|
+
def pdftk_command
|
13
|
+
"pdftk"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
Binary file
|
@@ -27,26 +27,12 @@ module DragonflyPdf
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '#page_dimensions' do
|
30
|
-
it 'returns
|
30
|
+
it 'returns array of page dimensions' do
|
31
31
|
analyser.call(sample_pages)[:page_dimensions].map{ |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(10)
|
32
32
|
analyser.call(sample_pages_with_bleed)[:page_dimensions].map{ |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(1)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe '#widths' do
|
37
|
-
it 'returns widths' do
|
38
|
-
analyser.call(sample_pages)[:widths].map(&:round).must_equal [210].cycle.take(10)
|
39
|
-
analyser.call(sample_pages_with_bleed)[:widths].map(&:round).must_equal [210].cycle.take(1)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#heights' do
|
44
|
-
it 'returns heights' do
|
45
|
-
analyser.call(sample_pages)[:heights].map(&:round).must_equal [297].cycle.take(10)
|
46
|
-
analyser.call(sample_pages_with_bleed)[:heights].map(&:round).must_equal [297].cycle.take(1)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
36
|
describe '#aspect_ratios' do
|
51
37
|
it 'returns aspect ratios' do
|
52
38
|
analyser.call(sample_pages)[:aspect_ratios].map{ |i| i.round(2) }.must_equal [0.71].cycle.take(10)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'pdf-reader'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module DragonflyPdf
|
5
|
+
module Processors
|
6
|
+
describe Append do
|
7
|
+
let(:app) { test_app.configure_with(:pdf) }
|
8
|
+
let(:processor) { DragonflyPdf::Processors::Append.new }
|
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) }
|
12
|
+
|
13
|
+
# =====================================================================
|
14
|
+
|
15
|
+
before do
|
16
|
+
processor.call(sample_1, [sample_2])
|
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}`.gsub(/\n/, '')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pdf-reader'
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
module DragonflyPdf
|
@@ -6,6 +7,7 @@ module DragonflyPdf
|
|
6
7
|
let(:app) { test_app.configure_with(:pdf) }
|
7
8
|
let(:processor) { DragonflyPdf::Processors::Page.new }
|
8
9
|
let(:sample_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
10
|
+
let(:result) { PDF::Reader.new(sample_pages.path) }
|
9
11
|
|
10
12
|
# =====================================================================
|
11
13
|
|
@@ -22,9 +24,8 @@ module DragonflyPdf
|
|
22
24
|
describe 'single pages' do
|
23
25
|
it 'renders page' do
|
24
26
|
processor.call(sample_pages, 1)
|
25
|
-
|
26
|
-
|
27
|
-
pdf.pages.first.text.must_equal '1'
|
27
|
+
result.pages.count.must_equal 1
|
28
|
+
result.pages.first.text.must_equal '1'
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'pdf-reader'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module DragonflyPdf
|
5
|
+
module Processors
|
6
|
+
describe Rotate do
|
7
|
+
let(:app) { test_app.configure_with(:pdf) }
|
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) }
|
11
|
+
|
12
|
+
# =====================================================================
|
13
|
+
|
14
|
+
it 'returns PDF by default' do
|
15
|
+
processor.call(sample_1, :left)
|
16
|
+
get_mime_type(sample_1.path).must_include 'application/pdf'
|
17
|
+
end
|
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
|
+
# ---------------------------------------------------------------------
|
34
|
+
|
35
|
+
def get_mime_type(file_path)
|
36
|
+
`file --mime-type #{file_path}`.gsub(/\n/, '')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'pdf-reader'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module DragonflyPdf
|
5
|
+
module Processors
|
6
|
+
describe Stamp do
|
7
|
+
let(:app) { test_app.configure_with(:pdf) }
|
8
|
+
let(:processor) { DragonflyPdf::Processors::Stamp.new }
|
9
|
+
let(:sample_1) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
|
10
|
+
let(:sample_stamp) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_stamp.pdf')) }
|
11
|
+
let(:result) { PDF::Reader.new(sample_1.path) }
|
12
|
+
|
13
|
+
# =====================================================================
|
14
|
+
|
15
|
+
before do
|
16
|
+
processor.call(sample_1, sample_stamp)
|
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 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
|
+
# ---------------------------------------------------------------------
|
32
|
+
|
33
|
+
def get_mime_type(file_path)
|
34
|
+
`file --mime-type #{file_path}`.gsub(/\n/, '')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/test_helper.rb
CHANGED
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.2.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-01-
|
11
|
+
date: 2016-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|
@@ -25,35 +25,35 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.7'
|
34
34
|
type: :development
|
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: '
|
40
|
+
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: guard-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: pdf-reader
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -128,16 +128,23 @@ files:
|
|
128
128
|
- lib/dragonfly_pdf/analysers/pdf_properties.rb
|
129
129
|
- lib/dragonfly_pdf/errors.rb
|
130
130
|
- lib/dragonfly_pdf/plugin.rb
|
131
|
+
- lib/dragonfly_pdf/processors/append.rb
|
131
132
|
- lib/dragonfly_pdf/processors/page.rb
|
132
133
|
- lib/dragonfly_pdf/processors/page_thumb.rb
|
134
|
+
- lib/dragonfly_pdf/processors/rotate.rb
|
135
|
+
- lib/dragonfly_pdf/processors/stamp.rb
|
133
136
|
- lib/dragonfly_pdf/processors/subset_fonts.rb
|
134
137
|
- lib/dragonfly_pdf/version.rb
|
135
138
|
- samples/sample_pages.pdf
|
136
139
|
- samples/sample_pages_with_bleed.pdf
|
140
|
+
- samples/sample_stamp.pdf
|
137
141
|
- test/dragonfly_pdf/analysers/pdf_properties_test.rb
|
138
142
|
- test/dragonfly_pdf/plugin_test.rb
|
143
|
+
- test/dragonfly_pdf/processors/append_test.rb
|
139
144
|
- test/dragonfly_pdf/processors/page_test.rb
|
140
145
|
- test/dragonfly_pdf/processors/page_thumb_test.rb
|
146
|
+
- test/dragonfly_pdf/processors/rotate_test.rb
|
147
|
+
- test/dragonfly_pdf/processors/stamp_test.rb
|
141
148
|
- test/dragonfly_pdf/processors/subset_fonts.rb
|
142
149
|
- test/test_helper.rb
|
143
150
|
homepage: https://github.com/tomasc/dragonfly_pdf
|
@@ -160,14 +167,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
167
|
version: '0'
|
161
168
|
requirements: []
|
162
169
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.4.6
|
164
171
|
signing_key:
|
165
172
|
specification_version: 4
|
166
173
|
summary: Dragonfly PDF analysers and processors.
|
167
174
|
test_files:
|
168
175
|
- test/dragonfly_pdf/analysers/pdf_properties_test.rb
|
169
176
|
- test/dragonfly_pdf/plugin_test.rb
|
177
|
+
- test/dragonfly_pdf/processors/append_test.rb
|
170
178
|
- test/dragonfly_pdf/processors/page_test.rb
|
171
179
|
- test/dragonfly_pdf/processors/page_thumb_test.rb
|
180
|
+
- test/dragonfly_pdf/processors/rotate_test.rb
|
181
|
+
- test/dragonfly_pdf/processors/stamp_test.rb
|
172
182
|
- test/dragonfly_pdf/processors/subset_fonts.rb
|
173
183
|
- test/test_helper.rb
|