pdfcrowd 5.3.0 → 5.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 +4 -4
- data/lib/pdfcrowd.rb +496 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5e4aae437d0c4993770eb539bcd6ec2ead0c8e825e3c3722be116d3b8547aa
|
4
|
+
data.tar.gz: 0dfb6bd06a801af12961879abf6f7fb2b0abe641612c53c064479fd7bd484b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7fbfa74285c6e038ec517bbd084b2d0022939233be6b639d9c412a4c9a40018029c7a82b86c34f2a957b5c44914ecd54b3326d5381f101764b9055088fdc86d
|
7
|
+
data.tar.gz: b076d3ea8b2766b5668f36fcafc895e597e47beb0a64c0237ace8ff25e121f934a0ec54c53456578f60b39611a2c2d29617fc805ab5a397b87d8f0fd8f7b7161
|
data/lib/pdfcrowd.rb
CHANGED
@@ -530,7 +530,7 @@ end
|
|
530
530
|
module Pdfcrowd
|
531
531
|
HOST = ENV["PDFCROWD_HOST"] || 'api.pdfcrowd.com'
|
532
532
|
MULTIPART_BOUNDARY = '----------ThIs_Is_tHe_bOUnDary_$'
|
533
|
-
CLIENT_VERSION = '5.
|
533
|
+
CLIENT_VERSION = '5.4.0'
|
534
534
|
|
535
535
|
class ConnectionHelper
|
536
536
|
def initialize(user_name, api_key)
|
@@ -541,7 +541,7 @@ module Pdfcrowd
|
|
541
541
|
|
542
542
|
setProxy(nil, nil, nil, nil)
|
543
543
|
setUseHttp(false)
|
544
|
-
setUserAgent('pdfcrowd_ruby_client/5.
|
544
|
+
setUserAgent('pdfcrowd_ruby_client/5.4.0 (https://pdfcrowd.com)')
|
545
545
|
|
546
546
|
@retry_count = 1
|
547
547
|
@converter_version = '20.10'
|
@@ -1716,7 +1716,7 @@ module Pdfcrowd
|
|
1716
1716
|
self
|
1717
1717
|
end
|
1718
1718
|
|
1719
|
-
# Set the viewport height in pixels. The viewport is the user's visible area of the page.
|
1719
|
+
# Set the viewport height in pixels. The viewport is the user's visible area of the page. If the input HTML uses lazily loaded images, try using a large value that covers the entire height of the HTML, e.g. 100000.
|
1720
1720
|
#
|
1721
1721
|
# * +height+ - Must be a positive integer number.
|
1722
1722
|
# * *Returns* - The converter object.
|
@@ -1732,7 +1732,7 @@ module Pdfcrowd
|
|
1732
1732
|
# Set the viewport size. The viewport is the user's visible area of the page.
|
1733
1733
|
#
|
1734
1734
|
# * +width+ - Set the viewport width in pixels. The viewport is the user's visible area of the page. The value must be in the range 96-65000.
|
1735
|
-
# * +height+ - Set the viewport height in pixels. The viewport is the user's visible area of the page. Must be a positive integer number.
|
1735
|
+
# * +height+ - Set the viewport height in pixels. The viewport is the user's visible area of the page. If the input HTML uses lazily loaded images, try using a large value that covers the entire height of the HTML, e.g. 100000. Must be a positive integer number.
|
1736
1736
|
# * *Returns* - The converter object.
|
1737
1737
|
def setViewport(width, height)
|
1738
1738
|
setViewportWidth(width)
|
@@ -2146,7 +2146,7 @@ module Pdfcrowd
|
|
2146
2146
|
end
|
2147
2147
|
|
2148
2148
|
# Get the number of conversion credits available in your account.
|
2149
|
-
# This method can only be called after a call to one of the
|
2149
|
+
# This method can only be called after a call to one of the convertXtoY methods.
|
2150
2150
|
# The returned value can differ from the actual count if you run parallel conversions.
|
2151
2151
|
# The special value 999999 is returned if the information is not available.
|
2152
2152
|
# * *Returns* - The number of credits.
|
@@ -2332,7 +2332,7 @@ module Pdfcrowd
|
|
2332
2332
|
self
|
2333
2333
|
end
|
2334
2334
|
|
2335
|
-
# Set a custom user agent HTTP header. It can be useful if you are behind
|
2335
|
+
# Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
|
2336
2336
|
#
|
2337
2337
|
# * +agent+ - The user agent string.
|
2338
2338
|
# * *Returns* - The converter object.
|
@@ -2353,9 +2353,9 @@ module Pdfcrowd
|
|
2353
2353
|
self
|
2354
2354
|
end
|
2355
2355
|
|
2356
|
-
# Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
2356
|
+
# Specifies the number of automatic retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
2357
2357
|
#
|
2358
|
-
# * +count+ - Number of retries
|
2358
|
+
# * +count+ - Number of retries.
|
2359
2359
|
# * *Returns* - The converter object.
|
2360
2360
|
def setRetryCount(count)
|
2361
2361
|
@helper.setRetryCount(count)
|
@@ -2982,7 +2982,7 @@ module Pdfcrowd
|
|
2982
2982
|
end
|
2983
2983
|
|
2984
2984
|
# Get the number of conversion credits available in your account.
|
2985
|
-
# This method can only be called after a call to one of the
|
2985
|
+
# This method can only be called after a call to one of the convertXtoY methods.
|
2986
2986
|
# The returned value can differ from the actual count if you run parallel conversions.
|
2987
2987
|
# The special value 999999 is returned if the information is not available.
|
2988
2988
|
# * *Returns* - The number of credits.
|
@@ -3094,7 +3094,7 @@ module Pdfcrowd
|
|
3094
3094
|
self
|
3095
3095
|
end
|
3096
3096
|
|
3097
|
-
# Set a custom user agent HTTP header. It can be useful if you are behind
|
3097
|
+
# Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
|
3098
3098
|
#
|
3099
3099
|
# * +agent+ - The user agent string.
|
3100
3100
|
# * *Returns* - The converter object.
|
@@ -3115,9 +3115,9 @@ module Pdfcrowd
|
|
3115
3115
|
self
|
3116
3116
|
end
|
3117
3117
|
|
3118
|
-
# Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
3118
|
+
# Specifies the number of automatic retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
3119
3119
|
#
|
3120
|
-
# * +count+ - Number of retries
|
3120
|
+
# * +count+ - Number of retries.
|
3121
3121
|
# * *Returns* - The converter object.
|
3122
3122
|
def setRetryCount(count)
|
3123
3123
|
@helper.setRetryCount(count)
|
@@ -3358,7 +3358,7 @@ module Pdfcrowd
|
|
3358
3358
|
end
|
3359
3359
|
|
3360
3360
|
# Get the number of conversion credits available in your account.
|
3361
|
-
# This method can only be called after a call to one of the
|
3361
|
+
# This method can only be called after a call to one of the convertXtoY methods.
|
3362
3362
|
# The returned value can differ from the actual count if you run parallel conversions.
|
3363
3363
|
# The special value 999999 is returned if the information is not available.
|
3364
3364
|
# * *Returns* - The number of credits.
|
@@ -3448,7 +3448,7 @@ module Pdfcrowd
|
|
3448
3448
|
self
|
3449
3449
|
end
|
3450
3450
|
|
3451
|
-
# Set a custom user agent HTTP header. It can be useful if you are behind
|
3451
|
+
# Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
|
3452
3452
|
#
|
3453
3453
|
# * +agent+ - The user agent string.
|
3454
3454
|
# * *Returns* - The converter object.
|
@@ -3469,9 +3469,9 @@ module Pdfcrowd
|
|
3469
3469
|
self
|
3470
3470
|
end
|
3471
3471
|
|
3472
|
-
# Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
3472
|
+
# Specifies the number of automatic retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
3473
3473
|
#
|
3474
|
-
# * +count+ - Number of retries
|
3474
|
+
# * +count+ - Number of retries.
|
3475
3475
|
# * *Returns* - The converter object.
|
3476
3476
|
def setRetryCount(count)
|
3477
3477
|
@helper.setRetryCount(count)
|
@@ -3564,6 +3564,15 @@ module Pdfcrowd
|
|
3564
3564
|
self
|
3565
3565
|
end
|
3566
3566
|
|
3567
|
+
# Password to open the encrypted PDF file.
|
3568
|
+
#
|
3569
|
+
# * +password+ - The input PDF password.
|
3570
|
+
# * *Returns* - The converter object.
|
3571
|
+
def setInputPdfPassword(password)
|
3572
|
+
@fields['input_pdf_password'] = password
|
3573
|
+
self
|
3574
|
+
end
|
3575
|
+
|
3567
3576
|
# Apply the first page of the watermark PDF to every page of the output PDF.
|
3568
3577
|
#
|
3569
3578
|
# * +watermark+ - The file path to a local watermark PDF file. The file must exist and not be empty.
|
@@ -3924,7 +3933,7 @@ module Pdfcrowd
|
|
3924
3933
|
end
|
3925
3934
|
|
3926
3935
|
# Get the number of conversion credits available in your account.
|
3927
|
-
# This method can only be called after a call to one of the
|
3936
|
+
# This method can only be called after a call to one of the convertXtoY methods.
|
3928
3937
|
# The returned value can differ from the actual count if you run parallel conversions.
|
3929
3938
|
# The special value 999999 is returned if the information is not available.
|
3930
3939
|
# * *Returns* - The number of credits.
|
@@ -3994,7 +4003,7 @@ module Pdfcrowd
|
|
3994
4003
|
self
|
3995
4004
|
end
|
3996
4005
|
|
3997
|
-
# Set a custom user agent HTTP header. It can be useful if you are behind
|
4006
|
+
# Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
|
3998
4007
|
#
|
3999
4008
|
# * +agent+ - The user agent string.
|
4000
4009
|
# * *Returns* - The converter object.
|
@@ -4015,9 +4024,9 @@ module Pdfcrowd
|
|
4015
4024
|
self
|
4016
4025
|
end
|
4017
4026
|
|
4018
|
-
# Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
4027
|
+
# Specifies the number of automatic retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
4019
4028
|
#
|
4020
|
-
# * +count+ - Number of retries
|
4029
|
+
# * +count+ - Number of retries.
|
4021
4030
|
# * *Returns* - The converter object.
|
4022
4031
|
def setRetryCount(count)
|
4023
4032
|
@helper.setRetryCount(count)
|
@@ -4245,7 +4254,7 @@ module Pdfcrowd
|
|
4245
4254
|
end
|
4246
4255
|
|
4247
4256
|
# Get the number of conversion credits available in your account.
|
4248
|
-
# This method can only be called after a call to one of the
|
4257
|
+
# This method can only be called after a call to one of the convertXtoY methods.
|
4249
4258
|
# The returned value can differ from the actual count if you run parallel conversions.
|
4250
4259
|
# The special value 999999 is returned if the information is not available.
|
4251
4260
|
# * *Returns* - The number of credits.
|
@@ -4335,7 +4344,464 @@ module Pdfcrowd
|
|
4335
4344
|
self
|
4336
4345
|
end
|
4337
4346
|
|
4338
|
-
# Set a custom user agent HTTP header. It can be useful if you are behind
|
4347
|
+
# Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
|
4348
|
+
#
|
4349
|
+
# * +agent+ - The user agent string.
|
4350
|
+
# * *Returns* - The converter object.
|
4351
|
+
def setUserAgent(agent)
|
4352
|
+
@helper.setUserAgent(agent)
|
4353
|
+
self
|
4354
|
+
end
|
4355
|
+
|
4356
|
+
# Specifies an HTTP proxy that the API client library will use to connect to the internet.
|
4357
|
+
#
|
4358
|
+
# * +host+ - The proxy hostname.
|
4359
|
+
# * +port+ - The proxy port.
|
4360
|
+
# * +user_name+ - The username.
|
4361
|
+
# * +password+ - The password.
|
4362
|
+
# * *Returns* - The converter object.
|
4363
|
+
def setProxy(host, port, user_name, password)
|
4364
|
+
@helper.setProxy(host, port, user_name, password)
|
4365
|
+
self
|
4366
|
+
end
|
4367
|
+
|
4368
|
+
# Specifies the number of automatic retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
4369
|
+
#
|
4370
|
+
# * +count+ - Number of retries.
|
4371
|
+
# * *Returns* - The converter object.
|
4372
|
+
def setRetryCount(count)
|
4373
|
+
@helper.setRetryCount(count)
|
4374
|
+
self
|
4375
|
+
end
|
4376
|
+
|
4377
|
+
end
|
4378
|
+
|
4379
|
+
# Conversion from PDF to HTML.
|
4380
|
+
class PdfToHtmlClient
|
4381
|
+
# Constructor for the Pdfcrowd API client.
|
4382
|
+
#
|
4383
|
+
# * +user_name+ - Your username at Pdfcrowd.
|
4384
|
+
# * +api_key+ - Your API key.
|
4385
|
+
def initialize(user_name, api_key)
|
4386
|
+
@helper = ConnectionHelper.new(user_name, api_key)
|
4387
|
+
@fields = {
|
4388
|
+
'input_format'=>'pdf',
|
4389
|
+
'output_format'=>'html'
|
4390
|
+
}
|
4391
|
+
@file_id = 1
|
4392
|
+
@files = {}
|
4393
|
+
@raw_data = {}
|
4394
|
+
end
|
4395
|
+
|
4396
|
+
# Convert a PDF.
|
4397
|
+
#
|
4398
|
+
# * +url+ - The address of the PDF to convert. The supported protocols are http:// and https://.
|
4399
|
+
# * *Returns* - Byte array containing the conversion output.
|
4400
|
+
def convertUrl(url)
|
4401
|
+
unless /(?i)^https?:\/\/.*$/.match(url)
|
4402
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "pdf-to-html", "The supported protocols are http:// and https://.", "convert_url"), 470);
|
4403
|
+
end
|
4404
|
+
|
4405
|
+
@fields['url'] = url
|
4406
|
+
@helper.post(@fields, @files, @raw_data)
|
4407
|
+
end
|
4408
|
+
|
4409
|
+
# Convert a PDF and write the result to an output stream.
|
4410
|
+
#
|
4411
|
+
# * +url+ - The address of the PDF to convert. The supported protocols are http:// and https://.
|
4412
|
+
# * +out_stream+ - The output stream that will contain the conversion output.
|
4413
|
+
def convertUrlToStream(url, out_stream)
|
4414
|
+
unless /(?i)^https?:\/\/.*$/.match(url)
|
4415
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "pdf-to-html", "The supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
|
4416
|
+
end
|
4417
|
+
|
4418
|
+
@fields['url'] = url
|
4419
|
+
@helper.post(@fields, @files, @raw_data, out_stream)
|
4420
|
+
end
|
4421
|
+
|
4422
|
+
# Convert a PDF and write the result to a local file.
|
4423
|
+
#
|
4424
|
+
# * +url+ - The address of the PDF to convert. The supported protocols are http:// and https://.
|
4425
|
+
# * +file_path+ - The output file path. The string must not be empty. The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.
|
4426
|
+
def convertUrlToFile(url, file_path)
|
4427
|
+
if (!(!file_path.nil? && !file_path.empty?))
|
4428
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertUrlToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_url_to_file"), 470);
|
4429
|
+
end
|
4430
|
+
|
4431
|
+
if (!(isOutputTypeValid(file_path)))
|
4432
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertUrlToFile::file_path", "pdf-to-html", "The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.", "convert_url_to_file"), 470);
|
4433
|
+
end
|
4434
|
+
|
4435
|
+
output_file = open(file_path, "wb")
|
4436
|
+
begin
|
4437
|
+
convertUrlToStream(url, output_file)
|
4438
|
+
output_file.close()
|
4439
|
+
rescue Error => why
|
4440
|
+
output_file.close()
|
4441
|
+
FileUtils.rm(file_path)
|
4442
|
+
raise
|
4443
|
+
end
|
4444
|
+
end
|
4445
|
+
|
4446
|
+
# Convert a local file.
|
4447
|
+
#
|
4448
|
+
# * +file+ - The path to a local file to convert. The file must exist and not be empty.
|
4449
|
+
# * *Returns* - Byte array containing the conversion output.
|
4450
|
+
def convertFile(file)
|
4451
|
+
if (!(File.file?(file) && !File.zero?(file)))
|
4452
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "pdf-to-html", "The file must exist and not be empty.", "convert_file"), 470);
|
4453
|
+
end
|
4454
|
+
|
4455
|
+
@files['file'] = file
|
4456
|
+
@helper.post(@fields, @files, @raw_data)
|
4457
|
+
end
|
4458
|
+
|
4459
|
+
# Convert a local file and write the result to an output stream.
|
4460
|
+
#
|
4461
|
+
# * +file+ - The path to a local file to convert. The file must exist and not be empty.
|
4462
|
+
# * +out_stream+ - The output stream that will contain the conversion output.
|
4463
|
+
def convertFileToStream(file, out_stream)
|
4464
|
+
if (!(File.file?(file) && !File.zero?(file)))
|
4465
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "pdf-to-html", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
|
4466
|
+
end
|
4467
|
+
|
4468
|
+
@files['file'] = file
|
4469
|
+
@helper.post(@fields, @files, @raw_data, out_stream)
|
4470
|
+
end
|
4471
|
+
|
4472
|
+
# Convert a local file and write the result to a local file.
|
4473
|
+
#
|
4474
|
+
# * +file+ - The path to a local file to convert. The file must exist and not be empty.
|
4475
|
+
# * +file_path+ - The output file path. The string must not be empty. The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.
|
4476
|
+
def convertFileToFile(file, file_path)
|
4477
|
+
if (!(!file_path.nil? && !file_path.empty?))
|
4478
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertFileToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_file_to_file"), 470);
|
4479
|
+
end
|
4480
|
+
|
4481
|
+
if (!(isOutputTypeValid(file_path)))
|
4482
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertFileToFile::file_path", "pdf-to-html", "The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.", "convert_file_to_file"), 470);
|
4483
|
+
end
|
4484
|
+
|
4485
|
+
output_file = open(file_path, "wb")
|
4486
|
+
begin
|
4487
|
+
convertFileToStream(file, output_file)
|
4488
|
+
output_file.close()
|
4489
|
+
rescue Error => why
|
4490
|
+
output_file.close()
|
4491
|
+
FileUtils.rm(file_path)
|
4492
|
+
raise
|
4493
|
+
end
|
4494
|
+
end
|
4495
|
+
|
4496
|
+
# Convert raw data.
|
4497
|
+
#
|
4498
|
+
# * +data+ - The raw content to be converted.
|
4499
|
+
# * *Returns* - Byte array with the output.
|
4500
|
+
def convertRawData(data)
|
4501
|
+
@raw_data['file'] = data
|
4502
|
+
@helper.post(@fields, @files, @raw_data)
|
4503
|
+
end
|
4504
|
+
|
4505
|
+
# Convert raw data and write the result to an output stream.
|
4506
|
+
#
|
4507
|
+
# * +data+ - The raw content to be converted.
|
4508
|
+
# * +out_stream+ - The output stream that will contain the conversion output.
|
4509
|
+
def convertRawDataToStream(data, out_stream)
|
4510
|
+
@raw_data['file'] = data
|
4511
|
+
@helper.post(@fields, @files, @raw_data, out_stream)
|
4512
|
+
end
|
4513
|
+
|
4514
|
+
# Convert raw data to a file.
|
4515
|
+
#
|
4516
|
+
# * +data+ - The raw content to be converted.
|
4517
|
+
# * +file_path+ - The output file path. The string must not be empty. The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.
|
4518
|
+
def convertRawDataToFile(data, file_path)
|
4519
|
+
if (!(!file_path.nil? && !file_path.empty?))
|
4520
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertRawDataToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_raw_data_to_file"), 470);
|
4521
|
+
end
|
4522
|
+
|
4523
|
+
if (!(isOutputTypeValid(file_path)))
|
4524
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertRawDataToFile::file_path", "pdf-to-html", "The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.", "convert_raw_data_to_file"), 470);
|
4525
|
+
end
|
4526
|
+
|
4527
|
+
output_file = open(file_path, "wb")
|
4528
|
+
begin
|
4529
|
+
convertRawDataToStream(data, output_file)
|
4530
|
+
output_file.close()
|
4531
|
+
rescue Error => why
|
4532
|
+
output_file.close()
|
4533
|
+
FileUtils.rm(file_path)
|
4534
|
+
raise
|
4535
|
+
end
|
4536
|
+
end
|
4537
|
+
|
4538
|
+
# Convert the contents of an input stream.
|
4539
|
+
#
|
4540
|
+
# * +in_stream+ - The input stream with source data.
|
4541
|
+
# * *Returns* - Byte array containing the conversion output.
|
4542
|
+
def convertStream(in_stream)
|
4543
|
+
@raw_data['stream'] = in_stream.read
|
4544
|
+
@helper.post(@fields, @files, @raw_data)
|
4545
|
+
end
|
4546
|
+
|
4547
|
+
# Convert the contents of an input stream and write the result to an output stream.
|
4548
|
+
#
|
4549
|
+
# * +in_stream+ - The input stream with source data.
|
4550
|
+
# * +out_stream+ - The output stream that will contain the conversion output.
|
4551
|
+
def convertStreamToStream(in_stream, out_stream)
|
4552
|
+
@raw_data['stream'] = in_stream.read
|
4553
|
+
@helper.post(@fields, @files, @raw_data, out_stream)
|
4554
|
+
end
|
4555
|
+
|
4556
|
+
# Convert the contents of an input stream and write the result to a local file.
|
4557
|
+
#
|
4558
|
+
# * +in_stream+ - The input stream with source data.
|
4559
|
+
# * +file_path+ - The output file path. The string must not be empty. The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.
|
4560
|
+
def convertStreamToFile(in_stream, file_path)
|
4561
|
+
if (!(!file_path.nil? && !file_path.empty?))
|
4562
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertStreamToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_stream_to_file"), 470);
|
4563
|
+
end
|
4564
|
+
|
4565
|
+
if (!(isOutputTypeValid(file_path)))
|
4566
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertStreamToFile::file_path", "pdf-to-html", "The converter generates an HTML or ZIP file. If ZIP file is generated, the file path must have a ZIP or zip extension.", "convert_stream_to_file"), 470);
|
4567
|
+
end
|
4568
|
+
|
4569
|
+
output_file = open(file_path, "wb")
|
4570
|
+
begin
|
4571
|
+
convertStreamToStream(in_stream, output_file)
|
4572
|
+
output_file.close()
|
4573
|
+
rescue Error => why
|
4574
|
+
output_file.close()
|
4575
|
+
FileUtils.rm(file_path)
|
4576
|
+
raise
|
4577
|
+
end
|
4578
|
+
end
|
4579
|
+
|
4580
|
+
# Password to open the encrypted PDF file.
|
4581
|
+
#
|
4582
|
+
# * +password+ - The input PDF password.
|
4583
|
+
# * *Returns* - The converter object.
|
4584
|
+
def setPdfPassword(password)
|
4585
|
+
@fields['pdf_password'] = password
|
4586
|
+
self
|
4587
|
+
end
|
4588
|
+
|
4589
|
+
# Set the scaling factor (zoom) for the main page area.
|
4590
|
+
#
|
4591
|
+
# * +factor+ - The percentage value. Must be a positive integer number.
|
4592
|
+
# * *Returns* - The converter object.
|
4593
|
+
def setScaleFactor(factor)
|
4594
|
+
if (!(Integer(factor) > 0))
|
4595
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(factor, "setScaleFactor", "pdf-to-html", "Must be a positive integer number.", "set_scale_factor"), 470);
|
4596
|
+
end
|
4597
|
+
|
4598
|
+
@fields['scale_factor'] = factor
|
4599
|
+
self
|
4600
|
+
end
|
4601
|
+
|
4602
|
+
# Set the page range to print.
|
4603
|
+
#
|
4604
|
+
# * +pages+ - A comma separated list of page numbers or ranges.
|
4605
|
+
# * *Returns* - The converter object.
|
4606
|
+
def setPrintPageRange(pages)
|
4607
|
+
unless /^(?:\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*,\s*)*\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*$/.match(pages)
|
4608
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "setPrintPageRange", "pdf-to-html", "A comma separated list of page numbers or ranges.", "set_print_page_range"), 470);
|
4609
|
+
end
|
4610
|
+
|
4611
|
+
@fields['print_page_range'] = pages
|
4612
|
+
self
|
4613
|
+
end
|
4614
|
+
|
4615
|
+
# Specifies where the images are stored.
|
4616
|
+
#
|
4617
|
+
# * +mode+ - The image storage mode. Allowed values are embed, separate.
|
4618
|
+
# * *Returns* - The converter object.
|
4619
|
+
def setImageMode(mode)
|
4620
|
+
unless /(?i)^(embed|separate)$/.match(mode)
|
4621
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setImageMode", "pdf-to-html", "Allowed values are embed, separate.", "set_image_mode"), 470);
|
4622
|
+
end
|
4623
|
+
|
4624
|
+
@fields['image_mode'] = mode
|
4625
|
+
self
|
4626
|
+
end
|
4627
|
+
|
4628
|
+
# Specifies where the style sheets are stored.
|
4629
|
+
#
|
4630
|
+
# * +mode+ - The style sheet storage mode. Allowed values are embed, separate.
|
4631
|
+
# * *Returns* - The converter object.
|
4632
|
+
def setCssMode(mode)
|
4633
|
+
unless /(?i)^(embed|separate)$/.match(mode)
|
4634
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setCssMode", "pdf-to-html", "Allowed values are embed, separate.", "set_css_mode"), 470);
|
4635
|
+
end
|
4636
|
+
|
4637
|
+
@fields['css_mode'] = mode
|
4638
|
+
self
|
4639
|
+
end
|
4640
|
+
|
4641
|
+
# Specifies where the fonts are stored.
|
4642
|
+
#
|
4643
|
+
# * +mode+ - The font storage mode. Allowed values are embed, separate.
|
4644
|
+
# * *Returns* - The converter object.
|
4645
|
+
def setFontMode(mode)
|
4646
|
+
unless /(?i)^(embed|separate)$/.match(mode)
|
4647
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setFontMode", "pdf-to-html", "Allowed values are embed, separate.", "set_font_mode"), 470);
|
4648
|
+
end
|
4649
|
+
|
4650
|
+
@fields['font_mode'] = mode
|
4651
|
+
self
|
4652
|
+
end
|
4653
|
+
|
4654
|
+
# A helper method to determine if the output file is a zip archive. The output of the conversion may be either an HTML file or a zip file containing the HTML and its external assets.
|
4655
|
+
# * *Returns* - True if the conversion output is a zip file, otherwise False.
|
4656
|
+
def isZippedOutput()
|
4657
|
+
@fields.fetch('image_mode', '') == 'separate' || @fields.fetch('css_mode', '') == 'separate' || @fields.fetch('font_mode', '') == 'separate' || @fields.fetch('force_zip', false) == true
|
4658
|
+
end
|
4659
|
+
|
4660
|
+
# Enforces the zip output format.
|
4661
|
+
#
|
4662
|
+
# * +value+ - Set to true to get the output as a zip archive.
|
4663
|
+
# * *Returns* - The converter object.
|
4664
|
+
def setForceZip(value)
|
4665
|
+
@fields['force_zip'] = value
|
4666
|
+
self
|
4667
|
+
end
|
4668
|
+
|
4669
|
+
# Set the HTML title. The title from the input PDF is used by default.
|
4670
|
+
#
|
4671
|
+
# * +title+ - The HTML title.
|
4672
|
+
# * *Returns* - The converter object.
|
4673
|
+
def setTitle(title)
|
4674
|
+
@fields['title'] = title
|
4675
|
+
self
|
4676
|
+
end
|
4677
|
+
|
4678
|
+
# Set the HTML subject. The subject from the input PDF is used by default.
|
4679
|
+
#
|
4680
|
+
# * +subject+ - The HTML subject.
|
4681
|
+
# * *Returns* - The converter object.
|
4682
|
+
def setSubject(subject)
|
4683
|
+
@fields['subject'] = subject
|
4684
|
+
self
|
4685
|
+
end
|
4686
|
+
|
4687
|
+
# Set the HTML author. The author from the input PDF is used by default.
|
4688
|
+
#
|
4689
|
+
# * +author+ - The HTML author.
|
4690
|
+
# * *Returns* - The converter object.
|
4691
|
+
def setAuthor(author)
|
4692
|
+
@fields['author'] = author
|
4693
|
+
self
|
4694
|
+
end
|
4695
|
+
|
4696
|
+
# Associate keywords with the HTML document. Keywords from the input PDF are used by default.
|
4697
|
+
#
|
4698
|
+
# * +keywords+ - The string containing the keywords.
|
4699
|
+
# * *Returns* - The converter object.
|
4700
|
+
def setKeywords(keywords)
|
4701
|
+
@fields['keywords'] = keywords
|
4702
|
+
self
|
4703
|
+
end
|
4704
|
+
|
4705
|
+
# Turn on the debug logging. Details about the conversion are stored in the debug log. The URL of the log can be obtained from the getDebugLogUrl method or available in conversion statistics.
|
4706
|
+
#
|
4707
|
+
# * +value+ - Set to true to enable the debug logging.
|
4708
|
+
# * *Returns* - The converter object.
|
4709
|
+
def setDebugLog(value)
|
4710
|
+
@fields['debug_log'] = value
|
4711
|
+
self
|
4712
|
+
end
|
4713
|
+
|
4714
|
+
# Get the URL of the debug log for the last conversion.
|
4715
|
+
# * *Returns* - The link to the debug log.
|
4716
|
+
def getDebugLogUrl()
|
4717
|
+
return @helper.getDebugLogUrl()
|
4718
|
+
end
|
4719
|
+
|
4720
|
+
# Get the number of conversion credits available in your account.
|
4721
|
+
# This method can only be called after a call to one of the convertXtoY methods.
|
4722
|
+
# The returned value can differ from the actual count if you run parallel conversions.
|
4723
|
+
# The special value 999999 is returned if the information is not available.
|
4724
|
+
# * *Returns* - The number of credits.
|
4725
|
+
def getRemainingCreditCount()
|
4726
|
+
return @helper.getRemainingCreditCount()
|
4727
|
+
end
|
4728
|
+
|
4729
|
+
# Get the number of credits consumed by the last conversion.
|
4730
|
+
# * *Returns* - The number of credits.
|
4731
|
+
def getConsumedCreditCount()
|
4732
|
+
return @helper.getConsumedCreditCount()
|
4733
|
+
end
|
4734
|
+
|
4735
|
+
# Get the job id.
|
4736
|
+
# * *Returns* - The unique job identifier.
|
4737
|
+
def getJobId()
|
4738
|
+
return @helper.getJobId()
|
4739
|
+
end
|
4740
|
+
|
4741
|
+
# Get the total number of pages in the output document.
|
4742
|
+
# * *Returns* - The page count.
|
4743
|
+
def getPageCount()
|
4744
|
+
return @helper.getPageCount()
|
4745
|
+
end
|
4746
|
+
|
4747
|
+
# Get the size of the output in bytes.
|
4748
|
+
# * *Returns* - The count of bytes.
|
4749
|
+
def getOutputSize()
|
4750
|
+
return @helper.getOutputSize()
|
4751
|
+
end
|
4752
|
+
|
4753
|
+
# Get the version details.
|
4754
|
+
# * *Returns* - API version, converter version, and client version.
|
4755
|
+
def getVersion()
|
4756
|
+
return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion()
|
4757
|
+
end
|
4758
|
+
|
4759
|
+
# Tag the conversion with a custom value. The tag is used in conversion statistics. A value longer than 32 characters is cut off.
|
4760
|
+
#
|
4761
|
+
# * +tag+ - A string with the custom tag.
|
4762
|
+
# * *Returns* - The converter object.
|
4763
|
+
def setTag(tag)
|
4764
|
+
@fields['tag'] = tag
|
4765
|
+
self
|
4766
|
+
end
|
4767
|
+
|
4768
|
+
# A proxy server used by Pdfcrowd conversion process for accessing the source URLs with HTTP scheme. It can help to circumvent regional restrictions or provide limited access to your intranet.
|
4769
|
+
#
|
4770
|
+
# * +proxy+ - The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
4771
|
+
# * *Returns* - The converter object.
|
4772
|
+
def setHttpProxy(proxy)
|
4773
|
+
unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy)
|
4774
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(proxy, "setHttpProxy", "pdf-to-html", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_http_proxy"), 470);
|
4775
|
+
end
|
4776
|
+
|
4777
|
+
@fields['http_proxy'] = proxy
|
4778
|
+
self
|
4779
|
+
end
|
4780
|
+
|
4781
|
+
# A proxy server used by Pdfcrowd conversion process for accessing the source URLs with HTTPS scheme. It can help to circumvent regional restrictions or provide limited access to your intranet.
|
4782
|
+
#
|
4783
|
+
# * +proxy+ - The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
4784
|
+
# * *Returns* - The converter object.
|
4785
|
+
def setHttpsProxy(proxy)
|
4786
|
+
unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy)
|
4787
|
+
raise Error.new(Pdfcrowd.create_invalid_value_message(proxy, "setHttpsProxy", "pdf-to-html", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470);
|
4788
|
+
end
|
4789
|
+
|
4790
|
+
@fields['https_proxy'] = proxy
|
4791
|
+
self
|
4792
|
+
end
|
4793
|
+
|
4794
|
+
# Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
|
4795
|
+
# Warning: Using HTTP is insecure as data sent over HTTP is not encrypted. Enable this option only if you know what you are doing.
|
4796
|
+
#
|
4797
|
+
# * +value+ - Set to true to use HTTP.
|
4798
|
+
# * *Returns* - The converter object.
|
4799
|
+
def setUseHttp(value)
|
4800
|
+
@helper.setUseHttp(value)
|
4801
|
+
self
|
4802
|
+
end
|
4803
|
+
|
4804
|
+
# Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
|
4339
4805
|
#
|
4340
4806
|
# * +agent+ - The user agent string.
|
4341
4807
|
# * *Returns* - The converter object.
|
@@ -4356,15 +4822,21 @@ module Pdfcrowd
|
|
4356
4822
|
self
|
4357
4823
|
end
|
4358
4824
|
|
4359
|
-
# Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
4825
|
+
# Specifies the number of automatic retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
|
4360
4826
|
#
|
4361
|
-
# * +count+ - Number of retries
|
4827
|
+
# * +count+ - Number of retries.
|
4362
4828
|
# * *Returns* - The converter object.
|
4363
4829
|
def setRetryCount(count)
|
4364
4830
|
@helper.setRetryCount(count)
|
4365
4831
|
self
|
4366
4832
|
end
|
4367
4833
|
|
4834
|
+
private
|
4835
|
+
|
4836
|
+
def isOutputTypeValid(file_path)
|
4837
|
+
extension = File.extname(file_path).downcase
|
4838
|
+
(extension == '.zip') == isZippedOutput()
|
4839
|
+
end
|
4368
4840
|
end
|
4369
4841
|
|
4370
4842
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfcrowd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pdfcrowd Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The Pdfcrowd API lets you easily convert between HTML, PDF and various
|
14
14
|
image formats.
|