pdfs2pdf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -4
- data/.rubocop.yml +95 -1
- data/{CHANGELOGS.md → CHANGELOG.md} +9 -0
- data/Gemfile +1 -1
- data/README.md +19 -38
- data/Rakefile +11 -15
- data/bin/pdfs2pdf +7 -4
- data/lib/pdfs2pdf.rb +5 -6
- data/lib/pdfs2pdf/cli.rb +22 -22
- data/lib/pdfs2pdf/configuration.rb +7 -8
- data/lib/pdfs2pdf/pdfs2pdf.rb +20 -25
- data/lib/pdfs2pdf/version.rb +1 -1
- data/pdfs2pdf.gemspec +26 -27
- data/test/lib/pdfs2pdf/test_pdfs2pdf.rb +5 -5
- data/test/test_helper.rb +7 -7
- metadata +3 -4
- data/rubocop-todo.yml +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83ae1e3e9fca1d4df07df80d14b3922da5b49696
|
4
|
+
data.tar.gz: fcae014da249a1a8b3743c3739a50613d4343b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21dcaa0b180e265f60a51facf62bb5df68c9d44f16f6a701770096d8fbc6899ad3ccd9ac102a9b72992df2ce8d5b5e3be78002021b265e993d7df358ddd6a11
|
7
|
+
data.tar.gz: ace3b8d0838f2fb957afc602d29f9bbab518bba0083b692a9b0c6033e37435698892945e08e8a648207534c559584dd3a273460c7e752d9111199134126fda5c
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1 +1,95 @@
|
|
1
|
-
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- Gemfile
|
4
|
+
- Rakefile
|
5
|
+
- bin/*
|
6
|
+
- pdfs2pdf.gemspec
|
7
|
+
- lib/**/*.rb
|
8
|
+
- test/**/*.rb
|
9
|
+
# Avoid long parameter lists
|
10
|
+
ParameterLists:
|
11
|
+
Max: 5
|
12
|
+
CountKeywordArgs: true
|
13
|
+
|
14
|
+
MethodLength:
|
15
|
+
CountComments: false
|
16
|
+
Max: 15
|
17
|
+
|
18
|
+
# Avoid more than `Max` levels of nesting.
|
19
|
+
BlockNesting:
|
20
|
+
Max: 4
|
21
|
+
|
22
|
+
# Align with the style guide.
|
23
|
+
CollectionMethods:
|
24
|
+
PreferredMethods:
|
25
|
+
collect: 'map'
|
26
|
+
inject: 'reduce'
|
27
|
+
find: 'detect'
|
28
|
+
find_all: 'select'
|
29
|
+
|
30
|
+
# Do not force public/protected/private keyword to be indented at the same
|
31
|
+
# level as the def keyword. My personal preference is to outdent these keywords
|
32
|
+
# because I think when scanning code it makes it easier to identify the
|
33
|
+
# sections of code and visually separate them. When the keyword is at the same
|
34
|
+
# level I think it sort of blends in with the def keywords and makes it harder
|
35
|
+
# to scan the code and see where the sections are.
|
36
|
+
AccessModifierIndentation:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
# Limit line length
|
40
|
+
LineLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# Disable documentation checking until a class needs to be documented once
|
44
|
+
Documentation:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Enforce Ruby 1.8-compatible hash syntax
|
48
|
+
HashSyntax:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
# No spaces inside hash literals
|
52
|
+
SpaceInsideHashLiteralBraces:
|
53
|
+
EnforcedStyle: no_space
|
54
|
+
|
55
|
+
# Allow dots at the end of lines
|
56
|
+
DotPosition:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Don't require magic comment at the top of every file
|
60
|
+
Encoding:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
# Enforce outdenting of access modifiers (i.e. public, private, protected)
|
64
|
+
AccessModifierIndentation:
|
65
|
+
EnforcedStyle: outdent
|
66
|
+
|
67
|
+
EmptyLinesAroundAccessModifier:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
# Align ends correctly
|
71
|
+
EndAlignment:
|
72
|
+
AlignWith: variable
|
73
|
+
|
74
|
+
# Indentation of when/else
|
75
|
+
CaseIndentation:
|
76
|
+
IndentWhenRelativeTo: end
|
77
|
+
IndentOneStep: false
|
78
|
+
|
79
|
+
DoubleNegation:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
PercentLiteralDelimiters:
|
83
|
+
PreferredDelimiters:
|
84
|
+
'%': ()
|
85
|
+
'%i': ()
|
86
|
+
'%q': ()
|
87
|
+
'%Q': ()
|
88
|
+
'%r': '{}'
|
89
|
+
'%s': ()
|
90
|
+
'%w': '[]'
|
91
|
+
'%W': '[]'
|
92
|
+
'%x': ()
|
93
|
+
|
94
|
+
StringLiterals:
|
95
|
+
EnforcedStyle: double_quotes
|
@@ -1,11 +1,20 @@
|
|
1
1
|
### Changelogs
|
2
2
|
|
3
|
+
#### 0.1.1
|
4
|
+
|
5
|
+
- Simplify the CLI interface
|
6
|
+
* remove `--base-dir` as it must always be the current directory
|
7
|
+
* remove the intermediate command in the `bin/pdfs2pdf`
|
8
|
+
- Cleanup the style with rubocop
|
9
|
+
- Make `--version` work properly
|
10
|
+
|
3
11
|
#### 0.1.0
|
4
12
|
|
5
13
|
- First [Semantic Versioning][] version
|
6
14
|
- Update gemspec file
|
7
15
|
|
8
16
|
#### 0.0.1 - 0.0.8
|
17
|
+
|
9
18
|
- Releases that do not follow Semantic Versioning
|
10
19
|
- Implement new features and fix a few bugs a long the way
|
11
20
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
##
|
1
|
+
## pdfs2pdf
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/pdfs2pdf.svg)](http://badge.fury.io/rb/pdfs2pdf)
|
4
4
|
[![Dependency Status](https://gemnasium.com/agilecreativity/pdfs2pdf.png)](https://gemnasium.com/agilecreativity/pdfs2pdf)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/agilecreativity/pdfs2pdf.png)](https://codeclimate.com/github/agilecreativity/pdfs2pdf)
|
6
6
|
|
7
|
-
Combine multiple PDF files into
|
8
|
-
|
9
|
-
Note: start from version `0.1.0` this gem will be released using [Semantic Versioning][] convention.
|
7
|
+
Combine multiple PDF files into a single pdf file with simple bookmarks support using [Ghostscript][].
|
10
8
|
|
11
9
|
### What it does?
|
12
10
|
|
13
|
-
Says you have the follow pdf files
|
11
|
+
Says you have the follow pdf files
|
14
12
|
|
15
13
|
```
|
16
14
|
./test/fixtures/samples/demo1_xxx.rb.xhtml.pdf
|
@@ -18,6 +16,7 @@ Says you have the follow pdf files (included inside the test fixtures)
|
|
18
16
|
./test/fixtures/samples/sub_dir/demo3_xxx.rb.xhtml.pdf
|
19
17
|
./test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml.pdf
|
20
18
|
```
|
19
|
+
|
21
20
|
Which have the following content:
|
22
21
|
|
23
22
|
- File: `./test/fixtures/samples/demo1_xxx.rb.xhtml.pdf`
|
@@ -40,23 +39,17 @@ When you run the following command:
|
|
40
39
|
|
41
40
|
```
|
42
41
|
gem install pdfs2pdf
|
43
|
-
|
44
|
-
cd
|
45
|
-
|
46
|
-
rbenv rehash
|
47
|
-
pdfs2pdf merge --base-dir ./test/fixtures/samples
|
42
|
+
# Note: must change to the root of the directory that we want to start from
|
43
|
+
cd ./test/fixtures/samples
|
44
|
+
pdfs2pdf --recursive
|
48
45
|
```
|
49
46
|
|
50
47
|
Will produce the result like the following
|
51
48
|
|
52
|
-
- File: `
|
49
|
+
- File: `pdfs2pdf_output.pdf` (excepted screenshot)
|
53
50
|
|
54
51
|
![](https://github.com/agilecreativity/pdfs2pdf/raw/master/final_output.png)
|
55
52
|
|
56
|
-
- File: `final_output.pdf` (actual pdf)
|
57
|
-
|
58
|
-
![](https://github.com/agilecreativity/pdfs2pdf/raw/master/final_output.pdf)
|
59
|
-
|
60
53
|
### Requirements
|
61
54
|
|
62
55
|
### Mandatory Requirement
|
@@ -69,38 +62,20 @@ installation from source.
|
|
69
62
|
- Alternatively, for Ubuntu you can try `sudo apt-get install ghostscript` and under OSX
|
70
63
|
you can use [Homebrew](https://github.com/Homebrew/homebrew).
|
71
64
|
|
72
|
-
|
65
|
+
### Usage
|
73
66
|
|
74
67
|
```sh
|
75
68
|
gem install pdfs2pdf
|
76
69
|
```
|
77
|
-
For list of usage type
|
78
70
|
|
79
|
-
|
80
|
-
pdfs2pdf help
|
81
|
-
```
|
82
|
-
Which should give the following options
|
83
|
-
|
84
|
-
```
|
85
|
-
Commands:
|
86
|
-
pdfs2pdf help [COMMAND] # Describe available commands or one specific command
|
87
|
-
pdfs2pdf merge # Combine multiple pdfs into one file with bookmarks
|
88
|
-
pdfs2pdf usage # Display usage information
|
89
|
-
```
|
90
|
-
|
91
|
-
Help on `merge` command just type `pdfs2pdf help merge`.
|
92
|
-
|
93
|
-
Which should produce the following guide.
|
71
|
+
### Usage/Synopsis:
|
94
72
|
|
95
73
|
```
|
96
74
|
Usage:
|
97
|
-
pdfs2pdf
|
75
|
+
pdfs2pdf
|
98
76
|
|
99
77
|
Options:
|
100
|
-
-b, [--base-dir=BASE_DIR] # Base directory
|
101
|
-
# Default: . (current directory)
|
102
78
|
-r, [--recursive], [--no-recursive] # Search for files recursively
|
103
|
-
# Default: true
|
104
79
|
-v, [--version], [--no-version] # Display version information
|
105
80
|
|
106
81
|
Combine multiple pdfs into one file with bookmarks
|
@@ -109,13 +84,19 @@ Combine multiple pdfs into one file with bookmarks
|
|
109
84
|
To combine multiple pdfs just try something like
|
110
85
|
|
111
86
|
```
|
112
|
-
|
87
|
+
cd ./test/fixtures/samples
|
88
|
+
pdfs2pdf -r
|
113
89
|
```
|
90
|
+
|
114
91
|
This will merge all the pdf files from `test/fixtures/samples` and generate the
|
115
|
-
`
|
92
|
+
`pdfs2pdf_output.pdf`.
|
116
93
|
|
117
94
|
### Known Issues
|
118
95
|
|
96
|
+
- The combined bookmarks sometime does not produce the correct links to page number.
|
97
|
+
Currently I am not sure what the workaround is. I love to hear from you if
|
98
|
+
know more about the 'pdfmarks' format and how it works with the bookmarks.
|
99
|
+
|
119
100
|
- The directory that contains the pdf files must only contain the
|
120
101
|
letters, numbers and/or underscore characters. Any other characters like
|
121
102
|
`-` (dash) may caused the 'pdfmarks' file to produce incorrect bookmarks.
|
data/Rakefile
CHANGED
@@ -1,30 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
project_name = 'pdfs2pdf'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
project_name = "pdfs2pdf"
|
5
4
|
Rake::TestTask.new do |t|
|
6
5
|
t.libs << "lib/#{project_name}"
|
7
6
|
t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
|
8
7
|
t.verbose = true
|
9
8
|
end
|
10
|
-
|
11
|
-
task default: :test
|
12
|
-
|
9
|
+
task default: [:test, :rubocop]
|
13
10
|
task :pry do
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require_relative
|
11
|
+
require "pry"
|
12
|
+
require "awesome_print"
|
13
|
+
require_relative "./lib/pdfs2pdf"
|
17
14
|
include Pdfs2Pdf
|
18
15
|
ARGV.clear
|
19
16
|
Pry.start
|
20
17
|
end
|
21
|
-
|
22
|
-
|
23
|
-
desc 'Run RuboCop on the lib directory'
|
18
|
+
require "rubocop/rake_task"
|
19
|
+
desc "Run RuboCop on the lib directory"
|
24
20
|
Rubocop::RakeTask.new(:rubocop) do |task|
|
25
|
-
task.patterns = [
|
21
|
+
task.patterns = ["lib/**/*.rb"]
|
26
22
|
# only show the files with failures
|
27
|
-
task.formatters = [
|
23
|
+
task.formatters = ["files"]
|
28
24
|
# don't abort rake on failure
|
29
25
|
task.fail_on_error = false
|
30
26
|
end
|
data/bin/pdfs2pdf
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
Pdfs2Pdf.update_config
|
2
|
+
require_relative "../lib/pdfs2pdf"
|
3
|
+
require_relative "../config/initializers/pdfs2pdf"
|
5
4
|
include Pdfs2Pdf
|
6
|
-
|
5
|
+
if ARGV.empty?
|
6
|
+
Pdfs2Pdf::CLI.start(%w[usage])
|
7
|
+
else
|
8
|
+
Pdfs2Pdf::CLI.start(%w[merge --recursive].concat(ARGV))
|
9
|
+
end
|
data/lib/pdfs2pdf.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative 'pdfs2pdf/pdfs2pdf'
|
1
|
+
require "agile_utils"
|
2
|
+
require "code_lister"
|
3
|
+
require_relative "pdfs2pdf/version"
|
4
|
+
require_relative "pdfs2pdf/cli"
|
5
|
+
require_relative "pdfs2pdf/pdfs2pdf"
|
7
6
|
include AgileUtils::Options
|
8
7
|
include CodeLister
|
9
8
|
include Pdfs2Pdf
|
data/lib/pdfs2pdf/cli.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require_relative
|
6
|
-
require_relative
|
2
|
+
require "thor"
|
3
|
+
require "tmpdir"
|
4
|
+
require "fileutils"
|
5
|
+
require_relative "./pdfs2pdf"
|
6
|
+
require_relative "../pdfs2pdf"
|
7
7
|
module Pdfs2Pdf
|
8
8
|
include AgileUtils::Options
|
9
9
|
include CodeLister
|
10
|
-
|
11
10
|
class CLI < Thor
|
12
|
-
desc
|
13
|
-
method_option *AgileUtils::Options::BASE_DIR
|
11
|
+
desc "merge", "Combine multiple pdfs into one file with bookmarks"
|
12
|
+
# method_option *AgileUtils::Options::BASE_DIR
|
14
13
|
method_option *AgileUtils::Options::RECURSIVE
|
15
14
|
method_option *AgileUtils::Options::VERSION
|
16
15
|
|
17
16
|
def merge
|
18
|
-
|
19
|
-
|
17
|
+
opts = options.symbolize_keys
|
18
|
+
if opts[:version]
|
19
|
+
puts "You are using Pdfs2Pdf version #{Pdfs2Pdf::VERSION}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
base_dir = File.expand_path(Dir.pwd)
|
23
|
+
pdf_files = CodeLister.files base_dir: base_dir,
|
24
|
+
exts: %w[pdf],
|
20
25
|
recursive: true
|
21
|
-
create_pdfmarks(pdf_files,
|
26
|
+
create_pdfmarks(pdf_files, base_dir)
|
22
27
|
merge_pdfs(pdf_files)
|
23
28
|
end
|
24
29
|
|
25
|
-
desc
|
30
|
+
desc "usage", "Display usage information"
|
26
31
|
def usage
|
27
32
|
puts <<-EOT
|
28
33
|
Usage:
|
29
|
-
pdfs2pdf
|
30
|
-
|
34
|
+
pdfs2pdf
|
31
35
|
Options:
|
32
|
-
-b, [--base-dir=BASE_DIR] # Base directory
|
33
|
-
# Default: . (current directory)
|
34
36
|
-r, [--recursive], [--no-recursive] # Search for files recursively
|
35
|
-
# Default: true
|
36
37
|
-v, [--version], [--no-version] # Display version information
|
37
|
-
|
38
38
|
Combine multiple pdfs into one file with bookmarks
|
39
39
|
EOT
|
40
40
|
end
|
41
41
|
|
42
42
|
default_task :usage
|
43
43
|
|
44
|
-
|
44
|
+
private
|
45
45
|
|
46
46
|
def create_pdfmarks(page_list, base_dir)
|
47
47
|
elapsed = AgileUtils::FileUtil.time do
|
48
|
-
Pdfs2Pdf.create_pdfmarks(page_list,
|
48
|
+
Pdfs2Pdf.create_pdfmarks(page_list, "pdfmarks", base_dir)
|
49
49
|
end
|
50
50
|
puts "Create pdfmarks took #{elapsed} ms"
|
51
51
|
end
|
52
52
|
|
53
53
|
def merge_pdfs(pdf_files)
|
54
54
|
elapsed = AgileUtils::FileUtil.time do
|
55
|
-
Pdfs2Pdf.merge_pdfs(pdf_files,
|
55
|
+
Pdfs2Pdf.merge_pdfs(pdf_files, "pdfmarks", "pdfs2pdf_output.pdf")
|
56
56
|
end
|
57
57
|
puts "Combine pdf files took #{elapsed} ms"
|
58
|
-
puts "Your combined pdf is available at #{File.absolute_path(
|
58
|
+
puts "Your combined pdf is available at #{File.absolute_path("pdfs2pdf_output.pdf")}"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module Pdfs2Pdf
|
3
2
|
class Configuration
|
4
3
|
attr_accessor :default_options,
|
@@ -8,17 +7,17 @@ module Pdfs2Pdf
|
|
8
7
|
def initialize
|
9
8
|
# see: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
|
10
9
|
@default_options = {
|
11
|
-
paper_size:
|
10
|
+
paper_size: "A4", # 'Letter'
|
12
11
|
# Note: placeholder values, will be added in the up coming release!
|
13
|
-
margin_top:
|
14
|
-
margin_right:
|
15
|
-
margin_bottom:
|
16
|
-
margin_left:
|
17
|
-
encoding:
|
12
|
+
margin_top: "0.75in",
|
13
|
+
margin_right: "0.75in",
|
14
|
+
margin_bottom: "0.75in",
|
15
|
+
margin_left: "0.75in",
|
16
|
+
encoding: "UTF-8"
|
18
17
|
}
|
19
18
|
|
20
19
|
# see: http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/pdf_creation_apis_and_specs/pdfmarkReference.pdf
|
21
|
-
@pdfmarks_meta = <<-END.gsub(/^\s+\|/,
|
20
|
+
@pdfmarks_meta = <<-END.gsub(/^\s+\|/, "")
|
22
21
|
|[ /Title (My Combined Pdf)
|
23
22
|
| /Author (Burin Choomnuan)
|
24
23
|
| /Keywords (fun, witty, interesting)
|
data/lib/pdfs2pdf/pdfs2pdf.rb
CHANGED
@@ -1,29 +1,23 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
require_relative
|
6
|
-
require_relative './configuration'
|
1
|
+
require "open3"
|
2
|
+
require "fileutils"
|
3
|
+
require "pdf-reader"
|
4
|
+
require_relative "../pdfs2pdf"
|
5
|
+
require_relative "./configuration"
|
7
6
|
module Pdfs2Pdf
|
8
7
|
class << self
|
9
8
|
# Create the 'pdfmarks' file for use with 'gs' utility
|
10
9
|
#
|
11
10
|
# @param [Array<String>] pdf_files the input file list (pdf)
|
12
11
|
# @param [String] output_file the output filename default to 'pdfmarks'
|
13
|
-
# @param [String] base_dir the base directory
|
14
|
-
def create_pdfmarks(pdf_files, pdfmarks_file =
|
15
|
-
|
12
|
+
# @param [String] base_dir the base directory
|
13
|
+
# def create_pdfmarks(pdf_files, pdfmarks_file = "pdfmarks", base_dir = Dir.pwd)
|
14
|
+
def create_pdfmarks(pdf_files, pdfmarks_file = "pdfmarks", base_dir)
|
15
|
+
File.open(pdfmarks_file, "w") do |out_file|
|
16
16
|
out_file.write(Pdfs2Pdf.configuration.pdfmarks_meta)
|
17
17
|
current_page = 1
|
18
18
|
pdf_files.each do |pdf_file|
|
19
|
-
|
20
|
-
|
21
|
-
pdf_file.gsub(base_dir, File.basename(pdf_file))
|
22
|
-
else
|
23
|
-
pdf_file
|
24
|
-
end
|
25
|
-
out_file.write "[ /Page #{current_page} /Title (#{filename}) /OUT pdfmark\n"
|
26
|
-
current_page += page_count(pdf_file)
|
19
|
+
out_file.write "[ /Page #{current_page} /Title (#{pdf_file}) /OUT pdfmark\n"
|
20
|
+
current_page += page_count(base_dir, pdf_file)
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
@@ -33,27 +27,28 @@ module Pdfs2Pdf
|
|
33
27
|
# @param [Array<String>] list input file list
|
34
28
|
# @param [String] pdfmarks the pdfmarks file default to 'pdfmarks'
|
35
29
|
# @param [String] output_file the output pdf file
|
36
|
-
def merge_pdfs(list, pdfmarks =
|
30
|
+
def merge_pdfs(list, pdfmarks = "pdfmarks", output_file = "pdfs2pdf_output.pdf")
|
37
31
|
paper_size = Pdfs2Pdf.configuration.default_options[:paper_size]
|
38
32
|
gs_binary = Pdfs2Pdf.configuration.gs_binary
|
39
33
|
_stdin, _stderr, status = Open3.capture3(
|
40
34
|
gs_binary,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
"-q",
|
36
|
+
"-dNOPAUSE",
|
37
|
+
"-dBATCH",
|
38
|
+
"-sDEVICE=pdfwrite",
|
45
39
|
"-sPAPERSIZE=#{paper_size}",
|
46
40
|
"-sOutputFile=#{output_file}",
|
47
41
|
*list,
|
48
42
|
pdfmarks)
|
49
|
-
fail
|
43
|
+
fail "Problem in merge_pdfs" unless status.success?
|
50
44
|
end
|
51
45
|
|
52
46
|
# Extract pdf page count using pdf-reader
|
53
47
|
#
|
54
48
|
# @return [Fixnum] the page count of the given pdf file
|
55
|
-
def page_count(pdf_file)
|
56
|
-
File.
|
49
|
+
def page_count(base_dir, pdf_file)
|
50
|
+
pdf_file = File.expand_path([base_dir, pdf_file].join("/"))
|
51
|
+
File.open(pdf_file, "rb") do |io|
|
57
52
|
reader = PDF::Reader.new(io)
|
58
53
|
return reader.page_count
|
59
54
|
end
|
data/lib/pdfs2pdf/version.rb
CHANGED
data/pdfs2pdf.gemspec
CHANGED
@@ -1,41 +1,40 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "pdfs2pdf/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = "pdfs2pdf"
|
8
8
|
spec.version = Pdfs2Pdf::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ["Burin Choomnuan"]
|
10
|
+
spec.email = ["agilecreativity@gmail.com"]
|
11
11
|
spec.summary = %q(Combine multiple pdfs into one pdf with proper bookmarks for easy navigation)
|
12
12
|
spec.description = %q(Combine multiple pdfs into a single file with bookmarks for easy navigation)
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
15
|
-
spec.files = Dir.glob(
|
13
|
+
spec.homepage = "https://github.com/agilecreativity/pdfs2pdf"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = Dir.glob("{bin,lib,config}/**/*") + %w[Gemfile
|
16
16
|
Rakefile
|
17
17
|
pdfs2pdf.gemspec
|
18
18
|
README.md
|
19
|
-
|
19
|
+
CHANGELOG.md
|
20
20
|
LICENSE
|
21
21
|
.rubocop.yml
|
22
|
-
.gitignore
|
23
|
-
rubocop-todo.yml)
|
22
|
+
.gitignore]
|
24
23
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
-
spec.test_files = Dir.glob(
|
26
|
-
spec.require_paths = [
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_runtime_dependency
|
29
|
-
spec.add_runtime_dependency
|
30
|
-
spec.add_runtime_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
24
|
+
spec.test_files = Dir.glob("{test}/**/*")
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
spec.add_runtime_dependency "thor"
|
27
|
+
spec.add_runtime_dependency "agile_utils", "~> 0.1"
|
28
|
+
spec.add_runtime_dependency "code_lister", "~> 0.1"
|
29
|
+
spec.add_runtime_dependency "pdf-reader", "~> 1.3.3"
|
30
|
+
spec.add_development_dependency "awesome_print", "~> 1.2"
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
32
|
+
spec.add_development_dependency "gem-ctags", "~> 1.0"
|
33
|
+
spec.add_development_dependency "guard-minitest", "~> 2.2"
|
34
|
+
spec.add_development_dependency "minitest", "~> 5.3"
|
35
|
+
spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
|
36
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
38
|
+
spec.add_development_dependency "rubocop", "~> 0.20"
|
39
|
+
spec.add_development_dependency "yard", "~> 0.8"
|
41
40
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../../test_helper"
|
2
2
|
describe Pdfs2Pdf do
|
3
|
-
context
|
4
|
-
it
|
5
|
-
input_file =
|
6
|
-
result = Pdfs2Pdf.page_count(input_file)
|
3
|
+
context "#page_count" do
|
4
|
+
it "returns result for valid command" do
|
5
|
+
input_file = "demo1_xxx.rb.xhtml.pdf"
|
6
|
+
result = Pdfs2Pdf.page_count("./test/fixtures/samples", input_file)
|
7
7
|
result.must_equal 1
|
8
8
|
end
|
9
9
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require_relative
|
1
|
+
require "minitest"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "minitest/pride"
|
4
|
+
require "minitest-spec-context"
|
5
|
+
require "pry"
|
6
|
+
require "awesome_print"
|
7
|
+
require_relative "../lib/pdfs2pdf"
|
8
8
|
include Pdfs2Pdf
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfs2pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burin Choomnuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -216,7 +216,7 @@ extra_rdoc_files: []
|
|
216
216
|
files:
|
217
217
|
- ".gitignore"
|
218
218
|
- ".rubocop.yml"
|
219
|
-
-
|
219
|
+
- CHANGELOG.md
|
220
220
|
- Gemfile
|
221
221
|
- LICENSE
|
222
222
|
- README.md
|
@@ -229,7 +229,6 @@ files:
|
|
229
229
|
- lib/pdfs2pdf/pdfs2pdf.rb
|
230
230
|
- lib/pdfs2pdf/version.rb
|
231
231
|
- pdfs2pdf.gemspec
|
232
|
-
- rubocop-todo.yml
|
233
232
|
- test/fixtures/samples/demo1_xxx.rb.xhtml.pdf
|
234
233
|
- test/fixtures/samples/demo2_xxx.rb.xhtml.pdf
|
235
234
|
- test/fixtures/samples/sub_dir/demo3_xxx.rb.xhtml.pdf
|
data/rubocop-todo.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2014-05-12 23:54:53 +1000 using RuboCop version 0.21.0.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
# Offense count: 3
|
9
|
-
AmbiguousOperator:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
# Offense count: 7
|
13
|
-
Documentation:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
# Offense count: 7
|
17
|
-
LineLength:
|
18
|
-
Max: 123
|
19
|
-
|
20
|
-
# Offense count: 3
|
21
|
-
# Configuration parameters: CountComments.
|
22
|
-
MethodLength:
|
23
|
-
Max: 15
|
24
|
-
|
25
|
-
# Offense count: 1
|
26
|
-
RegexpLiteral:
|
27
|
-
MaxSlashes: 0
|
28
|
-
|
29
|
-
# Offense count: 1
|
30
|
-
UnusedBlockArgument:
|
31
|
-
Enabled: false
|