pdfinfo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5a425d0b0736d042ad6cb90cd730ec12b1086cc
4
+ data.tar.gz: f50db651591c946a6788ccdbb12ff3d9093ff789
5
+ SHA512:
6
+ metadata.gz: e4b84b0d845a22db0e09d7651d6a62bd1af84108baa533af16d48975bfdba3ae28f3db9430acfb34e8a5c32aa894593910af66e93f994ad89f32aa69ae5a9d01
7
+ data.tar.gz: 17b53e239955de60c1c75a531b3dbfe603c1e92d356f425aa0cb94c2f01a151943876034528d4b9ed2b3917d1163dc3cc10198ad171379df4b6bfe8dbd5642a5
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ pdfinfo
@@ -0,0 +1 @@
1
+ 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryan Venegas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Pdfinfo
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pdfinfo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pdfinfo
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/pdfinfo/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,65 @@
1
+ require 'open3'
2
+ require 'pathname'
3
+
4
+ class Pdfinfo
5
+ DIMENSIONS_REGEXP = /(\d+) x (\d+)/
6
+
7
+ attr_reader :creator,
8
+ :producer,
9
+ :form,
10
+ :page_count,
11
+ :width,
12
+ :height,
13
+ :file_size,
14
+ :pdf_version
15
+
16
+ def self.exec(file_path)
17
+ stdout, stderr, status = Open3.capture2e("pdfinfo #{file_path}")
18
+ stdout.chomp
19
+ end
20
+
21
+ def self.pdfinfo_command
22
+ @pdfinfo_command || 'pdfinfo'
23
+ end
24
+
25
+ def self.pdfinfo_command=(cmd)
26
+ @pdfinfo_command = cmd
27
+ end
28
+
29
+ def initialize(source_path)
30
+ info_hash = parse_shell_response(exec(source_path))
31
+
32
+ @creator = info_hash['Creator']
33
+ @producer = info_hash['Producer']
34
+ @tagged = !!(info_hash['Tagged'] =~ /yes/)
35
+ @form = info_hash['Form']
36
+ @page_count = info_hash['Pages'].to_i
37
+ @encrypted = !!(info_hash['Encrypted'] =~ /yes/)
38
+ @width, @height = extract_page_dimensions(info_hash['Page size'])
39
+ @file_size = info_hash['File size'].to_i
40
+ @pdf_version = info_hash['PDF version']
41
+ end
42
+
43
+ def tagged?
44
+ @tagged
45
+ end
46
+
47
+ def encrypted?
48
+ @encrypted
49
+ end
50
+
51
+ private
52
+
53
+ def exec(file_path)
54
+ self.class.exec(file_path)
55
+ end
56
+
57
+ def parse_shell_response(response_str)
58
+ Hash[response_str.split(/\n/).map {|kv| kv.split(/:\s+/) }]
59
+ end
60
+
61
+ def extract_page_dimensions(str)
62
+ return unless str
63
+ str.match(DIMENSIONS_REGEXP).captures.map(&:to_i)
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ class Pdfinfo
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pdfinfo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pdfinfo"
8
+ spec.version = Pdfinfo::VERSION
9
+ spec.authors = ["Ryan Venegas"]
10
+ spec.email = ["RVenegas2@Gmail.com"]
11
+ spec.summary = %q{Simple ruby wrapper around the pdfinfo executable}
12
+ spec.description = %q{Simple ruby wrapper around the pdfinfo executable}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,10 @@
1
+ Creator: Prawn
2
+ Producer: Prawn
3
+ Tagged: no
4
+ Form: none
5
+ Pages: 3
6
+ Encrypted: no
7
+ Page size: 612 x 792 pts (letter) (rotated 0 degrees)
8
+ File size: 1521 bytes
9
+ Optimized: no
10
+ PDF version: 1.3
@@ -0,0 +1,127 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 3
16
+ /Kids [5 0 R 8 0 R 10 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 71
21
+ >>
22
+ stream
23
+ q
24
+
25
+ BT
26
+ 36 747.384 Td
27
+ /F1.0 12 Tf
28
+ [<50> 120 <41> 30 <47452031>] TJ
29
+ ET
30
+
31
+ Q
32
+
33
+ endstream
34
+ endobj
35
+ 5 0 obj
36
+ << /Type /Page
37
+ /Parent 3 0 R
38
+ /MediaBox [0 0 612.0 792.0]
39
+ /Contents 4 0 R
40
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
41
+ /Font << /F1.0 6 0 R
42
+ >>
43
+ >>
44
+ >>
45
+ endobj
46
+ 6 0 obj
47
+ << /Type /Font
48
+ /Subtype /Type1
49
+ /BaseFont /Helvetica
50
+ /Encoding /WinAnsiEncoding
51
+ >>
52
+ endobj
53
+ 7 0 obj
54
+ << /Length 71
55
+ >>
56
+ stream
57
+ q
58
+
59
+ BT
60
+ 36 747.384 Td
61
+ /F1.0 12 Tf
62
+ [<50> 120 <41> 30 <47452032>] TJ
63
+ ET
64
+
65
+ Q
66
+
67
+ endstream
68
+ endobj
69
+ 8 0 obj
70
+ << /Type /Page
71
+ /Parent 3 0 R
72
+ /MediaBox [0 0 612.0 792.0]
73
+ /Contents 7 0 R
74
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
75
+ /Font << /F1.0 6 0 R
76
+ >>
77
+ >>
78
+ >>
79
+ endobj
80
+ 9 0 obj
81
+ << /Length 71
82
+ >>
83
+ stream
84
+ q
85
+
86
+ BT
87
+ 36 747.384 Td
88
+ /F1.0 12 Tf
89
+ [<50> 120 <41> 30 <47452033>] TJ
90
+ ET
91
+
92
+ Q
93
+
94
+ endstream
95
+ endobj
96
+ 10 0 obj
97
+ << /Type /Page
98
+ /Parent 3 0 R
99
+ /MediaBox [0 0 612.0 792.0]
100
+ /Contents 9 0 R
101
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
102
+ /Font << /F1.0 6 0 R
103
+ >>
104
+ >>
105
+ >>
106
+ endobj
107
+ xref
108
+ 0 11
109
+ 0000000000 65535 f
110
+ 0000000015 00000 n
111
+ 0000000109 00000 n
112
+ 0000000158 00000 n
113
+ 0000000228 00000 n
114
+ 0000000349 00000 n
115
+ 0000000527 00000 n
116
+ 0000000624 00000 n
117
+ 0000000745 00000 n
118
+ 0000000923 00000 n
119
+ 0000001044 00000 n
120
+ trailer
121
+ << /Size 11
122
+ /Root 2 0 R
123
+ /Info 1 0 R
124
+ >>
125
+ startxref
126
+ 1223
127
+ %%EOF
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Pdfinfo do
4
+ let(:pdf_path) { fixture_path('test.pdf') }
5
+ let(:pdfinfo) { described_class.new(pdf_path) }
6
+ let(:mock_response) { File.read(fixture_path('shell_response.txt')).chomp }
7
+
8
+ before(:suite) do
9
+ # validate that our mock response matches the real response
10
+ expect(described_class.exec(pdf_path)).to eq(mock_response)
11
+ end
12
+
13
+ before(:each) do
14
+ allow(described_class).to receive(:exec).and_return(mock_response)
15
+ end
16
+
17
+ describe 'pdfinfo_command' do
18
+ it "falls back to pdfinfo" do
19
+ Pdfinfo.pdfinfo_command = nil
20
+ expect(Pdfinfo.pdfinfo_command).to eq('pdfinfo')
21
+ end
22
+
23
+ it 'allows the command to be changed' do
24
+ Pdfinfo.pdfinfo_command = '/another/bin/path/pdfinfo'
25
+ expect(Pdfinfo.pdfinfo_command).to eq('/another/bin/path/pdfinfo')
26
+ end
27
+ end
28
+
29
+ describe '#creator' do
30
+ context 'when given a creator' do
31
+ it { expect(pdfinfo.creator).to eq('Prawn') }
32
+ end
33
+ context 'when creator is not present' do
34
+ let(:mock_response) { "Creator: \n" }
35
+ it { expect(pdfinfo.creator).to be_nil }
36
+ end
37
+ end
38
+
39
+ describe '#producer' do
40
+ context 'when given a creator' do
41
+ it { expect(pdfinfo.producer).to eq('Prawn') }
42
+ end
43
+ context 'when creator is not present' do
44
+ let(:mock_response) { "Producer: \n" }
45
+ it { expect(pdfinfo.producer).to be_nil }
46
+ end
47
+ end
48
+
49
+ describe 'tagged?' do
50
+ context 'when tagged' do
51
+ let(:mock_response) { "Tagged: yes" }
52
+ it { expect(pdfinfo.tagged?).to eq(true) }
53
+ end
54
+ context 'when not tagged' do
55
+ let(:mock_response) { "Tagged: no" }
56
+ it { expect(pdfinfo.tagged?).to eq(false) }
57
+ end
58
+ end
59
+
60
+ describe '#form' do
61
+ it { expect(pdfinfo.form).to eq('none') }
62
+ end
63
+
64
+ describe 'page_count' do
65
+ it 'returns a fixnum value of the number of pages' do
66
+ expect(pdfinfo.page_count).to eq(3)
67
+ end
68
+ end
69
+
70
+ describe 'encrypted?' do
71
+ context 'given encrypted pdf' do
72
+ let(:mock_response) { "Encrypted: yes\n" }
73
+ it { expect(pdfinfo.encrypted?).to eq(true) }
74
+ end
75
+ context 'given unencrypted pdf' do
76
+ let(:mock_response) { 'Encrypted: no' }
77
+ it { expect(pdfinfo.encrypted?).to eq(false) }
78
+ end
79
+ end
80
+
81
+ describe 'width' do
82
+ it { expect(pdfinfo.width).to eq(612) }
83
+ end
84
+
85
+ describe 'height' do
86
+ it { expect(pdfinfo.height).to eq(792) }
87
+ end
88
+
89
+ describe 'size' do
90
+ it 'returns a fixnm value for the file size in bytes' do
91
+ expect(pdfinfo.file_size).to eq(1521)
92
+ end
93
+ end
94
+
95
+ describe 'pdf_version' do
96
+ it 'returns a string value for the PDF spec version' do
97
+ expect(pdfinfo.pdf_version).to eq('1.3')
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path("#{__dir__}/../lib/pdfinfo")
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ # expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ config.filter_run :focus
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ config.disable_monkey_patching!
16
+
17
+ config.warnings = false
18
+
19
+ if config.files_to_run.one?
20
+ config.default_formatter = 'doc'
21
+ end
22
+
23
+ # config.profile_examples = 10
24
+
25
+ config.order = :random
26
+
27
+ Kernel.srand config.seed
28
+
29
+ config.before(:each) do
30
+ Pdfinfo.instance_variable_set(:@pdfinfo_command, nil)
31
+ end
32
+ end
33
+
34
+ def fixture_path(path)
35
+ Pathname.new(File.expand_path(File.join("../fixtures", path), __FILE__))
36
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdfinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Venegas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Simple ruby wrapper around the pdfinfo executable
56
+ email:
57
+ - RVenegas2@Gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".ruby-gemset"
65
+ - ".ruby-version"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/pdfinfo.rb
71
+ - lib/pdfinfo/version.rb
72
+ - pdfinfo.gemspec
73
+ - spec/fixtures/shell_response.txt
74
+ - spec/fixtures/test.pdf
75
+ - spec/pdfinfo_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Simple ruby wrapper around the pdfinfo executable
101
+ test_files:
102
+ - spec/fixtures/shell_response.txt
103
+ - spec/fixtures/test.pdf
104
+ - spec/pdfinfo_spec.rb
105
+ - spec/spec_helper.rb