pdf_margins 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +3 -0
- data/lib/pdf/margins/checker.rb +11 -15
- data/lib/pdf/margins/version.rb +1 -1
- data/test/checker_test.rb +60 -16
- data/test/pdfs/bottom-margin-only.pdf +0 -0
- data/test/pdfs/clear-margins-pages.pdf +0 -0
- data/test/pdfs/clear-margins-spreads.pdf +0 -0
- data/test/pdfs/left-margin-only.pdf +0 -0
- data/test/pdfs/margins.indd +0 -0
- data/test/pdfs/right-margin-only.pdf +0 -0
- data/test/pdfs/top-margin-only.pdf +0 -0
- metadata +15 -13
- data/test/pdfs/clear-margins.pdf +0 -0
- data/test/pdfs/p2-left-margin-only.pdf +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
M2QzN2FjMWFlN2Y5OTc4ZDM1YzIyNDZmMTVjMTc2NTdjMGY0NzI0ZDIwZTVm
|
10
|
-
YzgzZDA1OWIzN2E5NWIwMDM2MjM3OWYyZmVhZTE0YzkwZjcyYWYwZGIwMTZm
|
11
|
-
MTliZGMwMzkzMmFhZmY2OTAyMDFlMWIyOTNjMWFhMDVmYzM1NWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDNiMzczMDkwYTkxYjRlN2E3Mzc5MDFlNDA0MmNlODU0YmQxNzA1Y2UyODdm
|
14
|
-
NzE4M2ZmZTg0MGY0MTVkZGQyZGI2ZTQ5MzM3NGExOWM2ODZjYmFmOTUyZjg1
|
15
|
-
ZjkwNjEwMjc4NGY2MjUyNGJhYWU4MzQ1ZTA2YjRmYzRjM2RhN2U=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6065ffaa732ecbbbe1d9addb6275715ea9613596
|
4
|
+
data.tar.gz: 8a3e756c74ba210add152540fee7948255bd40ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f89e8ca71ee8d320e7afc9cae7181a839429c23e306b6ce916a4294a6991bc9a4d99c407405d6f102648ab4bf489a0b5d73e97fff1fa68f4cd8eb8a4d569195
|
7
|
+
data.tar.gz: bc12bde2c429fe3eb0ed5b79daa775b837717a773b9ad391209f11c7747b544c650c9c984aecbe6c3c793a6f1d1b6fad57ecf504ffad4b9d5ddc58c3f29747bf
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
pdf/margins
|
2
2
|
==
|
3
3
|
|
4
|
+
[![Build
|
5
|
+
Status](https://travis-ci.org/newspaperclub/pdf_margins.png)](https://travis-ci.org/newspaperclub/pdf_margins)
|
6
|
+
|
4
7
|
Simple Ruby library to check a PDF for clear margin areas, by rendering to
|
5
8
|
a CMYK bitmap, ensuring that the pixel area defined by each margin is empty.
|
6
9
|
It's pretty slow, but this is a lot easier than attempting to work out which
|
data/lib/pdf/margins/checker.rb
CHANGED
@@ -12,15 +12,17 @@ module PDF
|
|
12
12
|
SCALE_MULTIPLIER = 1
|
13
13
|
RESOLUTION = DEFAULT_RESOLUTION * SCALE_MULTIPLIER
|
14
14
|
|
15
|
-
attr_reader :file, :top_margin, :right_margin, :bottom_margin, :left_margin
|
15
|
+
attr_reader :file, :top_margin, :right_margin, :bottom_margin, :left_margin, :spreads
|
16
16
|
|
17
|
-
# Dimensions are in mm, to be converted to PDF points later.
|
18
|
-
|
17
|
+
# Dimensions are in mm, to be converted to PDF points later. Pass spreads
|
18
|
+
# as true to check left and right margins of spreads, not pages.
|
19
|
+
def initialize(file, top_margin, right_margin, bottom_margin, left_margin, spreads=false)
|
19
20
|
@file = file
|
20
21
|
@top_margin = top_margin
|
21
22
|
@right_margin = right_margin
|
22
23
|
@bottom_margin = bottom_margin
|
23
24
|
@left_margin = left_margin
|
25
|
+
@spreads = spreads
|
24
26
|
end
|
25
27
|
|
26
28
|
def issues
|
@@ -45,18 +47,12 @@ module PDF
|
|
45
47
|
page_issues << Issue.new(page_number, :bottom)
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if page_number % 2
|
53
|
-
|
54
|
-
page_issues << Issue.new(page_number, :left)
|
55
|
-
end
|
56
|
-
else
|
57
|
-
if dirty_pixels?(right_pixels(image, right_margin))
|
58
|
-
page_issues << Issue.new(page_number, :right)
|
59
|
-
end
|
50
|
+
if (!spreads || page_number % 2 == 0) && dirty_pixels?(left_pixels(image, left_margin))
|
51
|
+
page_issues << Issue.new(page_number, :left)
|
52
|
+
end
|
53
|
+
|
54
|
+
if (!spreads || page_number % 2 != 0) && dirty_pixels?(right_pixels(image, right_margin))
|
55
|
+
page_issues << Issue.new(page_number, :right)
|
60
56
|
end
|
61
57
|
end
|
62
58
|
end.flatten
|
data/lib/pdf/margins/version.rb
CHANGED
data/test/checker_test.rb
CHANGED
@@ -2,34 +2,78 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class CheckerTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
test "PDF with clear margins" do
|
6
|
-
checker = PDF::Margins::Checker.new(pdf_path('clear-margins.pdf'),
|
5
|
+
test "PDF as pages with clear margins tested as pages" do
|
6
|
+
checker = PDF::Margins::Checker.new(pdf_path('clear-margins-pages.pdf'), 15, 15, 15, 15)
|
7
7
|
assert_equal [], checker.issues
|
8
8
|
end
|
9
9
|
|
10
|
-
test "PDF with
|
11
|
-
checker = PDF::Margins::Checker.new(pdf_path('
|
10
|
+
test "PDF as spreads with clear margins tested as spreads" do
|
11
|
+
checker = PDF::Margins::Checker.new(pdf_path('clear-margins-spreads.pdf'), 15, 15, 15, 15, true)
|
12
12
|
assert_equal [], checker.issues
|
13
13
|
end
|
14
14
|
|
15
|
-
test "PDF with
|
16
|
-
checker = PDF::Margins::Checker.new(pdf_path('
|
17
|
-
assert_equal [
|
15
|
+
test "PDF as spreads with clear margins tested as pages" do
|
16
|
+
checker = PDF::Margins::Checker.new(pdf_path('clear-margins-spreads.pdf'), 15, 15, 15, 15)
|
17
|
+
assert_equal [
|
18
|
+
PDF::Margins::Issue.new(1, :left),
|
19
|
+
PDF::Margins::Issue.new(2, :right),
|
20
|
+
PDF::Margins::Issue.new(3, :left),
|
21
|
+
PDF::Margins::Issue.new(4, :right)
|
22
|
+
], checker.issues
|
18
23
|
end
|
19
24
|
|
20
|
-
test "PDF with dirty
|
21
|
-
checker = PDF::Margins::Checker.new(pdf_path('
|
22
|
-
assert_equal [
|
25
|
+
test "PDF as pages with dirty left margin" do
|
26
|
+
checker = PDF::Margins::Checker.new(pdf_path('left-margin-only.pdf'), 15, 15, 15, 15)
|
27
|
+
assert_equal [
|
28
|
+
PDF::Margins::Issue.new(1, :left)
|
29
|
+
], checker.issues
|
23
30
|
end
|
24
31
|
|
25
|
-
test "PDF with dirty
|
26
|
-
checker = PDF::Margins::Checker.new(pdf_path('
|
27
|
-
assert_equal [
|
32
|
+
test "PDF as pages with dirty right margin" do
|
33
|
+
checker = PDF::Margins::Checker.new(pdf_path('right-margin-only.pdf'), 15, 15, 15, 15)
|
34
|
+
assert_equal [
|
35
|
+
PDF::Margins::Issue.new(1, :right)
|
36
|
+
], checker.issues
|
28
37
|
end
|
29
38
|
|
30
|
-
test "PDF with dirty
|
31
|
-
checker = PDF::Margins::Checker.new(pdf_path('
|
32
|
-
assert_equal [
|
39
|
+
test "PDF with dirty top margin as spreads" do
|
40
|
+
checker = PDF::Margins::Checker.new(pdf_path('top-margin-only.pdf'), 15, 15, 15, 15, true)
|
41
|
+
assert_equal [
|
42
|
+
PDF::Margins::Issue.new(1, :top),
|
43
|
+
PDF::Margins::Issue.new(2, :top),
|
44
|
+
PDF::Margins::Issue.new(3, :top),
|
45
|
+
PDF::Margins::Issue.new(4, :top)
|
46
|
+
], checker.issues
|
47
|
+
end
|
48
|
+
|
49
|
+
test "PDF with dirty bottom margin as spreads" do
|
50
|
+
checker = PDF::Margins::Checker.new(pdf_path('bottom-margin-only.pdf'), 15, 15, 15, 15, true)
|
51
|
+
assert_equal [
|
52
|
+
PDF::Margins::Issue.new(1, :bottom),
|
53
|
+
PDF::Margins::Issue.new(2, :bottom),
|
54
|
+
PDF::Margins::Issue.new(3, :bottom),
|
55
|
+
PDF::Margins::Issue.new(4, :bottom)
|
56
|
+
], checker.issues
|
57
|
+
end
|
58
|
+
|
59
|
+
test "PDF with dirty top margin as pages" do
|
60
|
+
checker = PDF::Margins::Checker.new(pdf_path('top-margin-only.pdf'), 15, 15, 15, 15)
|
61
|
+
assert_equal [
|
62
|
+
PDF::Margins::Issue.new(1, :top),
|
63
|
+
PDF::Margins::Issue.new(2, :top),
|
64
|
+
PDF::Margins::Issue.new(3, :top),
|
65
|
+
PDF::Margins::Issue.new(4, :top)
|
66
|
+
], checker.issues
|
67
|
+
end
|
68
|
+
|
69
|
+
test "PDF with dirty bottom margin as pages" do
|
70
|
+
checker = PDF::Margins::Checker.new(pdf_path('bottom-margin-only.pdf'), 15, 15, 15, 15)
|
71
|
+
assert_equal [
|
72
|
+
PDF::Margins::Issue.new(1, :bottom),
|
73
|
+
PDF::Margins::Issue.new(2, :bottom),
|
74
|
+
PDF::Margins::Issue.new(3, :bottom),
|
75
|
+
PDF::Margins::Issue.new(4, :bottom)
|
76
|
+
], checker.issues
|
33
77
|
end
|
34
78
|
|
35
79
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf_margins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -28,28 +28,28 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
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
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
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
54
|
version: '0'
|
55
55
|
description:
|
@@ -67,9 +67,10 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- test/checker_test.rb
|
69
69
|
- test/pdfs/bottom-margin-only.pdf
|
70
|
-
- test/pdfs/clear-margins.pdf
|
70
|
+
- test/pdfs/clear-margins-pages.pdf
|
71
|
+
- test/pdfs/clear-margins-spreads.pdf
|
71
72
|
- test/pdfs/left-margin-only.pdf
|
72
|
-
- test/pdfs/
|
73
|
+
- test/pdfs/margins.indd
|
73
74
|
- test/pdfs/right-margin-only.pdf
|
74
75
|
- test/pdfs/top-margin-only.pdf
|
75
76
|
- test/test_helper.rb
|
@@ -83,26 +84,27 @@ require_paths:
|
|
83
84
|
- lib
|
84
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
86
|
requirements:
|
86
|
-
- -
|
87
|
+
- - '>='
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
91
|
requirements:
|
91
|
-
- -
|
92
|
+
- - '>='
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
96
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.0.
|
97
|
+
rubygems_version: 2.0.2
|
97
98
|
signing_key:
|
98
99
|
specification_version: 4
|
99
100
|
summary: Simple library to checks whether the margins are clear in a PDF
|
100
101
|
test_files:
|
101
102
|
- test/checker_test.rb
|
102
103
|
- test/pdfs/bottom-margin-only.pdf
|
103
|
-
- test/pdfs/clear-margins.pdf
|
104
|
+
- test/pdfs/clear-margins-pages.pdf
|
105
|
+
- test/pdfs/clear-margins-spreads.pdf
|
104
106
|
- test/pdfs/left-margin-only.pdf
|
105
|
-
- test/pdfs/
|
107
|
+
- test/pdfs/margins.indd
|
106
108
|
- test/pdfs/right-margin-only.pdf
|
107
109
|
- test/pdfs/top-margin-only.pdf
|
108
110
|
- test/test_helper.rb
|
data/test/pdfs/clear-margins.pdf
DELETED
Binary file
|
Binary file
|