rtftopdf 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +7 -0
- data/lib/rtftopdf/version.rb +3 -0
- data/lib/rtftopdf.rb +29 -0
- data/rtftopdf.gemspec +24 -0
- data/test/lib/rtftopdf_test.rb +42 -0
- data/test/test_helper.rb +5 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15b77852e3975a2469258cc12956c184a09811d8
|
4
|
+
data.tar.gz: 8166fc6770f04f1d485c4d929d0914367a13170c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5244e2ad896532540bcc5d4dcee625830231a8e7a0f8b285e88bb9eda2b837515070e03bb9f639bef2c83e009c4db5b2e6352c67d82d5701c2d5092e9d4e4c45
|
7
|
+
data.tar.gz: 6584e219ed644119ce6c0e5b60b64e1fa4f388a3e0f1e84b7eacb04ada415d7215c9e40e8ee1a60cfe4837ac2d568ffe8cb0622e67d1589811c40884f75e3a90
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Caleb Cauthon
|
2
|
+
|
3
|
+
MIT 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,33 @@
|
|
1
|
+
# Rtftopdf
|
2
|
+
|
3
|
+
Converts rtf strings to pdf output using unrtf and wkhtmltopdf.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
brew install unrtf
|
9
|
+
brew install wkhtmltopdf
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'rtftopdf'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rtftopdf
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
RTFtoPDF.to_pdf("some rtf input")
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rtftopdf.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rtftopdf/version"
|
2
|
+
require 'tempfile'
|
3
|
+
require 'pdfkit'
|
4
|
+
|
5
|
+
class RTF
|
6
|
+
def initialize rtf_content
|
7
|
+
@rtf_content = rtf_content
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_html
|
11
|
+
temporary_rtf_file = Tempfile.new('RTF')
|
12
|
+
temporary_rtf_file.write(@rtf_content)
|
13
|
+
temporary_rtf_file.close
|
14
|
+
|
15
|
+
html_content = `unrtf #{temporary_rtf_file.path}`
|
16
|
+
temporary_rtf_file.unlink
|
17
|
+
|
18
|
+
html_content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class RTFtoPDF
|
23
|
+
def self.to_pdf rtf_content
|
24
|
+
html_content = RTF.new(rtf_content).to_html
|
25
|
+
pdf_content = PDFKit.new(html_content).to_pdf
|
26
|
+
|
27
|
+
pdf_content
|
28
|
+
end
|
29
|
+
end
|
data/rtftopdf.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rtftopdf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rtftopdf"
|
8
|
+
spec.version = Rtftopdf::VERSION
|
9
|
+
spec.authors = ["Caleb Cauthon"]
|
10
|
+
spec.email = ["calebcauthon@gmail.com"]
|
11
|
+
spec.description = %q{RTF to PDF conversion}
|
12
|
+
spec.summary = %q{Converts rtf strings to pdf output using unrtf and wkhtmltopdf.}
|
13
|
+
spec.homepage = "http://github.com/calebcauthon/rtftopdf"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest", "~> 4.7.3"
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mocha/setup'
|
3
|
+
|
4
|
+
describe "rtf to pdf conversion" do
|
5
|
+
describe "rtf to html conversion" do
|
6
|
+
it "must turn rtf input into html" do
|
7
|
+
rtf_input = '{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 Times New Roman;}{\f2\fnil Times New Roman;}{\f3\fswiss\fprq2\fcharset0 Arial;}}\viewkind4\uc1\pard\nowidctlpar\qr\b\f0\fs18 LOREM ISPO FACTO\par\pard\nowidctlpar\qc\f1\fs28 LOREM IPSEUM AGREEMENT\f0\fs18 \par}'
|
8
|
+
temporary_rtf_file = Tempfile.new('RTF')
|
9
|
+
temporary_rtf_file.write(rtf_input)
|
10
|
+
temporary_rtf_file.close
|
11
|
+
|
12
|
+
html_content = `unrtf #{temporary_rtf_file.path}`
|
13
|
+
temporary_rtf_file.unlink
|
14
|
+
|
15
|
+
mock_pdfkit = mock() do
|
16
|
+
expects(:to_pdf)
|
17
|
+
end
|
18
|
+
|
19
|
+
PDFKit.expects(:new).with(html_content).returns(mock_pdfkit)
|
20
|
+
RTFtoPDF.to_pdf(rtf_input)
|
21
|
+
end
|
22
|
+
it "must delete the temporary file when its finished" do
|
23
|
+
Tempfile.any_instance.expects(:unlink)
|
24
|
+
RTFtoPDF.to_pdf("asdf")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
it "must pass on the html result to pdf kit" do
|
28
|
+
mock_pdfkit = mock() do
|
29
|
+
expects(:to_pdf)
|
30
|
+
end
|
31
|
+
|
32
|
+
RTF.any_instance.stubs(:to_html).returns("my html content!")
|
33
|
+
|
34
|
+
PDFKit.expects(:new).with("my html content!").returns(mock_pdfkit)
|
35
|
+
RTFtoPDF.to_pdf("bla bla /so-=1 RTF content")
|
36
|
+
end
|
37
|
+
it "must return the pdf result from pdfkit" do
|
38
|
+
PDFKit.any_instance.stubs(:to_pdf).returns("my pdf!")
|
39
|
+
|
40
|
+
RTFtoPDF.to_pdf("00001").must_equal "my pdf!"
|
41
|
+
end
|
42
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtftopdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Cauthon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.7.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.7.3
|
55
|
+
description: RTF to PDF conversion
|
56
|
+
email:
|
57
|
+
- calebcauthon@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/rtftopdf.rb
|
68
|
+
- lib/rtftopdf/version.rb
|
69
|
+
- rtftopdf.gemspec
|
70
|
+
- test/lib/rtftopdf_test.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
homepage: http://github.com/calebcauthon/rtftopdf
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.1.11
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Converts rtf strings to pdf output using unrtf and wkhtmltopdf.
|
96
|
+
test_files:
|
97
|
+
- test/lib/rtftopdf_test.rb
|
98
|
+
- test/test_helper.rb
|