pdfcrowd 2.3.0 → 2.4.0
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 +7 -0
- data/lib/pdfcrowd.rb +66 -52
- metadata +9 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: 5562a39162351e15148ecf1ffbc6fe7bd2c7f039
|
4
|
+
metadata.gz: 330aeca5d18142d232dd63431f35c74bc8221d80
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: d98fc1713d73e1818760af9ce050385abf2961e4eebb262e2605d77efdf1056aa1296d1c3d8b381ddc17c5becf188e35806c414a9eab34fa558142662bc8d5aa
|
7
|
+
metadata.gz: bbd5c20891097d095e1c567a4da82e55f978913d0cc90bc74cd60691d3558f8e5207adfee2444a3d1dd8393aef25f4433d4430d7b7ce1d19b82f08d8027ca925
|
data/lib/pdfcrowd.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2013 pdfcrowd.com
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person
|
4
4
|
# obtaining a copy of this software and associated documentation
|
@@ -8,10 +8,10 @@
|
|
8
8
|
# copies of the Software, and to permit persons to whom the
|
9
9
|
# Software is furnished to do so, subject to the following
|
10
10
|
# conditions:
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# The above copyright notice and this permission notice shall be
|
13
13
|
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
16
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
17
|
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -28,26 +28,26 @@ require 'cgi'
|
|
28
28
|
module Pdfcrowd
|
29
29
|
# constants for setPageLayout()
|
30
30
|
SINGLE_PAGE, CONTINUOUS, CONTINUOUS_FACING = 1, 2, 3
|
31
|
-
|
31
|
+
|
32
32
|
# constants for setPageMode()
|
33
33
|
NONE_VISIBLE, THUMBNAILS_VISIBLE, FULLSCREEN = 1, 2, 3
|
34
|
-
|
34
|
+
|
35
35
|
# constants for setInitialPdfZoomType()
|
36
36
|
FIT_WIDTH, FIT_HEIGHT, FIT_PAGE = 1, 2, 3
|
37
37
|
|
38
38
|
|
39
39
|
#
|
40
40
|
# Thrown when an error occurs.
|
41
|
-
#
|
41
|
+
#
|
42
42
|
class Error < RuntimeError
|
43
43
|
attr_reader :http_code, :error
|
44
|
-
|
44
|
+
|
45
45
|
def initialize(error, http_code=nil)
|
46
46
|
super()
|
47
47
|
@http_code = http_code
|
48
48
|
@error = error
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def to_s()
|
52
52
|
|
53
53
|
@http_code ? "#{@http_code} - #{@error}" : @error
|
@@ -57,9 +57,9 @@ module Pdfcrowd
|
|
57
57
|
|
58
58
|
#
|
59
59
|
# Pdfcrowd API client.
|
60
|
-
#
|
60
|
+
#
|
61
61
|
class Client
|
62
|
-
|
62
|
+
|
63
63
|
#
|
64
64
|
# Client constructor.
|
65
65
|
#
|
@@ -68,39 +68,39 @@ module Pdfcrowd
|
|
68
68
|
#
|
69
69
|
def initialize(username, apikey)
|
70
70
|
useSSL(false)
|
71
|
-
@fields = {
|
71
|
+
@fields = {
|
72
72
|
'username' => username,
|
73
73
|
'key' => apikey,
|
74
74
|
'html_zoom' => 200,
|
75
75
|
'pdf_scaling_factor' => 1
|
76
76
|
}
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
#
|
80
80
|
# Converts a web page.
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# uri -- a web page URL
|
83
83
|
# outstream -- an object having method 'write(data)'; if nil then the
|
84
84
|
# return value is a string containing the PDF.
|
85
|
-
#
|
85
|
+
#
|
86
86
|
def convertURI(uri, outstream=nil)
|
87
87
|
return call_api_urlencoded('/api/pdf/convert/uri/', uri, outstream)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
#
|
91
91
|
# Converts an in-memory html document.
|
92
92
|
#
|
93
93
|
# content -- a string containing an html document
|
94
94
|
# outstream -- an object having method 'write(data)'; if nil then the
|
95
95
|
# return value is a string containing the PDF.
|
96
|
-
#
|
96
|
+
#
|
97
97
|
def convertHtml(content, outstream=nil)
|
98
98
|
return call_api_urlencoded('/api/pdf/convert/html/', content, outstream)
|
99
99
|
end
|
100
100
|
|
101
101
|
#
|
102
102
|
# Converts an html file.
|
103
|
-
#
|
103
|
+
#
|
104
104
|
# fpath -- a path to an html file
|
105
105
|
# outstream -- an object having method 'write(data)'; if nil then the
|
106
106
|
# return value is a string containing the PDF.
|
@@ -111,65 +111,73 @@ module Pdfcrowd
|
|
111
111
|
|
112
112
|
#
|
113
113
|
# Returns the number of available conversion tokens.
|
114
|
-
#
|
114
|
+
#
|
115
115
|
def numTokens()
|
116
116
|
uri = '/api/user/%s/tokens/' % @fields['username']
|
117
117
|
return Integer(call_api_urlencoded(uri))
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def useSSL(use_ssl)
|
121
121
|
@use_ssl = use_ssl
|
122
122
|
@api_uri = use_ssl ? HTTPS_API_URI : HTTP_API_URI
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
def setUsername(username)
|
126
126
|
@fields['username'] = username
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
def setApiKey(key)
|
130
130
|
@fields['key'] = key
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
def setPageWidth(value)
|
134
134
|
@fields['width'] = value
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
def setPageHeight(value)
|
138
138
|
@fields['height'] = value
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
def setHorizontalMargin(value)
|
142
|
-
@fields['
|
142
|
+
@fields['margin_right'] = @fields['margin_left'] = value.to_s()
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
def setVerticalMargin(value)
|
146
|
-
@fields['
|
146
|
+
@fields['margin_top'] = @fields['margin_bottom'] = value.to_s()
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
|
+
def setPageMargins(top, right, bottom, left)
|
150
|
+
@fields['margin_top'] = top.to_s()
|
151
|
+
@fields['margin_right'] = right.to_s()
|
152
|
+
@fields['margin_bottom'] = bottom.to_s()
|
153
|
+
@fields['margin_left'] = left.to_s()
|
154
|
+
end
|
155
|
+
|
156
|
+
|
149
157
|
def setEncrypted(val=true)
|
150
158
|
@fields['encrypted'] = val
|
151
159
|
end
|
152
|
-
|
160
|
+
|
153
161
|
def setUserPassword(pwd)
|
154
162
|
@fields['user_pwd'] = pwd
|
155
163
|
end
|
156
|
-
|
164
|
+
|
157
165
|
def setOwnerPassword(pwd)
|
158
166
|
@fields['owner_pwd'] = pwd
|
159
167
|
end
|
160
|
-
|
168
|
+
|
161
169
|
def setNoPrint(val=true)
|
162
170
|
@fields['no_print'] = val
|
163
171
|
end
|
164
|
-
|
172
|
+
|
165
173
|
def setNoModify(val=true)
|
166
174
|
@fields['no_modify'] = val
|
167
175
|
end
|
168
|
-
|
176
|
+
|
169
177
|
def setNoCopy(val=true)
|
170
178
|
@fields['no_copy'] = val
|
171
179
|
end
|
172
|
-
|
180
|
+
|
173
181
|
def setPageLayout(value)
|
174
182
|
assert { value > 0 and value <= 3 }
|
175
183
|
@fields['page_layout'] = value
|
@@ -225,7 +233,7 @@ module Pdfcrowd
|
|
225
233
|
assert { value>0 and value<=3 }
|
226
234
|
@fields['initial_pdf_zoom_type'] = value
|
227
235
|
end
|
228
|
-
|
236
|
+
|
229
237
|
def setInitialPdfExactZoom(value)
|
230
238
|
@fields['initial_pdf_zoom_type'] = 4
|
231
239
|
@fields['initial_pdf_zoom'] = value
|
@@ -246,15 +254,15 @@ module Pdfcrowd
|
|
246
254
|
def setFooterHtml(value)
|
247
255
|
@fields['footer_html'] = value
|
248
256
|
end
|
249
|
-
|
257
|
+
|
250
258
|
def setFooterUrl(value)
|
251
259
|
@fields['footer_url'] = value
|
252
260
|
end
|
253
|
-
|
261
|
+
|
254
262
|
def setHeaderHtml(value)
|
255
263
|
@fields['header_html'] = value
|
256
264
|
end
|
257
|
-
|
265
|
+
|
258
266
|
def setHeaderUrl(value)
|
259
267
|
@fields['header_url'] = value
|
260
268
|
end
|
@@ -296,28 +304,28 @@ module Pdfcrowd
|
|
296
304
|
# Private stuff
|
297
305
|
#
|
298
306
|
|
299
|
-
private
|
307
|
+
private
|
300
308
|
|
301
309
|
def create_http_obj()
|
302
310
|
if @use_ssl
|
303
|
-
require 'net/https' #apt-get install libopenssl-ruby
|
311
|
+
require 'net/https' #apt-get install libopenssl-ruby
|
304
312
|
http = Net::HTTP.new($api_hostname, $api_https_port)
|
305
313
|
# OpenSSL::SSL::VERIFY_PEER fails here:
|
306
314
|
# ... certificate verify failed ...
|
307
315
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
308
|
-
http.use_ssl = @use_ssl
|
316
|
+
http.use_ssl = @use_ssl
|
309
317
|
else
|
310
318
|
http = Net::HTTP.new($api_hostname, $api_http_port)
|
311
319
|
end
|
312
320
|
return http
|
313
321
|
end
|
314
|
-
|
322
|
+
|
315
323
|
def call_api_urlencoded(path, src=nil, out_stream=nil)
|
316
324
|
request = Net::HTTP::Post.new(path)
|
317
325
|
request.set_form_data(rename_post_data({'src' => src}))
|
318
326
|
return call_api(request, out_stream)
|
319
327
|
end
|
320
|
-
|
328
|
+
|
321
329
|
|
322
330
|
def call_api(request, out_stream)
|
323
331
|
http = create_http_obj()
|
@@ -348,7 +356,7 @@ module Pdfcrowd
|
|
348
356
|
@fields.each { |key, val| result[key] = val if val }
|
349
357
|
result
|
350
358
|
end
|
351
|
-
|
359
|
+
|
352
360
|
def encode_multipart_post_data(filename)
|
353
361
|
boundary = '----------ThIs_Is_tHe_bOUnDary_$'
|
354
362
|
body = []
|
@@ -369,7 +377,7 @@ module Pdfcrowd
|
|
369
377
|
content_type = 'multipart/form-data; boundary=%s' % boundary
|
370
378
|
return content_type, body
|
371
379
|
end
|
372
|
-
|
380
|
+
|
373
381
|
def post_multipart(fpath, out_stream)
|
374
382
|
req = Net::HTTP::Post.new('/api/pdf/convert/html/')
|
375
383
|
req.content_type, req.body = encode_multipart_post_data(fpath)
|
@@ -398,7 +406,7 @@ HTTPS_API_URI = "https://#{$api_hostname}#{API_SELECTOR_BASE}"
|
|
398
406
|
# ---------------------------------------------------------------------------
|
399
407
|
#
|
400
408
|
# Test
|
401
|
-
#
|
409
|
+
#
|
402
410
|
|
403
411
|
if __FILE__ == $0
|
404
412
|
if ARGV.length < 2
|
@@ -419,10 +427,10 @@ if __FILE__ == $0
|
|
419
427
|
|
420
428
|
some_html="<html><body>Uploaded content!</body></html>"
|
421
429
|
Dir.chdir(File.dirname($0))
|
422
|
-
$test_dir = '
|
430
|
+
$test_dir = '../test_files'
|
423
431
|
|
424
432
|
def out_stream(name, use_ssl)
|
425
|
-
fname =
|
433
|
+
fname = $test_dir + "/out/rb_client_#{name}"
|
426
434
|
if use_ssl
|
427
435
|
fname = fname + '_ssl'
|
428
436
|
end
|
@@ -434,7 +442,7 @@ if __FILE__ == $0
|
|
434
442
|
client.useSSL(use_ssl)
|
435
443
|
begin
|
436
444
|
ntokens = client.numTokens()
|
437
|
-
client.convertURI('http://www.
|
445
|
+
client.convertURI('http://www.web-to-pdf.com', out_stream('uri', use_ssl))
|
438
446
|
client.convertHtml(some_html, out_stream('content', use_ssl))
|
439
447
|
client.convertFile("#{$test_dir}/in/simple.html", out_stream('upload', use_ssl))
|
440
448
|
client.convertFile("#{$test_dir}/in/archive.tar.gz", out_stream('archive', use_ssl))
|
@@ -476,9 +484,9 @@ if __FILE__ == $0
|
|
476
484
|
[:setInitialPdfZoomType, Pdfcrowd::FIT_PAGE],
|
477
485
|
[:setInitialPdfExactZoom, 113],
|
478
486
|
[:setFooterHtml, '<b>bold</b> and <i>italic</i> <img src="http://pdfcrowd.com/static/images/logo175x30.png" />'],
|
479
|
-
[:setFooterUrl, 'http://
|
487
|
+
[:setFooterUrl, 'http://pdfcrowd.com/hub/random/footer.html'],
|
480
488
|
[:setHeaderHtml, 'page %p out of %n'],
|
481
|
-
[:setHeaderUrl, 'http://
|
489
|
+
[:setHeaderUrl, 'http://pdfcrowd.com/hub/random/header.html'],
|
482
490
|
[:setPdfScalingFactor, 0.5],
|
483
491
|
[:setPageBackgroundColor, 'ee82EE'],
|
484
492
|
[:setTransparentBackground, true]]
|
@@ -491,5 +499,11 @@ if __FILE__ == $0
|
|
491
499
|
print 'FAILED: ', why
|
492
500
|
exit(1)
|
493
501
|
end
|
494
|
-
|
502
|
+
|
503
|
+
# 4 margins
|
504
|
+
client = Pdfcrowd::Client.new(ARGV[0], ARGV[1])
|
505
|
+
client.setPageMargins('0.25in', '0.5in', '0.75in', '1.0in')
|
506
|
+
client.convertHtml('<div style="background-color:red;height:100%">4 margins</div>', out_stream('4margins', false))
|
507
|
+
|
508
|
+
|
495
509
|
end
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfcrowd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 2.3.0
|
4
|
+
version: 2.4.0
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Pdfcrowd Team
|
@@ -15,7 +9,7 @@ autorequire:
|
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
11
|
|
18
|
-
date:
|
12
|
+
date: 2013-03-13 00:00:00 Z
|
19
13
|
dependencies: []
|
20
14
|
|
21
15
|
description: It lets you easily convert web pages and raw HTML code to PDF in your Ruby applications.
|
@@ -31,35 +25,28 @@ files:
|
|
31
25
|
homepage: https://pdfcrowd.com/html-to-pdf-api/
|
32
26
|
licenses: []
|
33
27
|
|
28
|
+
metadata: {}
|
29
|
+
|
34
30
|
post_install_message:
|
35
31
|
rdoc_options: []
|
36
32
|
|
37
33
|
require_paths:
|
38
34
|
- lib
|
39
35
|
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
36
|
requirements:
|
42
|
-
-
|
37
|
+
- &id001
|
38
|
+
- ">="
|
43
39
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 3
|
45
|
-
segments:
|
46
|
-
- 0
|
47
40
|
version: "0"
|
48
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
42
|
requirements:
|
51
|
-
-
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
hash: 3
|
54
|
-
segments:
|
55
|
-
- 0
|
56
|
-
version: "0"
|
43
|
+
- *id001
|
57
44
|
requirements: []
|
58
45
|
|
59
46
|
rubyforge_project:
|
60
|
-
rubygems_version:
|
47
|
+
rubygems_version: 2.0.3
|
61
48
|
signing_key:
|
62
|
-
specification_version:
|
49
|
+
specification_version: 4
|
63
50
|
summary: A client for the Pdfcrowd HTML to PDF API.
|
64
51
|
test_files: []
|
65
52
|
|