img_to_pdf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/img_to_pdf +5 -0
- data/img_to_pdf.gemspec +35 -0
- data/lib/img_to_pdf.rb +15 -0
- data/lib/img_to_pdf/cli.rb +25 -0
- data/lib/img_to_pdf/cli_option.rb +68 -0
- data/lib/img_to_pdf/dimension.rb +40 -0
- data/lib/img_to_pdf/error.rb +2 -0
- data/lib/img_to_pdf/fit_page_document.rb +92 -0
- data/lib/img_to_pdf/image.rb +52 -0
- data/lib/img_to_pdf/integer_parser.rb +12 -0
- data/lib/img_to_pdf/margin.rb +5 -0
- data/lib/img_to_pdf/paper_size_parser.rb +28 -0
- data/lib/img_to_pdf/parser_error.rb +4 -0
- data/lib/img_to_pdf/unit.rb +17 -0
- data/lib/img_to_pdf/version.rb +3 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5dde70fccbb8aca8711e4ba1b6542fd1e1b7e6a9a95d86366adba0c10edb00e1
|
4
|
+
data.tar.gz: c84bba32cd8bb79d6656853045ff3a5f2654b57072c656ad545a3e62e5f26117
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d24a1be432c7f643ba5b6253deb239cd81e8fc94a77d458e312a46834a1b11b3e2e2f92add210b7aab90862be63cb8ada194b9ca5c05bac1422eec3f6eac1533
|
7
|
+
data.tar.gz: 4d9213f55e4417485266ade0c7deabd5053dcf9bda9f0e39094a8004635ed5dfacbaffaafc523cecfe667e527601d5f70376394ed48365165bdfe47504c2f43c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2020 Yuya.Nishida.
|
2
|
+
|
3
|
+
X11 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.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# img_to_pdf
|
2
|
+
|
3
|
+
A tool to create PDF from raster image.
|
4
|
+
|
5
|
+
[![License X11](https://img.shields.io/badge/license-X11-brightgreen.svg)](https://raw.githubusercontent.com/nishidayuya/img_to_pdf/master/LICENSE.txt)
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
* Ruby
|
10
|
+
* ImageMagick
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
```sh
|
15
|
+
$ gem install img_to_pdf
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Create PDF from PNG:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
$ img_to_pdf input.png output.pdf
|
24
|
+
```
|
25
|
+
|
26
|
+
Same as:
|
27
|
+
|
28
|
+
```sh
|
29
|
+
$ img_to_pdf \
|
30
|
+
--paper-size=a4-landscape \
|
31
|
+
--horizontal-pages=1 \
|
32
|
+
--vertical-pages=1 \
|
33
|
+
input.png output.pdf
|
34
|
+
```
|
35
|
+
|
36
|
+
Create 3x4 pages B5 portrait PDF from JPG:
|
37
|
+
|
38
|
+
```
|
39
|
+
$ img_to_pdf \
|
40
|
+
--paper-size=b5-portrait \
|
41
|
+
--horizontal-pages=3 \
|
42
|
+
--vertical-pages=4 \
|
43
|
+
input.jpg output.pdf
|
44
|
+
```
|
45
|
+
|
46
|
+
Show help message:
|
47
|
+
|
48
|
+
```
|
49
|
+
$ img_to_pdf --help
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nishidayuya/img_to_pdf .
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "img_to_pdf"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/img_to_pdf
ADDED
data/img_to_pdf.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require_relative 'lib/img_to_pdf/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "img_to_pdf"
|
7
|
+
spec.version = ImgToPdf::VERSION
|
8
|
+
spec.authors = ["Yuya.Nishida."]
|
9
|
+
spec.email = ["yuya@j96.org"]
|
10
|
+
|
11
|
+
spec.summary = (Pathname(__dir__) / "README.md").each_line(chomp: true).
|
12
|
+
lazy.grep_v(/\A\s*\z|\A\#/).first
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/nishidayuya/" + spec.name
|
15
|
+
spec.license = "X11"
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "prawn"
|
31
|
+
spec.add_runtime_dependency "mini_magick"
|
32
|
+
|
33
|
+
spec.add_development_dependency "rake"
|
34
|
+
spec.add_development_dependency "test-unit"
|
35
|
+
end
|
data/lib/img_to_pdf.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module ImgToPdf
|
4
|
+
autoload(:VERSION, "img_to_pdf/version")
|
5
|
+
|
6
|
+
# set autoload
|
7
|
+
lib_path = Pathname(__dir__)
|
8
|
+
Pathname.glob(lib_path / "img_to_pdf/*.rb").sort.each do |path|
|
9
|
+
no_ext_path = path.relative_path_from(lib_path).sub_ext("")
|
10
|
+
class_name = no_ext_path.basename.to_s.
|
11
|
+
split("_").map(&:capitalize).join.to_sym
|
12
|
+
next if class_name == :Version
|
13
|
+
autoload(class_name, no_ext_path.to_s)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
|
3
|
+
require "img_to_pdf"
|
4
|
+
|
5
|
+
module ImgToPdf::Cli
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def run(argv)
|
9
|
+
option = ImgToPdf::CliOption.from_argv(argv)
|
10
|
+
page_dimension_pt = ImgToPdf::PaperSizeParser.(option.paper_size_text)
|
11
|
+
input_image = ImgToPdf::Image.from_path(option.input_path)
|
12
|
+
document = ImgToPdf::FitPageDocument.create(
|
13
|
+
page_dimension_pt: page_dimension_pt,
|
14
|
+
margin_pt: option.margin_pt,
|
15
|
+
n_horizontal_pages: option.n_horizontal_pages,
|
16
|
+
n_vertical_pages: option.n_vertical_pages,
|
17
|
+
image: input_image,
|
18
|
+
)
|
19
|
+
document.render_file(option.output_path)
|
20
|
+
rescue ImgToPdf::Error => e
|
21
|
+
raise if option.debug
|
22
|
+
STDERR.puts("#{e.class.name}: #{e.message}")
|
23
|
+
exit(1)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
require "img_to_pdf"
|
4
|
+
|
5
|
+
class ImgToPdf::CliOption < Struct.new(:input_path, :output_path, :debug,
|
6
|
+
:paper_size_text, :margin_pt,
|
7
|
+
:n_horizontal_pages, :n_vertical_pages,
|
8
|
+
keyword_init: true)
|
9
|
+
BANNER = <<EOS.chomp
|
10
|
+
Usage: #{File.basename(Process.argv0)} [options] input_image_path output_pdf_path
|
11
|
+
EOS
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def default
|
15
|
+
default_margin_pt = ImgToPdf::Unit.convert_mm_to_pt(10)
|
16
|
+
return new(
|
17
|
+
input_path: nil,
|
18
|
+
output_path: nil,
|
19
|
+
debug: false,
|
20
|
+
paper_size_text: "a4-landscape",
|
21
|
+
margin_pt: ImgToPdf::Margin.new(
|
22
|
+
left: default_margin_pt,
|
23
|
+
right: default_margin_pt,
|
24
|
+
top: default_margin_pt,
|
25
|
+
bottom: default_margin_pt,
|
26
|
+
),
|
27
|
+
n_horizontal_pages: 1,
|
28
|
+
n_vertical_pages: 1,
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def from_argv(argv, stdout: STDOUT)
|
33
|
+
result = default
|
34
|
+
|
35
|
+
parser = OptionParser.new
|
36
|
+
parser.version = ImgToPdf::VERSION
|
37
|
+
parser.banner = BANNER
|
38
|
+
parser.summary_indent = ""
|
39
|
+
parser.separator("")
|
40
|
+
parser.separator("Options:")
|
41
|
+
parser.on("--paper-size=SIZE",
|
42
|
+
"specify paper size. 'a4-landscape'(default), 'b3-portrait', etc.") do |v|
|
43
|
+
result.paper_size_text = v
|
44
|
+
end
|
45
|
+
parser.on("--horizontal-pages=INTEGER",
|
46
|
+
"specify number of horizontal pages. default 1.") do |v|
|
47
|
+
result.n_horizontal_pages = ImgToPdf::IntegerParser.(v)
|
48
|
+
end
|
49
|
+
parser.on("--vertical-pages=INTEGER",
|
50
|
+
"specify number of vertical pages. default 1.") do |v|
|
51
|
+
result.n_vertical_pages = ImgToPdf::IntegerParser.(v)
|
52
|
+
end
|
53
|
+
parser.on("--debug") do
|
54
|
+
result.debug = true
|
55
|
+
end
|
56
|
+
|
57
|
+
input_path, output_path = *parser.parse(argv)
|
58
|
+
if !output_path
|
59
|
+
stdout.puts(parser.help)
|
60
|
+
exit(1)
|
61
|
+
end
|
62
|
+
result.input_path = Pathname(input_path).expand_path
|
63
|
+
result.output_path = Pathname(output_path).expand_path
|
64
|
+
|
65
|
+
return result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "img_to_pdf"
|
2
|
+
|
3
|
+
class ImgToPdf::Dimension < Struct.new(:width, :height, keyword_init: true)
|
4
|
+
class << self
|
5
|
+
# @param [Array<(Float, Float)>] ary `[width, height]`.
|
6
|
+
# @return ImgToPdf::Dimension parsed.
|
7
|
+
def from_array(ary)
|
8
|
+
return new(width: ary[0], height: ary[1])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array<(Float, Float)>] array. `[width, height]`.
|
13
|
+
def to_a
|
14
|
+
return [width, height]
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [:landscape, :portrait] direction of dimension.
|
18
|
+
def direction
|
19
|
+
return width > height ? :landscape : :portrait
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [ImgToPdf::Dimension] transposed dimension.
|
23
|
+
def transpose
|
24
|
+
return self.class.new(width: height, height: width)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [:landscape, :portrait] direction
|
28
|
+
# @return [ImgToPdf::Dimension] justified dimension.
|
29
|
+
def justify_direction(target_direction)
|
30
|
+
return direction == target_direction ? dup : transpose
|
31
|
+
end
|
32
|
+
|
33
|
+
# points to inches.
|
34
|
+
#
|
35
|
+
# @return [ImgToPdf::Dimension] inch dimension.
|
36
|
+
def pt_to_in
|
37
|
+
return self.class.new(width: ImgToPdf::Unit.convert_pt_to_in(width),
|
38
|
+
height: ImgToPdf::Unit.convert_pt_to_in(height))
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "prawn"
|
2
|
+
|
3
|
+
require "img_to_pdf"
|
4
|
+
|
5
|
+
class ImgToPdf::FitPageDocument
|
6
|
+
# @param [ImgToPdf::Dimension] page_dimension_pt page size. points.
|
7
|
+
# @param [ImgToPdf::Margin] margin_pt margin size. points.
|
8
|
+
# @param [ImgToPdf::Image] image source image.
|
9
|
+
# @param [Integer] n_horizontal_pages number of horizontal pages.
|
10
|
+
# @param [Integer] n_vertical_pages number of vertical pages.
|
11
|
+
# @return [ImgToPdf::FitPageDocument] document to render PDF.
|
12
|
+
def self.create(page_dimension_pt:, margin_pt:, image:,
|
13
|
+
n_horizontal_pages: 1, n_vertical_pages: 1)
|
14
|
+
result = new(page_dimension_pt: page_dimension_pt, margin_pt: margin_pt,
|
15
|
+
n_horizontal_pages: n_horizontal_pages,
|
16
|
+
n_vertical_pages: n_vertical_pages,
|
17
|
+
image: image)
|
18
|
+
result.draw
|
19
|
+
return result
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(page_dimension_pt:, margin_pt:, image:,
|
23
|
+
n_horizontal_pages:, n_vertical_pages:)
|
24
|
+
@page_dimension_pt = page_dimension_pt
|
25
|
+
@margin_pt = margin_pt
|
26
|
+
@image = image
|
27
|
+
@n_horizontal_pages = n_horizontal_pages
|
28
|
+
@n_vertical_pages = n_vertical_pages
|
29
|
+
|
30
|
+
@pdf = Prawn::Document.new(
|
31
|
+
page_size: @page_dimension_pt.to_a,
|
32
|
+
margin: @margin_pt.to_a,
|
33
|
+
skip_page_creation: true,
|
34
|
+
info: {
|
35
|
+
Creator: "img_to_pdf version #{ImgToPdf::VERSION}",
|
36
|
+
},
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw
|
41
|
+
canvas_dimension_pt = determine_canvas_dimension_pt
|
42
|
+
canvas_scale = determine_canvas_scale(canvas_dimension_pt)
|
43
|
+
sub_image_dimension_px = ImgToPdf::Dimension.new(
|
44
|
+
width: @image.dimension_px.width / @n_horizontal_pages,
|
45
|
+
height: @image.dimension_px.height / @n_vertical_pages,
|
46
|
+
)
|
47
|
+
each_sub_image(sub_image_dimension_px) do |sub_image|
|
48
|
+
@pdf.start_new_page
|
49
|
+
@pdf.image(
|
50
|
+
sub_image.path,
|
51
|
+
scale: canvas_scale,
|
52
|
+
at: [0, canvas_dimension_pt.height / @n_vertical_pages],
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [Pathname] output_path path to PDF output.
|
58
|
+
def render_file(output_path)
|
59
|
+
@pdf.render_file(output_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def determine_canvas_dimension_pt
|
65
|
+
w = (@page_dimension_pt.width - @margin_pt.left - @margin_pt.right) *
|
66
|
+
@n_horizontal_pages
|
67
|
+
h = (@page_dimension_pt.height - @margin_pt.top - @margin_pt.bottom) *
|
68
|
+
@n_vertical_pages
|
69
|
+
return ImgToPdf::Dimension.new(width: w, height: h)
|
70
|
+
end
|
71
|
+
|
72
|
+
def determine_canvas_scale(canvas_dimension_pt)
|
73
|
+
canvas_dimension_in = canvas_dimension_pt.pt_to_in
|
74
|
+
dpi_from_width = @image.dimension_px.width / canvas_dimension_in.width
|
75
|
+
dpi_from_height = @image.dimension_px.height / canvas_dimension_in.height
|
76
|
+
canvas_dpi = [dpi_from_width, dpi_from_height].max
|
77
|
+
return 72 / canvas_dpi
|
78
|
+
end
|
79
|
+
|
80
|
+
def each_sub_image(sub_image_dimension_px)
|
81
|
+
@n_vertical_pages.times do |i_y|
|
82
|
+
@n_horizontal_pages.times do |i_x|
|
83
|
+
@image.crop(sub_image_dimension_px.width * i_x,
|
84
|
+
sub_image_dimension_px.height * i_y,
|
85
|
+
sub_image_dimension_px.width,
|
86
|
+
sub_image_dimension_px.height) do |sub_image|
|
87
|
+
yield(sub_image)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
3
|
+
require "mini_magick"
|
4
|
+
require "prawn"
|
5
|
+
|
6
|
+
require "img_to_pdf"
|
7
|
+
|
8
|
+
class ImgToPdf::Image
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# @param [Pathname] path path to instantiate.
|
13
|
+
# @return [ImgToPdf::Image] instance.
|
14
|
+
def from_path(path)
|
15
|
+
return new(path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(path)
|
20
|
+
@dimension_px = nil
|
21
|
+
@path = path
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [ImgToPdf::Dimension] image dimension. pixels.
|
25
|
+
def dimension_px
|
26
|
+
return @dimension_px if @dimension_px
|
27
|
+
image_klass = Prawn::Images.const_get(path.extname.upcase.sub(/\A\./, ""))
|
28
|
+
image = image_klass.new(path.read)
|
29
|
+
@dimension_px = ImgToPdf::Dimension.new(width: image.width,
|
30
|
+
height: image.height)
|
31
|
+
return @dimension_px
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Numeric] x
|
35
|
+
# @param [Numeric] y
|
36
|
+
# @param [Numeric] width
|
37
|
+
# @param [Numeric] height
|
38
|
+
# @yieldparam [ImgToPdf::Image] sub_image cropped sub image.
|
39
|
+
def crop(x, y, width, height)
|
40
|
+
Tempfile.create(["img_to_pdf-image-", path.extname]) do |f|
|
41
|
+
f.close
|
42
|
+
sub_raw_image_path = Pathname(f.path)
|
43
|
+
|
44
|
+
raw_image = MiniMagick::Image.open(path)
|
45
|
+
raw_image.crop("#{width}x#{height}+#{x}+#{y}")
|
46
|
+
raw_image.write(sub_raw_image_path)
|
47
|
+
|
48
|
+
sub_image = self.class.from_path(sub_raw_image_path)
|
49
|
+
yield(sub_image)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "pdf/core/page_geometry"
|
2
|
+
|
3
|
+
require "img_to_pdf"
|
4
|
+
|
5
|
+
module ImgToPdf::PaperSizeParser
|
6
|
+
extend self
|
7
|
+
|
8
|
+
AVAILABLE_DIRECTIONS = %i[landscape portrait]
|
9
|
+
|
10
|
+
# @param [String] s paper size text. "a4-landscape", "b3-portrait", etc.
|
11
|
+
# @return [ImgToPdf::Dimension] parsed paper dimension. points.
|
12
|
+
def call(s)
|
13
|
+
paper_size, direction = *s.split("-")
|
14
|
+
direction = direction.downcase.to_sym
|
15
|
+
if !AVAILABLE_DIRECTIONS.include?(direction)
|
16
|
+
raise ImgToPdf::ParserError, "invalid paper direction: #{s.inspect}"
|
17
|
+
end
|
18
|
+
raw_size_pt = PDF::Core::PageGeometry::SIZES[paper_size.upcase]
|
19
|
+
if !raw_size_pt
|
20
|
+
raise ImgToPdf::ParserError, "invalid paper size: #{s.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
paper_dimension_pt = ImgToPdf::Dimension.from_array(raw_size_pt)
|
24
|
+
paper_dimension_pt = paper_dimension_pt.justify_direction(direction)
|
25
|
+
|
26
|
+
return paper_dimension_pt
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "img_to_pdf"
|
2
|
+
|
3
|
+
module ImgToPdf::Unit
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# @param [Float] mm source length. millimeters.
|
7
|
+
# @return [Float] destination length. points.
|
8
|
+
def convert_mm_to_pt(mm)
|
9
|
+
return mm / 25.4 * 72
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [Float] pt source length. points.
|
13
|
+
# @return [Float] destination length. inches.
|
14
|
+
def convert_pt_to_in(pt)
|
15
|
+
return pt / 72
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: img_to_pdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuya.Nishida.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: prawn
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mini_magick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A tool to create PDF from raster image.
|
70
|
+
email:
|
71
|
+
- yuya@j96.org
|
72
|
+
executables:
|
73
|
+
- img_to_pdf
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- exe/img_to_pdf
|
85
|
+
- img_to_pdf.gemspec
|
86
|
+
- lib/img_to_pdf.rb
|
87
|
+
- lib/img_to_pdf/cli.rb
|
88
|
+
- lib/img_to_pdf/cli_option.rb
|
89
|
+
- lib/img_to_pdf/dimension.rb
|
90
|
+
- lib/img_to_pdf/error.rb
|
91
|
+
- lib/img_to_pdf/fit_page_document.rb
|
92
|
+
- lib/img_to_pdf/image.rb
|
93
|
+
- lib/img_to_pdf/integer_parser.rb
|
94
|
+
- lib/img_to_pdf/margin.rb
|
95
|
+
- lib/img_to_pdf/paper_size_parser.rb
|
96
|
+
- lib/img_to_pdf/parser_error.rb
|
97
|
+
- lib/img_to_pdf/unit.rb
|
98
|
+
- lib/img_to_pdf/version.rb
|
99
|
+
homepage: https://github.com/nishidayuya/img_to_pdf
|
100
|
+
licenses:
|
101
|
+
- X11
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/nishidayuya/img_to_pdf
|
104
|
+
source_code_uri: https://github.com/nishidayuya/img_to_pdf
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 2.3.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.0.3
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: A tool to create PDF from raster image.
|
124
|
+
test_files: []
|