pdf_info 0.3.1 → 0.4.0
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.
Potentially problematic release.
This version of pdf_info might be problematic. Click here for more details.
- data/.travis.yml +17 -0
- data/README.md +32 -20
- data/lib/pdf/info.rb +11 -10
- data/lib/pdf/info/version.rb +1 -1
- data/spec/pdf_info_spec.rb +7 -2
- metadata +20 -9
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.8.7
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- ruby-head
|
7
|
+
- jruby
|
8
|
+
- rbx
|
9
|
+
- ree
|
10
|
+
|
11
|
+
before_install:
|
12
|
+
- sudo apt-get update -qq
|
13
|
+
- sudo apt-get install -qq -y poppler-utils poppler-data
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: ruby-head
|
data/README.md
CHANGED
@@ -3,34 +3,46 @@ pdf_info
|
|
3
3
|
|
4
4
|
Very simple wrapper to the [pdfinfo](http://linuxcommand.org/man_pages/pdfinfo1.html) unix tool, to provide the metadata information as a hash.
|
5
5
|
|
6
|
+
[](https://travis-ci.org/newspaperclub/pdf_info)
|
7
|
+
[](https://codeclimate.com/github/newspaperclub/pdf_info)
|
8
|
+
|
6
9
|
Usage
|
7
10
|
--
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
```ruby
|
13
|
+
require 'pdf/info'
|
14
|
+
info = PDF::Info.new('/Users/tom/tmp/magazine.pdf')
|
15
|
+
pp info.metadata
|
16
|
+
```
|
12
17
|
|
13
18
|
Gives you the following output:
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
```ruby
|
21
|
+
{
|
22
|
+
:version => 1.3,
|
23
|
+
:pages => [
|
24
|
+
[819.213, 1077.17],
|
25
|
+
[819.213, 1077.17],
|
26
|
+
[819.213, 1077.17],
|
27
|
+
[819.213, 1077.17],
|
28
|
+
[819.213, 1077.17],
|
29
|
+
[819.213, 1077.17],
|
30
|
+
[819.213, 1077.17],
|
31
|
+
[819.213, 1077.17],
|
32
|
+
[819.213, 1077.17],
|
33
|
+
[819.213, 1077.17],
|
34
|
+
[819.213, 1077.17],
|
35
|
+
[819.213, 1077.17]
|
36
|
+
],
|
37
|
+
:page_count => 12,
|
38
|
+
:encrypted => false
|
39
|
+
}
|
40
|
+
```
|
31
41
|
|
32
42
|
Each of the pages has an individual size in PDF points - that's just how PDFs are. If you want more of the metadata that `pdfinfo` outputs, send us a patch.
|
33
43
|
|
34
44
|
If you need to manually set the path to the `pdfinfo` binary:
|
35
45
|
|
36
|
-
|
46
|
+
```ruby
|
47
|
+
PDF::Info.command_path = "/usr/local/bin/pdfinfo"
|
48
|
+
```
|
data/lib/pdf/info.rb
CHANGED
@@ -20,7 +20,7 @@ module PDF
|
|
20
20
|
output = `#{self.class.command_path} "#{@pdf_path}" -f 1 -l -1`
|
21
21
|
exit_code = $?
|
22
22
|
case exit_code
|
23
|
-
when 0
|
23
|
+
when 0 || nil
|
24
24
|
return output
|
25
25
|
else
|
26
26
|
exit_error = PDF::Info::UnexpectedExitError.new
|
@@ -58,23 +58,24 @@ module PDF
|
|
58
58
|
metadata[:encrypted] = pair.last == 'yes'
|
59
59
|
when "Optimized"
|
60
60
|
metadata[:optimized] = pair.last == 'yes'
|
61
|
+
when "Tagged"
|
62
|
+
metadata[:tagged] = pair.last == 'yes'
|
61
63
|
when "PDF version"
|
62
64
|
metadata[:version] = pair.last.to_f
|
63
|
-
when "
|
64
|
-
metadata[:
|
65
|
-
when "
|
66
|
-
metadata[:
|
67
|
-
when "Producer"
|
68
|
-
metadata[:producer] = pair.last.to_s.strip
|
69
|
-
when "Subject"
|
70
|
-
metadata[:subject] = pair.last.to_s.strip
|
65
|
+
when "CreationDate"
|
66
|
+
metadata[:creation_date] = DateTime.parse(pair.last)
|
67
|
+
when "ModDate"
|
68
|
+
metadata[:modification_date] = DateTime.parse(pair.last)
|
71
69
|
when /^Page.*size$/
|
72
70
|
metadata[:pages] ||= []
|
73
71
|
metadata[:pages] << pair.last.scan(/[\d.]+/).map(&:to_f)
|
74
72
|
metadata[:format] = pair.last.scan(/.*\(\w+\)$/).to_s
|
73
|
+
when String
|
74
|
+
metadata[pair.first.downcase.tr(" ", "_").to_sym] = pair.last.to_s.strip
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
|
+
metadata
|
78
79
|
end
|
79
80
|
|
80
81
|
end
|
data/lib/pdf/info/version.rb
CHANGED
data/spec/pdf_info_spec.rb
CHANGED
@@ -97,10 +97,15 @@ describe PDF::Info do
|
|
97
97
|
its([:creator]) { should == "PScript5.dll Version 5.2.2" }
|
98
98
|
its([:version]) { should == 1.4 }
|
99
99
|
its([:title]) { should == "Microsoft Word - sample.pdf.docx" }
|
100
|
-
its([:encrypted]) { should
|
101
|
-
its([:optimized]) { should
|
100
|
+
its([:encrypted]) { should be_false }
|
101
|
+
its([:optimized]) { should be_false }
|
102
102
|
its([:producer]) { should == "GPL Ghostscript 8.15" }
|
103
103
|
its([:subject]) { should be_nil }
|
104
|
+
its([:author]) { should eq "carlos"}
|
105
|
+
its([:creation_date]) { should eq DateTime.parse("2010-10-09T10:29:55+00:00")}
|
106
|
+
its([:modification_date]) { should eq DateTime.parse("2010-10-09T10:29:55+00:00")}
|
107
|
+
its([:tagged]) { should be_false }
|
108
|
+
its([:file_size]) { should eq "218882 bytes" }
|
104
109
|
end
|
105
110
|
|
106
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description:
|
37
47
|
email:
|
38
48
|
- tom@tomtaylor.co.uk
|
@@ -43,6 +53,7 @@ files:
|
|
43
53
|
- .document
|
44
54
|
- .gitignore
|
45
55
|
- .rspec
|
56
|
+
- .travis.yml
|
46
57
|
- Gemfile
|
47
58
|
- LICENSE.txt
|
48
59
|
- README.md
|
@@ -71,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
82
|
version: '0'
|
72
83
|
segments:
|
73
84
|
- 0
|
74
|
-
hash: -
|
85
|
+
hash: -1371290085031323010
|
75
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
87
|
none: false
|
77
88
|
requirements:
|
@@ -80,10 +91,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
91
|
version: '0'
|
81
92
|
segments:
|
82
93
|
- 0
|
83
|
-
hash: -
|
94
|
+
hash: -1371290085031323010
|
84
95
|
requirements: []
|
85
96
|
rubyforge_project: pdf_info
|
86
|
-
rubygems_version: 1.8.
|
97
|
+
rubygems_version: 1.8.23
|
87
98
|
signing_key:
|
88
99
|
specification_version: 3
|
89
100
|
summary: Wraps the pdfinfo command line tool to provide a hash of metadata
|