dragonfly_pdf 0.2.5 → 0.2.6
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/dragonfly_pdf.gemspec +15 -15
- data/lib/dragonfly_pdf.rb +3 -2
- data/lib/dragonfly_pdf/analysers/pdf_properties.rb +6 -6
- data/lib/dragonfly_pdf/errors.rb +1 -1
- data/lib/dragonfly_pdf/processors/append.rb +1 -1
- data/lib/dragonfly_pdf/processors/page.rb +1 -1
- data/lib/dragonfly_pdf/processors/page_thumb.rb +2 -7
- 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 +2 -2
- data/lib/dragonfly_pdf/version.rb +1 -1
- data/test/dragonfly_pdf/analysers/pdf_properties_test.rb +4 -4
- data/test/dragonfly_pdf/processors/append_test.rb +1 -1
- data/test/dragonfly_pdf/processors/page_test.rb +1 -1
- data/test/dragonfly_pdf/processors/page_thumb_test.rb +1 -1
- data/test/dragonfly_pdf/processors/remove_password_test.rb +1 -1
- data/test/dragonfly_pdf/processors/rotate_test.rb +1 -1
- data/test/dragonfly_pdf/processors/stamp_test.rb +1 -1
- data/test/dragonfly_pdf/processors/subset_fonts.rb +3 -3
- data/test/test_helper.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fc722543b372f865b8d4eb0ab182770d4653316
|
4
|
+
data.tar.gz: 1e0738ba31044b375180d60cae924da0fe43ca9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb1121c63fe16f5d364f098e23ed4edb46740b1c871622dea3da541e85b1e56f6b929fe54c5275432e48b43517fea1eb49733ff5438717f79911b9e9355f4bc2
|
7
|
+
data.tar.gz: 6704887572f6b7620b2bbb3f87d4d725fe06492c4902b81b7725d8b8858d7d2a0a1976529534ba79f569780449a2cf09817898ba2b4ed583b89d6d3e1825feac
|
data/.travis.yml
CHANGED
data/dragonfly_pdf.gemspec
CHANGED
@@ -4,26 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'dragonfly_pdf/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'dragonfly_pdf'
|
8
8
|
spec.version = DragonflyPdf::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
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
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'dragonfly', '~> 1.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'guard'
|
25
|
+
spec.add_development_dependency 'guard-minitest'
|
26
|
+
spec.add_development_dependency 'minitest'
|
27
|
+
spec.add_development_dependency 'pdf-reader'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
29
|
end
|
data/lib/dragonfly_pdf.rb
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'dragonfly'
|
2
|
+
require 'dragonfly_pdf/plugin'
|
3
|
+
require 'dragonfly_pdf/version'
|
@@ -6,20 +6,20 @@ module DragonflyPdf
|
|
6
6
|
|
7
7
|
box_data = []
|
8
8
|
rotate_data = []
|
9
|
-
IO.foreach(content.path, "\n\n", encoding:
|
9
|
+
IO.foreach(content.path, "\n\n", encoding: 'ISO-8859-1') do |item|
|
10
10
|
box_data += item.scan(/(MediaBox|CropBox|BleedBox|TrimBox)\s?\[([\d\.]+?)\s([\d\.]+?)\s([\d\.]+?)\s([\d\.]+?)\]/)
|
11
11
|
rotate_data += item.scan(/\/Rotate\s(\d+?)\s/)
|
12
12
|
end
|
13
13
|
|
14
|
-
media_box = box_data.select{ |d| d.first =~ /mediabox/i }
|
15
|
-
desired_box = box_data.select{ |d| d.first =~ /#{box_type}/i }
|
14
|
+
media_box = box_data.select { |d| d.first =~ /mediabox/i }
|
15
|
+
desired_box = box_data.select { |d| d.first =~ /#{box_type}/i }
|
16
16
|
|
17
17
|
# drop last value, since that comes from data about all pages
|
18
18
|
media_box = media_box[0..-2] if media_box.length > 1
|
19
19
|
|
20
|
-
page_dimensions = (desired_box.
|
21
|
-
i = dim[1..-1].map(&:to_f).map{ |d| pt2mm(d) }
|
22
|
-
[
|
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
23
|
end
|
24
24
|
|
25
25
|
page_count = page_dimensions.count
|
data/lib/dragonfly_pdf/errors.rb
CHANGED
@@ -6,7 +6,7 @@ module DragonflyPdf
|
|
6
6
|
class Page
|
7
7
|
def call(content, page_number = 1, _opts = {})
|
8
8
|
pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
|
9
|
-
|
9
|
+
raise DragonflyPdf::PageNotFound unless pdf_properties[:page_numbers].include?(page_number)
|
10
10
|
|
11
11
|
content.shell_update(ext: :pdf) do |old_path, new_path|
|
12
12
|
"#{gs_command} -dFirstPage=#{page_number} -dLastPage=#{page_number} -o #{new_path} -f #{old_path}"
|
@@ -8,8 +8,7 @@ module DragonflyPdf
|
|
8
8
|
@page_number = page_number
|
9
9
|
@format = opts['format'] || :png
|
10
10
|
@density = opts['density'] || 150
|
11
|
-
|
12
|
-
# fail DragonflyPdf::PageNotFound unless pdf_properties[:page_numbers].include?(@page_number)
|
11
|
+
@crop_args = opts['crop_args']
|
13
12
|
|
14
13
|
content.shell_update(ext: @format) do |old_path, new_path|
|
15
14
|
"#{convert_command} #{old_path}[#{pdf_page_number}] #{new_path}"
|
@@ -27,12 +26,8 @@ module DragonflyPdf
|
|
27
26
|
|
28
27
|
private # =============================================================
|
29
28
|
|
30
|
-
def pdf_properties
|
31
|
-
@pdf_properties ||= DragonflyPdf::Analysers::PdfProperties.new.call(@content)
|
32
|
-
end
|
33
|
-
|
34
29
|
def convert_command
|
35
|
-
"convert -alpha deactivate -background white -colorspace sRGB -density #{@density}x#{@density} -define pdf:use-cropbox=true -define pdf:use-trimbox=true"
|
30
|
+
"convert -alpha deactivate -background white -colorspace sRGB -density #{@density}x#{@density} -define pdf:use-cropbox=true -define pdf:use-trimbox=true #{@crop_args}"
|
36
31
|
end
|
37
32
|
|
38
33
|
def pdf_page_number
|
@@ -4,7 +4,7 @@ module DragonflyPdf
|
|
4
4
|
def call(content, arg)
|
5
5
|
rotate_args = case arg
|
6
6
|
when String, Symbol
|
7
|
-
|
7
|
+
raise ArgumentError unless arg =~ /north|south|east|west|left|right|down/i
|
8
8
|
"1-end#{arg}"
|
9
9
|
when Hash
|
10
10
|
pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DragonflyPdf
|
2
2
|
module Processors
|
3
3
|
class SubsetFonts
|
4
|
-
def call
|
4
|
+
def call(content, _opts = {})
|
5
5
|
content.shell_update(ext: :pdf) do |old_path, new_path|
|
6
6
|
"#{gs_command} -o #{new_path} -f #{old_path}"
|
7
7
|
end
|
@@ -10,7 +10,7 @@ module DragonflyPdf
|
|
10
10
|
private # =============================================================
|
11
11
|
|
12
12
|
def gs_command
|
13
|
-
|
13
|
+
'gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSubsetFonts=true'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -31,15 +31,15 @@ module DragonflyPdf
|
|
31
31
|
|
32
32
|
describe '#page_dimensions' do
|
33
33
|
it 'returns array of page dimensions' do
|
34
|
-
analyser.call(sample_pages)[:page_dimensions].map{ |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(10)
|
35
|
-
analyser.call(sample_pages_with_bleed)[:page_dimensions].map{ |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(1)
|
34
|
+
analyser.call(sample_pages)[:page_dimensions].map { |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(10)
|
35
|
+
analyser.call(sample_pages_with_bleed)[:page_dimensions].map { |p| p.map(&:round) }.must_equal [[210, 297]].cycle.take(1)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '#aspect_ratios' do
|
40
40
|
it 'returns aspect ratios' do
|
41
|
-
analyser.call(sample_pages)[:aspect_ratios].map{ |i| i.round(2) }.must_equal [0.71].cycle.take(10)
|
42
|
-
analyser.call(sample_pages_with_bleed)[:aspect_ratios].map{ |i| i.round(2) }.must_equal [0.71].cycle.take(1)
|
41
|
+
analyser.call(sample_pages)[:aspect_ratios].map { |i| i.round(2) }.must_equal [0.71].cycle.take(10)
|
42
|
+
analyser.call(sample_pages_with_bleed)[:aspect_ratios].map { |i| i.round(2) }.must_equal [0.71].cycle.take(1)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -9,13 +9,13 @@ module DragonflyPdf
|
|
9
9
|
|
10
10
|
it 'returns PDF by default' do
|
11
11
|
processor.call(sample_pages, 1)
|
12
|
-
get_mime_type(sample_pages.path).must_include
|
12
|
+
get_mime_type(sample_pages.path).must_include 'application/pdf'
|
13
13
|
end
|
14
14
|
|
15
15
|
private # =============================================================
|
16
16
|
|
17
|
-
def get_mime_type
|
18
|
-
`file --mime-type #{file_path}`.
|
17
|
+
def get_mime_type(file_path)
|
18
|
+
`file --mime-type #{file_path}`.delete("\n")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/test/test_helper.rb
CHANGED
@@ -13,9 +13,9 @@ SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
|
|
13
13
|
|
14
14
|
# ---------------------------------------------------------------------
|
15
15
|
|
16
|
-
def test_app
|
16
|
+
def test_app(name = nil)
|
17
17
|
app = Dragonfly::App.instance(name)
|
18
18
|
app.datastore = Dragonfly::MemoryDataStore.new
|
19
|
-
app.secret =
|
19
|
+
app.secret = 'test secret'
|
20
20
|
app
|
21
21
|
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.2.
|
4
|
+
version: 0.2.6
|
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-
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.4.
|
174
|
+
rubygems_version: 2.4.5.1
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Dragonfly PDF analysers and processors.
|