Class: HyPDF
- Inherits:
-
Object
show all
- Defined in:
- lib/hypdf.rb,
lib/hypdf/version.rb,
lib/hypdf/exceptions.rb
Defined Under Namespace
Classes: AuthorizationRequired, ContentRequired, InternalServerError, NoSuchBucket, PaymentRequired, RequestTimeout, S3AccessDenied
Constant Summary
collapse
- HOST =
ENV['HYPDF_HOST'] || 'https://www.hypdf.com'
- VERSION =
"1.0.19"
Class Method Summary
collapse
-
.decryptpdf(file, options = {}) ⇒ Object
-
.editmeta(file, options = {}) ⇒ Object
-
.encryptpdf(file, options = {}) ⇒ Object
-
.fillform(file, options = {}) ⇒ Object
-
.htmltopdf(content, options = {}) ⇒ Object
-
.jobstatus(job_id, options = {}) ⇒ Object
-
.pdfextract(file, options = {}) ⇒ Object
-
.pdfinfo(file, options = {}) ⇒ Object
-
.pdftotext(file, options = {}) ⇒ Object
-
.pdfunite(*params) ⇒ Object
-
.readform(file, options = {}) ⇒ Object
Class Method Details
.decryptpdf(file, options = {}) ⇒ Object
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/hypdf.rb', line 124
def decryptpdf(file, options = {})
options.merge!(file: File.new(file))
response = request('decryptpdf', options).body
if options[:bucket].nil?
{pdf: response}
else
JSON.parse(response, symbolize_names: true)
end
end
|
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/hypdf.rb', line 56
def editmeta(file, options = {})
options.merge!(file: File.new(file))
response = request('editmeta', options).body
if options[:bucket].nil?
{pdf: response}
else
JSON.parse(response, symbolize_names: true)
end
end
|
.encryptpdf(file, options = {}) ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/hypdf.rb', line 113
def encryptpdf(file, options = {})
options.merge!(file: File.new(file))
response = request('encryptpdf', options).body
if options[:bucket].nil?
{pdf: response}
else
JSON.parse(response, symbolize_names: true)
end
end
|
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/hypdf.rb', line 102
def fillform(file, options = {})
options.merge!(file: File.new(file))
response = request('fillform', options).body
if options[:bucket].nil?
{pdf: response}
else
JSON.parse(response, symbolize_names: true)
end
end
|
.htmltopdf(content, options = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/hypdf.rb', line 12
def htmltopdf(content, options = {})
raise HyPDF::ContentRequired if content.nil? || content.empty?
options[:content] = content
response = request('htmltopdf', options)
result = {
pages: response.['hypdf-pages'].to_i,
page_size: response.['hypdf-page-size'],
pdf_version: response.['hypdf-pdf-version'].to_f
}
if options[:callback].nil? && options[:bucket].nil?
result.merge(pdf: response.body)
else
result.merge(JSON.parse(response.body, symbolize_names: true))
end
end
|
.jobstatus(job_id, options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/hypdf.rb', line 30
def jobstatus(job_id, options = {})
options[:job_id] = job_id
options[:user] ||= ENV["HYPDF_USER"]
options[:password] ||= ENV["HYPDF_PASSWORD"]
response = HTTParty.get(
"#{HyPDF::HOST}/jobstatus",
query: options
)
case response.code
when 200 then JSON.parse(response.body)
when 400 then raise HyPDF::ContentRequired
when 401 then raise HyPDF::AuthorizationRequired
when 402 then raise HyPDF::PaymentRequired
when 403 then raise HyPDF::S3AccessDenied
when 404 then raise HyPDF::NoSuchBucket
when 408 then raise HyPDF::RequestTimeout
when 500 then raise HyPDF::InternalServerError
end
end
|
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/hypdf.rb', line 72
def (file, options = {})
options.merge!(file: File.new(file))
response = request('pdfextract', options).body
if options[:bucket].nil?
{pdf: response}
else
JSON.parse(response, symbolize_names: true)
end
end
|
.pdfinfo(file, options = {}) ⇒ Object
51
52
53
54
|
# File 'lib/hypdf.rb', line 51
def pdfinfo(file, options = {})
options.merge!(file: File.new(file))
JSON.parse(request('pdfinfo', options).body)
end
|
.pdftotext(file, options = {}) ⇒ Object
67
68
69
70
|
# File 'lib/hypdf.rb', line 67
def pdftotext(file, options = {})
options.merge!(file: File.new(file))
JSON.parse(request('pdftotext', options).body, symbolize_names: true)
end
|
.pdfunite(*params) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/hypdf.rb', line 83
def pdfunite(*params)
options = params.last.is_a?(Hash) ? params.delete_at(-1) : {}
params.each_with_index do |param, index|
options.merge!("file_#{index}" => file_for(param, index))
end
response = request('pdfunite', options).body
if options[:bucket].nil?
{pdf: response}
else
JSON.parse(response, symbolize_names: true)
end
end
|
97
98
99
100
|
# File 'lib/hypdf.rb', line 97
def readform(file, options = {})
options.merge!(file: File.new(file))
JSON.parse(request('readform', options).body)
end
|