pdf_outline_editor 0.1.0-java → 0.2.1-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4919cc4df58a6af4c74185a140a8845176b9afef34bed77558171361fbb299e
4
- data.tar.gz: 3dd0368ac59022b051083b41b48dc48a21944e1d224d570574651d95298697a5
3
+ metadata.gz: db0e27ede890c9f281ca74ca4d832b3b6e7f40c6c0fbf6a328695efc6f8604ed
4
+ data.tar.gz: d022eae7b5f029b68e872387808a3939697374532b68c8adcef7e29fbee4c1b7
5
5
  SHA512:
6
- metadata.gz: 9e523afaa754c0b56534e34dd65688416d6e6b109770890f8bc19b0a7fff8ae586c828e9fe35a2245ea0164582ccb7e96d590a2afe3d8b260158cc27bfd5ad5e
7
- data.tar.gz: 77fbe6d6d9d8afaf5bd4eb78aa987a857ef1690e99e6a72379eb487820526aa5e47779a25f30f3f3cd09ca63a3c1697517f0330e9053a79cd0505b0a3a445b84
6
+ metadata.gz: bc3d9da6964efdeb79b574d0a557d4de66907ea0107a48d7e0391452385ba36291bc0ace1bcd3043299e18a9fb7df841a7c63fbe93f9681d318252b2fb84eb1a
7
+ data.tar.gz: d6f3f2bf0c82ecee7a6b8b7f8447de2cafbdf05f155c5bb0e1280cc67888654b3caf9874febdc4aa076f7c9de7e487c70dd54163276a8db52d7d9d203a475e7e
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # `pdf_outline_editor`
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
 
5
5
  This gem provides a command to get/set PDF outlines from a JSON/YAML definition file.
6
6
 
7
+ Useful for [PDF files which don't have outlines](https://github.com/healthypackrat/pdf-outlines).
8
+
7
9
  ## Requirements
8
10
 
9
11
  - JRuby
@@ -16,7 +18,7 @@ $ jgem install pdf_outline_editor
16
18
 
17
19
  ## Usage
18
20
 
19
- First, generate outlines definition file by running `init` command:
21
+ First, generate an outlines definition file by running `init` command:
20
22
 
21
23
  ```
22
24
  $ pdf_outline_editor init -f json > toc.json
@@ -38,9 +40,9 @@ $ pdf_outline_editor load input.pdf toc.json output.pdf
38
40
 
39
41
  ## Development
40
42
 
41
- Run `bin/jruby-ng-server` in a new terminal window for faster loading.
43
+ Run `bin/rspec` to run the specs.
42
44
 
43
- Then run `bin/rspec` to run the specs.
45
+ Run `bin/rubocop` to check formattings.
44
46
 
45
47
  ## Contributing
46
48
 
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env jruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "pdf_outline_editor"
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 => error
9
- warn error.message
9
+ rescue PdfOutlineEditor::Error => e
10
+ warn e.message
10
11
  exit 1
11
12
  end
@@ -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 = [:json, :yaml]
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($0)} dump [options] <input-pdf-path>"
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 = [:json, :yaml]
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($0)} init [options]"
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($0)} load <input-pdf-path> <input-outlines-path> <output-pdf-path>"
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
- if respond_to?(method_name, true)
55
- send(method_name, path)
56
- else
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, $!.message
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
- if root_outline
35
- traverse(root_outline)
36
- else
37
- nil
38
- end
37
+ return unless root_outline
38
+
39
+ traverse(root_outline)
39
40
  end
40
41
 
41
42
  def close
42
- unless @closed
43
- @doc.close
44
- @closed = true
45
- end
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,17 +25,19 @@ 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, $!.message
28
+ rescue IOException => e
29
+ raise Error, e.message
27
30
  end
28
31
 
32
+ @doc.set_all_security_to_be_removed(true)
33
+
29
34
  @pages = @doc.pages.to_a
30
35
 
31
36
  @closed = false
32
37
  end
33
38
 
34
39
  def load(entries)
35
- root_outline = PDDocumentOutline.new
40
+ root_outline = PDDocumentOutline.new
36
41
 
37
42
  @doc.document_catalog.document_outline = root_outline
38
43
 
@@ -46,10 +51,10 @@ module PdfOutlineEditor
46
51
  end
47
52
 
48
53
  def close
49
- unless @closed
50
- @doc.close
51
- @closed = true
52
- end
54
+ return if @closed
55
+
56
+ @doc.close
57
+ @closed = true
53
58
  end
54
59
 
55
60
  private
@@ -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
- _known_commands = {}
8
+ known_commands = {}
7
9
 
8
10
  define_method :known_commands do
9
- _known_commands
11
+ known_commands
10
12
  end
11
13
 
12
14
  define_method :register_command do |key, klass|
13
- _known_commands[key] = klass
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
- if command_class
35
- command = command_class.new(@argv)
36
- command.run
37
- else
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($0)} <command> <args>"
47
+ @parser.banner = "Usage: #{File.basename($PROGRAM_NAME)} <command> <args>"
50
48
 
51
49
  @parser.version = VERSION
52
50
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PdfOutlineEditor
2
- VERSION = "0.1.0"
4
+ VERSION = '0.2.1'
3
5
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'java'
2
4
 
3
- require_relative '../vendor/pdfbox/pdfbox-app-2.0.13.jar'
5
+ require_relative '../vendor/pdfbox/pdfbox-app-2.0.25.jar'
4
6
 
5
7
  require 'pdf_outline_editor/version'
6
8
 
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.0
4
+ version: 0.2.1
5
5
  platform: java
6
6
  authors:
7
7
  - healthypackrat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-31 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '10.0'
32
+ version: '13.0'
33
33
  name: rake
34
34
  prerelease: false
35
35
  type: :development
@@ -37,7 +37,7 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
@@ -70,11 +70,12 @@ 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.13.jar
73
+ - vendor/pdfbox/pdfbox-app-2.0.25.jar
74
74
  homepage: https://github.com/healthypackrat/pdf_outline_editor
75
75
  licenses:
76
76
  - Apache-2.0
77
- metadata: {}
77
+ metadata:
78
+ rubygems_mfa_required: 'true'
78
79
  post_install_message:
79
80
  rdoc_options: []
80
81
  require_paths:
@@ -90,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.7.6
94
+ rubygems_version: 3.2.29
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Set PDF outlines from a JSON/YAML definition file