pdf_outline_editor 0.1.0-java → 0.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/exe/pdf_outline_editor +4 -3
- data/lib/pdf_outline_editor.rb +3 -1
- data/lib/pdf_outline_editor/commands/dump_command.rb +5 -5
- data/lib/pdf_outline_editor/commands/init_command.rb +4 -2
- data/lib/pdf_outline_editor/commands/load_command.rb +10 -6
- data/lib/pdf_outline_editor/dumper.rb +12 -11
- data/lib/pdf_outline_editor/loader.rb +11 -10
- data/lib/pdf_outline_editor/runner.rb +11 -13
- data/lib/pdf_outline_editor/version.rb +3 -1
- data/vendor/pdfbox/{pdfbox-app-2.0.13.jar → pdfbox-app-2.0.19.jar} +0 -0
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 838d9b32a11014f56a8dbe2c0451bea0c2ebf31e0612773b08baa6ed976da101
|
4
|
+
data.tar.gz: b6093c9d2d13b60ab303febea5ea6c3b5a23e97c5675102f4a474e60ca2fc554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d58ba781a8de58fa6c6100c4a66a212e4396db7745afa6205c5a1043902d4cee112b776c1857bd5538c5a8fd7afa91e78bbcd213291beb2517f506a2db5cbc17
|
7
|
+
data.tar.gz: 288e09ced447ecbae03e07ac529552c15cd934abf1bf751e0afa9a1e825c8a25037e2e08993c629424b35dfc3bfd4bb36e2ff43fabb3cdb0b3f3fb8565a80d1e
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# pdf\_outline\_editor
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/healthypackrat/pdf_outline_editor.svg?branch=master)](https://travis-ci.org/healthypackrat/pdf_outline_editor)
|
4
4
|
|
@@ -38,7 +38,11 @@ $ pdf_outline_editor load input.pdf toc.json output.pdf
|
|
38
38
|
|
39
39
|
## Development
|
40
40
|
|
41
|
-
Run `bin/jruby-ng-server` in
|
41
|
+
Run `bin/jruby-ng-server` in background for faster loading.
|
42
|
+
|
43
|
+
```
|
44
|
+
$ bin/jruby-ng-server &
|
45
|
+
```
|
42
46
|
|
43
47
|
Then run `bin/rspec` to run the specs.
|
44
48
|
|
data/exe/pdf_outline_editor
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env jruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
+
require 'pdf_outline_editor'
|
4
5
|
|
5
6
|
begin
|
6
7
|
runner = PdfOutlineEditor::Runner.new(ARGV)
|
7
8
|
runner.run
|
8
|
-
rescue PdfOutlineEditor::Error =>
|
9
|
-
warn
|
9
|
+
rescue PdfOutlineEditor::Error => e
|
10
|
+
warn e.message
|
10
11
|
exit 1
|
11
12
|
end
|
data/lib/pdf_outline_editor.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
|
3
5
|
module PdfOutlineEditor
|
@@ -8,7 +10,7 @@ module PdfOutlineEditor
|
|
8
10
|
def initialize(argv)
|
9
11
|
@parser = nil
|
10
12
|
|
11
|
-
@output_formats = [
|
13
|
+
@output_formats = %i[json yaml]
|
12
14
|
@output_format = :json
|
13
15
|
|
14
16
|
@input_pdf_path = nil
|
@@ -22,9 +24,7 @@ module PdfOutlineEditor
|
|
22
24
|
Dumper.open(@input_pdf_path) do |dumper|
|
23
25
|
outlines = dumper.dump
|
24
26
|
|
25
|
-
if outlines
|
26
|
-
puts send("convert_to_#{@output_format}", outlines)
|
27
|
-
end
|
27
|
+
puts send("convert_to_#{@output_format}", outlines) if outlines
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ module PdfOutlineEditor
|
|
35
35
|
|
36
36
|
@parser = OptionParser.new
|
37
37
|
|
38
|
-
@parser.banner = "Usage: #{File.basename($
|
38
|
+
@parser.banner = "Usage: #{File.basename($PROGRAM_NAME)} dump [options] <input-pdf-path>"
|
39
39
|
|
40
40
|
desc = "Output format (default: #{@output_format}; one of #{@output_formats.join(', ')})"
|
41
41
|
@parser.on('-f', '--format=FORMAT', @output_formats, desc) do |value|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
|
3
5
|
module PdfOutlineEditor
|
@@ -8,7 +10,7 @@ module PdfOutlineEditor
|
|
8
10
|
def initialize(argv)
|
9
11
|
@parser = nil
|
10
12
|
|
11
|
-
@output_formats = [
|
13
|
+
@output_formats = %i[json yaml]
|
12
14
|
@output_format = :json
|
13
15
|
|
14
16
|
parser.parse!(argv)
|
@@ -42,7 +44,7 @@ module PdfOutlineEditor
|
|
42
44
|
|
43
45
|
@parser = OptionParser.new
|
44
46
|
|
45
|
-
@parser.banner = "Usage: #{File.basename($
|
47
|
+
@parser.banner = "Usage: #{File.basename($PROGRAM_NAME)} init [options]"
|
46
48
|
|
47
49
|
desc = "Output format (default: #{@output_format}; one of #{@output_formats.join(', ')})"
|
48
50
|
@parser.on('-f', '--format=FORMAT', @output_formats, desc) do |value|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
|
3
5
|
module PdfOutlineEditor
|
@@ -29,20 +31,24 @@ module PdfOutlineEditor
|
|
29
31
|
|
30
32
|
@parser = OptionParser.new
|
31
33
|
|
32
|
-
@parser.banner = "Usage: #{File.basename($
|
34
|
+
@parser.banner = "Usage: #{File.basename($PROGRAM_NAME)} load <input-pdf-path> <input-outlines-path> <output-pdf-path>"
|
33
35
|
|
34
36
|
@parser
|
35
37
|
end
|
36
38
|
|
37
39
|
def handle_args(argv)
|
38
40
|
@input_pdf_path = argv.shift
|
41
|
+
|
39
42
|
raise Error, 'missing input pdf path' unless @input_pdf_path
|
40
43
|
|
41
44
|
input_outlines_path = argv.shift
|
45
|
+
|
42
46
|
raise Error, 'missing input outlines path' unless input_outlines_path
|
47
|
+
|
43
48
|
@outlines = parse_outlines(input_outlines_path)
|
44
49
|
|
45
50
|
@output_pdf_path = argv.shift
|
51
|
+
|
46
52
|
raise Error, 'missing output pdf path' unless @output_pdf_path
|
47
53
|
end
|
48
54
|
|
@@ -51,11 +57,9 @@ module PdfOutlineEditor
|
|
51
57
|
|
52
58
|
method_name = "parse_#{ext}_outlines"
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
raise Error, "unknown extension: #{ext}"
|
58
|
-
end
|
60
|
+
raise Error, "unknown extension: #{ext}" unless respond_to?(method_name, true)
|
61
|
+
|
62
|
+
send(method_name, path)
|
59
63
|
end
|
60
64
|
|
61
65
|
def parse_json_outlines(path)
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PdfOutlineEditor
|
2
4
|
class Dumper
|
3
5
|
java_import org.apache.pdfbox.pdmodel.PDDocument
|
4
6
|
|
5
7
|
JavaFile = java.io.File
|
8
|
+
IOException = java.io.IOException
|
6
9
|
|
7
10
|
def self.open(input_pdf_path)
|
8
11
|
dumper = new(input_pdf_path)
|
@@ -19,8 +22,8 @@ module PdfOutlineEditor
|
|
19
22
|
def initialize(input_pdf_path)
|
20
23
|
begin
|
21
24
|
@doc = PDDocument.load(JavaFile.new(input_pdf_path))
|
22
|
-
rescue
|
23
|
-
raise Error,
|
25
|
+
rescue IOException => e
|
26
|
+
raise Error, e.message
|
24
27
|
end
|
25
28
|
|
26
29
|
@pages = @doc.pages
|
@@ -31,18 +34,16 @@ module PdfOutlineEditor
|
|
31
34
|
def dump
|
32
35
|
root_outline = @doc.document_catalog.document_outline
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
nil
|
38
|
-
end
|
37
|
+
return unless root_outline
|
38
|
+
|
39
|
+
traverse(root_outline)
|
39
40
|
end
|
40
41
|
|
41
42
|
def close
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
return if @closed
|
44
|
+
|
45
|
+
@doc.close
|
46
|
+
@closed = true
|
46
47
|
end
|
47
48
|
|
48
49
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PdfOutlineEditor
|
2
4
|
class Loader
|
3
5
|
java_import org.apache.pdfbox.pdmodel.PDDocument
|
@@ -6,6 +8,7 @@ module PdfOutlineEditor
|
|
6
8
|
java_import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem
|
7
9
|
|
8
10
|
JavaFile = java.io.File
|
11
|
+
IOException = java.io.IOException
|
9
12
|
|
10
13
|
def self.open(input_pdf_path)
|
11
14
|
loader = new(input_pdf_path)
|
@@ -22,8 +25,8 @@ module PdfOutlineEditor
|
|
22
25
|
def initialize(input_pdf_path)
|
23
26
|
begin
|
24
27
|
@doc = PDDocument.load(JavaFile.new(input_pdf_path))
|
25
|
-
rescue
|
26
|
-
raise Error,
|
28
|
+
rescue IOException => e
|
29
|
+
raise Error, e.message
|
27
30
|
end
|
28
31
|
|
29
32
|
@pages = @doc.pages.to_a
|
@@ -32,7 +35,7 @@ module PdfOutlineEditor
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def load(entries)
|
35
|
-
root_outline =
|
38
|
+
root_outline = PDDocumentOutline.new
|
36
39
|
|
37
40
|
@doc.document_catalog.document_outline = root_outline
|
38
41
|
|
@@ -46,10 +49,10 @@ module PdfOutlineEditor
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def close
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
return if @closed
|
53
|
+
|
54
|
+
@doc.close
|
55
|
+
@closed = true
|
53
56
|
end
|
54
57
|
|
55
58
|
private
|
@@ -59,9 +62,7 @@ module PdfOutlineEditor
|
|
59
62
|
|
60
63
|
max_page_number = @pages.size
|
61
64
|
|
62
|
-
unless (1..max_page_number).include?(page_number)
|
63
|
-
raise Error, "page number must be between 1 and #{max_page_number}: got #{page_number}"
|
64
|
-
end
|
65
|
+
raise Error, "page number must be between 1 and #{max_page_number}: got #{page_number}" unless (1..max_page_number).include?(page_number)
|
65
66
|
|
66
67
|
page = @pages[page_number - 1]
|
67
68
|
|
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
|
3
5
|
module PdfOutlineEditor
|
4
6
|
class Runner
|
5
7
|
class << self
|
6
|
-
|
8
|
+
known_commands = {}
|
7
9
|
|
8
10
|
define_method :known_commands do
|
9
|
-
|
11
|
+
known_commands
|
10
12
|
end
|
11
13
|
|
12
14
|
define_method :register_command do |key, klass|
|
13
|
-
|
15
|
+
known_commands[key] = klass
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -23,20 +25,16 @@ module PdfOutlineEditor
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def run
|
26
|
-
if @argv.empty?
|
27
|
-
raise Error, "missing a command: available commands are #{Runner.known_commands.keys.sort.join(', ')}"
|
28
|
-
end
|
28
|
+
raise Error, "missing a command: available commands are #{Runner.known_commands.keys.sort.join(', ')}" if @argv.empty?
|
29
29
|
|
30
30
|
command_name = @argv.shift
|
31
31
|
|
32
32
|
command_class = Runner.known_commands[command_name.to_sym]
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
raise Error, "unknown command: #{command_name}"
|
39
|
-
end
|
34
|
+
raise Error, "unknown command: #{command_name}" unless command_class
|
35
|
+
|
36
|
+
command = command_class.new(@argv)
|
37
|
+
command.run
|
40
38
|
end
|
41
39
|
|
42
40
|
private
|
@@ -46,7 +44,7 @@ module PdfOutlineEditor
|
|
46
44
|
|
47
45
|
@parser = OptionParser.new
|
48
46
|
|
49
|
-
@parser.banner = "Usage: #{File.basename($
|
47
|
+
@parser.banner = "Usage: #{File.basename($PROGRAM_NAME)} <command> <args>"
|
50
48
|
|
51
49
|
@parser.version = VERSION
|
52
50
|
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf_outline_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- healthypackrat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -17,8 +17,8 @@ dependencies:
|
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: '2.0'
|
19
19
|
name: bundler
|
20
|
-
prerelease: false
|
21
20
|
type: :development
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
@@ -29,15 +29,15 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '13.0'
|
33
33
|
name: rake
|
34
|
-
prerelease: false
|
35
34
|
type: :development
|
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: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
@@ -45,8 +45,8 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.0'
|
47
47
|
name: rspec
|
48
|
-
prerelease: false
|
49
48
|
type: :development
|
49
|
+
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
@@ -70,7 +70,7 @@ files:
|
|
70
70
|
- lib/pdf_outline_editor/loader.rb
|
71
71
|
- lib/pdf_outline_editor/runner.rb
|
72
72
|
- lib/pdf_outline_editor/version.rb
|
73
|
-
- vendor/pdfbox/pdfbox-app-2.0.
|
73
|
+
- vendor/pdfbox/pdfbox-app-2.0.19.jar
|
74
74
|
homepage: https://github.com/healthypackrat/pdf_outline_editor
|
75
75
|
licenses:
|
76
76
|
- Apache-2.0
|
@@ -90,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.7.6
|
93
|
+
rubygems_version: 3.0.6
|
95
94
|
signing_key:
|
96
95
|
specification_version: 4
|
97
96
|
summary: Set PDF outlines from a JSON/YAML definition file
|