kristin 0.3.0 → 0.3.3
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 +4 -4
- data/.travis.yml +13 -0
- data/README.md +4 -0
- data/Rakefile +5 -0
- data/kristin.gemspec +2 -1
- data/lib/kristin.rb +5 -2
- data/lib/kristin/version.rb +1 -1
- data/spec/kristin_spec.rb +47 -45
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8c3c24251891a9302c52f0364dcfd73324fea6b
|
4
|
+
data.tar.gz: 6016b1a2817584e85f73002f8efc8c70e3c367d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cad5f0343a24a8567e31d561bd1c40eed49f4529b3df9a5d9985a64a994f6dbaccfa6f69a0c465669a6f91c60a23c830571d588b7ef8685aa10d4ca9ef6426b
|
7
|
+
data.tar.gz: 2964db20fb2041cc32453b8a539fde6cc516c3787becbcb29315226dce88c7e5e0becf3c03868b6a60450b4eeca8c2f630f747714f576fa18ad9f7fd4c52b37f
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- ruby-head
|
6
|
+
- rbx-19mode
|
7
|
+
notifications:
|
8
|
+
recipients:
|
9
|
+
- ricny046@gmail.com
|
10
|
+
before_install:
|
11
|
+
- sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes
|
12
|
+
- sudo apt-get update -qq
|
13
|
+
- sudo apt-get install pdf2htmlex libxslt-dev libxml2-dev
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Kristin
|
2
2
|
[](https://codeclimate.com/github/ricn/kristin)
|
3
|
+
[](https://travis-ci.org/ricn/kristin)
|
3
4
|
|
4
5
|
Convert PDF docs to beautiful HTML files without losing text or format. This gem uses pdf2htmlEX to do the conversion.
|
5
6
|
|
@@ -41,6 +42,9 @@ Kristin.convert('document.pdf', 'document.html', { first_page: 2, last_page: 4,
|
|
41
42
|
# last_page - last page to convert. Default: 2147483647
|
42
43
|
# hdpi - horizontal resolution for graphics in DPI. Default: 144
|
43
44
|
# vdpi - vertical resolution for graphics in DPI. Default: 144
|
45
|
+
# zoom - zoom ratio. Default: 1.0
|
46
|
+
# fit_width - fit width (pixels). Example: fit_width: 1024
|
47
|
+
# fit_height - fit height (pixels). Example: fit_height: 1024
|
44
48
|
|
45
49
|
```
|
46
50
|
|
data/Rakefile
CHANGED
data/kristin.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "nokogiri"
|
24
|
+
spec.add_development_dependency "rspec"
|
24
25
|
end
|
data/lib/kristin.rb
CHANGED
@@ -31,7 +31,10 @@ module Kristin
|
|
31
31
|
opts.push("--last-page #{@options[:last_page]}") if @options[:last_page]
|
32
32
|
opts.push("--hdpi #{@options[:hdpi]}") if @options[:hdpi]
|
33
33
|
opts.push("--vdpi #{@options[:vdpi]}") if @options[:vdpi]
|
34
|
-
|
34
|
+
opts.push("--zoom #{@options[:zoom]}") if @options[:zoom]
|
35
|
+
opts.push("--fit-width #{@options[:fit_width]}") if @options[:fit_width]
|
36
|
+
opts.push("--fit-height #{@options[:fit_height]}") if @options[:fit_height]
|
37
|
+
|
35
38
|
opts.join(" ")
|
36
39
|
end
|
37
40
|
|
@@ -63,7 +66,7 @@ module Kristin
|
|
63
66
|
def download_file(source)
|
64
67
|
tmp_file = "/tmp/#{random_source_name}.pdf"
|
65
68
|
File.open(tmp_file, "wb") do |saved_file|
|
66
|
-
open(source, 'rb') do |read_file|
|
69
|
+
open(URI.encode(source), 'rb') do |read_file|
|
67
70
|
saved_file.write(read_file.read)
|
68
71
|
end
|
69
72
|
end
|
data/lib/kristin/version.rb
CHANGED
data/spec/kristin_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
2
|
+
require 'webrick'
|
3
|
+
include WEBrick
|
4
|
+
|
3
5
|
describe Kristin do
|
4
6
|
|
5
7
|
before(:all) do
|
@@ -8,6 +10,15 @@ describe Kristin do
|
|
8
10
|
@no_pdf = file_path("image.png")
|
9
11
|
@large_pdf = file_path("large.pdf")
|
10
12
|
@target_path = "tmp/kristin"
|
13
|
+
@target_file = @target_path + "/output.html"
|
14
|
+
@fast_opts = { process_outline: false, vdpi: 1, hdpi: 1, first_page: 1, last_page: 1 }
|
15
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
16
|
+
port = 50510
|
17
|
+
@url = "http://#{Socket.gethostname}:#{port}"
|
18
|
+
@t1 = Thread.new do
|
19
|
+
@server = HTTPServer.new(:Port => port, :DocumentRoot => dir, :AccessLog => [], :Logger => WEBrick::Log::new("/dev/null", 7))
|
20
|
+
@server.start
|
21
|
+
end
|
11
22
|
end
|
12
23
|
|
13
24
|
before(:each) do
|
@@ -18,6 +29,10 @@ describe Kristin do
|
|
18
29
|
FileUtils.rm_rf @target_path
|
19
30
|
end
|
20
31
|
|
32
|
+
after(:all) do
|
33
|
+
@t1.exit
|
34
|
+
end
|
35
|
+
|
21
36
|
describe "#convert" do
|
22
37
|
describe "with no options" do
|
23
38
|
it "should raise error if source file does not exists" do
|
@@ -26,15 +41,13 @@ describe Kristin do
|
|
26
41
|
end
|
27
42
|
|
28
43
|
it "should convert a one page pdf to one html file" do
|
29
|
-
|
30
|
-
|
31
|
-
File.exists?(target).should == true
|
44
|
+
Kristin::Converter.new(@one_page_pdf, @target_file, @fast_opts).convert
|
45
|
+
File.exists?(@target_file).should == true
|
32
46
|
end
|
33
47
|
|
34
48
|
it "should convert a multi page pdf to one html file" do
|
35
|
-
|
36
|
-
|
37
|
-
File.exists?(target).should == true
|
49
|
+
Kristin::Converter.new(@multi_page_pdf, @target_file, @fast_opts).convert
|
50
|
+
File.exists?(@target_file).should == true
|
38
51
|
end
|
39
52
|
|
40
53
|
it "should raise error if pdf is not a real pdf" do
|
@@ -42,45 +55,30 @@ describe Kristin do
|
|
42
55
|
end
|
43
56
|
|
44
57
|
it "should convert a pdf from an URL" do
|
45
|
-
|
46
|
-
|
47
|
-
File.exists?(target).should == true
|
58
|
+
Kristin::Converter.new("#{@url}/one.pdf", @target_file, @fast_opts).convert
|
59
|
+
File.exists?(@target_file).should == true
|
48
60
|
end
|
49
61
|
|
50
62
|
it "should raise an error if URL does not exist" do
|
51
|
-
|
52
|
-
lambda { Kristin::Converter.new("https://www.filepicker.io/api/file/donotexist.pdf", target).convert }.should raise_error(IOError)
|
63
|
+
lambda { Kristin::Converter.new("#{@url}/donotexist.pdf", @target_file).convert }.should raise_error(IOError)
|
53
64
|
end
|
54
65
|
|
55
66
|
it "should raise an error if URL file is not a real pdf" do
|
56
|
-
|
57
|
-
lambda { Kristin::Converter.new("https://www.filepicker.io/api/file/agxKeTfQSWKvMR4CDXMq", target).convert }.should raise_error(IOError)
|
67
|
+
lambda { Kristin::Converter.new("#{@url}/image.png", @target_file).convert }.should raise_error(IOError)
|
58
68
|
end
|
59
69
|
end
|
60
70
|
|
61
71
|
describe "options" do
|
62
|
-
#TODO: Only convert file once for performance
|
63
|
-
|
64
|
-
it "should process outline by default" do
|
65
|
-
target = @target_path + "/large.html"
|
66
|
-
Kristin::Converter.new(@large_pdf, target, { process_outline: false }).convert
|
67
|
-
doc = Nokogiri::HTML(File.open(target))
|
68
|
-
el = doc.css("#pdf-outline").first
|
69
|
-
el.children.should_not be_empty
|
70
|
-
end
|
71
|
-
|
72
72
|
it "should be possible to disable outline" do
|
73
|
-
|
74
|
-
|
75
|
-
doc = Nokogiri::HTML(File.open(target))
|
73
|
+
Kristin::Converter.new(@large_pdf, @target_file, { process_outline: false }).convert
|
74
|
+
doc = Nokogiri::HTML(File.open(@target_file))
|
76
75
|
el = doc.css("#pdf-outline").first
|
77
76
|
el.children.first.text.strip.should be_empty
|
78
77
|
end
|
79
78
|
|
80
79
|
it "should be possible to specify first page" do
|
81
|
-
|
82
|
-
|
83
|
-
doc = Nokogiri::HTML(File.open(target))
|
80
|
+
Kristin::Converter.new(@multi_page_pdf, @target_file, { first_page: 2 }).convert
|
81
|
+
doc = Nokogiri::HTML(File.open(@target_file))
|
84
82
|
# Content only present on page 1
|
85
83
|
content_from_page_1 = doc.search("//span").map(&:content).select {|c| c.include? "Geometric series"}
|
86
84
|
# Content only present on page 2
|
@@ -90,9 +88,8 @@ describe Kristin do
|
|
90
88
|
end
|
91
89
|
|
92
90
|
it "should be possible to specify last page" do
|
93
|
-
|
94
|
-
|
95
|
-
doc = Nokogiri::HTML(File.open(target))
|
91
|
+
Kristin::Converter.new(@multi_page_pdf, @target_file, { last_page: 9 }).convert
|
92
|
+
doc = Nokogiri::HTML(File.open(@target_file))
|
96
93
|
# Content only present on page 1
|
97
94
|
content_from_page_1 = doc.search("//span").map(&:content).select {|c| c.include? "Geometric series"}
|
98
95
|
# Content only present on page 10
|
@@ -102,29 +99,34 @@ describe Kristin do
|
|
102
99
|
end
|
103
100
|
|
104
101
|
it "should be possible to specify hdpi and vdpi" do
|
105
|
-
|
106
|
-
|
107
|
-
doc
|
108
|
-
|
102
|
+
Kristin::Converter.new(@one_page_pdf, @target_file, { hdpi: 0, vdpi: 0 }).convert
|
103
|
+
doc = IO.read(@target_file)
|
104
|
+
doc.should include("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAAAAAAAAAAHqZRakAAAADElEQVQI12M4dugAAASaAkndTfHQAAAAAElFTkSuQmCC")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should be possible to specify zoom ratio" do
|
108
|
+
Kristin::Converter.new(@one_page_pdf, @target_file, { zoom: 2.0 }).convert
|
109
|
+
doc = IO.read(@target_file)
|
110
|
+
doc.should include("2.000000")
|
109
111
|
end
|
110
112
|
|
111
|
-
it "should be possible to specify
|
112
|
-
|
113
|
+
it "should be possible to specify fit_width and fit_height" do
|
114
|
+
Kristin::Converter.new(@one_page_pdf, @target_file, { fit_width: 1024, fit_height: 1024 }).convert
|
115
|
+
doc = IO.read(@target_file)
|
116
|
+
doc.should include("1.292929")
|
113
117
|
end
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
117
121
|
describe ".convert" do
|
118
122
|
it "should convert without options" do
|
119
|
-
|
120
|
-
|
121
|
-
File.exists?(target).should == true
|
123
|
+
Kristin.convert(@one_page_pdf, @target_file)
|
124
|
+
File.exists?(@target_file).should == true
|
122
125
|
end
|
123
126
|
|
124
127
|
it "should convert with options" do
|
125
|
-
|
126
|
-
|
127
|
-
File.exists?(target).should == true
|
128
|
+
Kristin.convert(@one_page_pdf, @target_file, { hdpi: 1, vdpi: 1 })
|
129
|
+
File.exists?(@target_file).should == true
|
128
130
|
end
|
129
131
|
end
|
130
132
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kristin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Nyström
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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'
|
55
69
|
description: ' Convert PDF docs to beautiful HTML files without losing text or format.
|
56
70
|
This gem uses pdf2htmlEX to do the conversion.'
|
57
71
|
email:
|
@@ -62,6 +76,7 @@ extra_rdoc_files: []
|
|
62
76
|
files:
|
63
77
|
- .gitignore
|
64
78
|
- .rspec
|
79
|
+
- .travis.yml
|
65
80
|
- Gemfile
|
66
81
|
- LICENSE.txt
|
67
82
|
- README.md
|