Class: Pdfcrowd::PdfToHtmlClient
- Inherits:
-
Object
- Object
- Pdfcrowd::PdfToHtmlClient
- Defined in:
- lib/pdfcrowd.rb
Overview
Conversion from PDF to HTML.
Instance Method Summary collapse
- #convertFile(file) ⇒ Object
- #convertFileToFile(file, file_path) ⇒ Object
- #convertFileToStream(file, out_stream) ⇒ Object
- #convertRawData(data) ⇒ Object
- #convertRawDataToFile(data, file_path) ⇒ Object
- #convertRawDataToStream(data, out_stream) ⇒ Object
- #convertStream(in_stream) ⇒ Object
- #convertStreamToFile(in_stream, file_path) ⇒ Object
- #convertStreamToStream(in_stream, out_stream) ⇒ Object
- #convertUrl(url) ⇒ Object
- #convertUrlToFile(url, file_path) ⇒ Object
- #convertUrlToStream(url, out_stream) ⇒ Object
- #getConsumedCreditCount ⇒ Object
- #getDebugLogUrl ⇒ Object
- #getJobId ⇒ Object
- #getOutputSize ⇒ Object
- #getPageCount ⇒ Object
- #getRemainingCreditCount ⇒ Object
- #getVersion ⇒ Object
-
#initialize(user_name, api_key) ⇒ PdfToHtmlClient
constructor
A new instance of PdfToHtmlClient.
- #isZippedOutput ⇒ Object
- #setAuthor(author) ⇒ Object
- #setClientUserAgent(agent) ⇒ Object
- #setConverterVersion(version) ⇒ Object
- #setCssMode(mode) ⇒ Object
- #setCustomCss(css) ⇒ Object
- #setDebugLog(value) ⇒ Object
- #setDpi(dpi) ⇒ Object
- #setFontMode(mode) ⇒ Object
- #setForceZip(value) ⇒ Object
- #setHtmlNamespace(prefix) ⇒ Object
- #setHttpProxy(proxy) ⇒ Object
- #setHttpsProxy(proxy) ⇒ Object
- #setImageFormat(image_format) ⇒ Object
- #setImageMode(mode) ⇒ Object
- #setKeywords(keywords) ⇒ Object
- #setPdfPassword(password) ⇒ Object
- #setPrintPageRange(pages) ⇒ Object
- #setProxy(host, port, user_name, password) ⇒ Object
- #setRetryCount(count) ⇒ Object
- #setScaleFactor(factor) ⇒ Object
- #setSplitLigatures(value) ⇒ Object
- #setSubject(subject) ⇒ Object
- #setTag(tag) ⇒ Object
- #setTitle(title) ⇒ Object
- #setType3Mode(mode) ⇒ Object
- #setUseHttp(value) ⇒ Object
- #setUserAgent(agent) ⇒ Object
Constructor Details
#initialize(user_name, api_key) ⇒ PdfToHtmlClient
Returns a new instance of PdfToHtmlClient.
4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 |
# File 'lib/pdfcrowd.rb', line 4268 def initialize(user_name, api_key) @helper = ConnectionHelper.new(user_name, api_key) @fields = { 'input_format'=>'pdf', 'output_format'=>'html' } @file_id = 1 @files = {} @raw_data = {} end |
Instance Method Details
#convertFile(file) ⇒ Object
4321 4322 4323 4324 4325 4326 4327 4328 |
# File 'lib/pdfcrowd.rb', line 4321 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "convertFile", "pdf-to-html", "The file must exist and not be empty.", "convert_file"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data) end |
#convertFileToFile(file, file_path) ⇒ Object
4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 |
# File 'lib/pdfcrowd.rb', line 4341 def convertFileToFile(file, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertFileToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_file_to_file"), 470); end if (!(isOutputTypeValid(file_path))) raise Error.new(Pdfcrowd.(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); end output_file = open(file_path, "wb") begin convertFileToStream(file, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertFileToStream(file, out_stream) ⇒ Object
4331 4332 4333 4334 4335 4336 4337 4338 |
# File 'lib/pdfcrowd.rb', line 4331 def convertFileToStream(file, out_stream) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "convertFileToStream::file", "pdf-to-html", "The file must exist and not be empty.", "convert_file_to_stream"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertRawData(data) ⇒ Object
4362 4363 4364 4365 |
# File 'lib/pdfcrowd.rb', line 4362 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 |
# File 'lib/pdfcrowd.rb', line 4374 def convertRawDataToFile(data, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertRawDataToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_raw_data_to_file"), 470); end if (!(isOutputTypeValid(file_path))) raise Error.new(Pdfcrowd.(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); end output_file = open(file_path, "wb") begin convertRawDataToStream(data, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertRawDataToStream(data, out_stream) ⇒ Object
4368 4369 4370 4371 |
# File 'lib/pdfcrowd.rb', line 4368 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
4395 4396 4397 4398 |
# File 'lib/pdfcrowd.rb', line 4395 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 |
# File 'lib/pdfcrowd.rb', line 4407 def convertStreamToFile(in_stream, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertStreamToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_stream_to_file"), 470); end if (!(isOutputTypeValid(file_path))) raise Error.new(Pdfcrowd.(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); end output_file = open(file_path, "wb") begin convertStreamToStream(in_stream, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertStreamToStream(in_stream, out_stream) ⇒ Object
4401 4402 4403 4404 |
# File 'lib/pdfcrowd.rb', line 4401 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
4280 4281 4282 4283 4284 4285 4286 4287 |
# File 'lib/pdfcrowd.rb', line 4280 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrl", "pdf-to-html", "Supported protocols are http:// and https://.", "convert_url"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data) end |
#convertUrlToFile(url, file_path) ⇒ Object
4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 |
# File 'lib/pdfcrowd.rb', line 4300 def convertUrlToFile(url, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertUrlToFile::file_path", "pdf-to-html", "The string must not be empty.", "convert_url_to_file"), 470); end if (!(isOutputTypeValid(file_path))) raise Error.new(Pdfcrowd.(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); end output_file = open(file_path, "wb") begin convertUrlToStream(url, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertUrlToStream(url, out_stream) ⇒ Object
4290 4291 4292 4293 4294 4295 4296 4297 |
# File 'lib/pdfcrowd.rb', line 4290 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrlToStream::url", "pdf-to-html", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data, out_stream) end |
#getConsumedCreditCount ⇒ Object
4587 4588 4589 |
# File 'lib/pdfcrowd.rb', line 4587 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
4577 4578 4579 |
# File 'lib/pdfcrowd.rb', line 4577 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
4592 4593 4594 |
# File 'lib/pdfcrowd.rb', line 4592 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
4602 4603 4604 |
# File 'lib/pdfcrowd.rb', line 4602 def getOutputSize() return @helper.getOutputSize() end |
#getPageCount ⇒ Object
4597 4598 4599 |
# File 'lib/pdfcrowd.rb', line 4597 def getPageCount() return @helper.getPageCount() end |
#getRemainingCreditCount ⇒ Object
4582 4583 4584 |
# File 'lib/pdfcrowd.rb', line 4582 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
4607 4608 4609 |
# File 'lib/pdfcrowd.rb', line 4607 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#isZippedOutput ⇒ Object
4536 4537 4538 |
# File 'lib/pdfcrowd.rb', line 4536 def isZippedOutput() @fields.fetch('image_mode', '') == 'separate' || @fields.fetch('css_mode', '') == 'separate' || @fields.fetch('font_mode', '') == 'separate' || @fields.fetch('force_zip', false) == true end |
#setAuthor(author) ⇒ Object
4559 4560 4561 4562 |
# File 'lib/pdfcrowd.rb', line 4559 def setAuthor() @fields['author'] = self end |
#setClientUserAgent(agent) ⇒ Object
4654 4655 4656 4657 |
# File 'lib/pdfcrowd.rb', line 4654 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setConverterVersion(version) ⇒ Object
4638 4639 4640 4641 4642 4643 4644 4645 |
# File 'lib/pdfcrowd.rb', line 4638 def setConverterVersion(version) unless /(?i)^(24.04|20.10|18.10|latest)$/.match(version) raise Error.new(Pdfcrowd.(version, "setConverterVersion", "pdf-to-html", "Allowed values are 24.04, 20.10, 18.10, latest.", "set_converter_version"), 470); end @helper.setConverterVersion(version) self end |
#setCssMode(mode) ⇒ Object
4480 4481 4482 4483 4484 4485 4486 4487 |
# File 'lib/pdfcrowd.rb', line 4480 def setCssMode(mode) unless /(?i)^(embed|separate)$/.match(mode) raise Error.new(Pdfcrowd.(mode, "setCssMode", "pdf-to-html", "Allowed values are embed, separate.", "set_css_mode"), 470); end @fields['css_mode'] = mode self end |
#setCustomCss(css) ⇒ Object
4516 4517 4518 4519 4520 4521 4522 4523 |
# File 'lib/pdfcrowd.rb', line 4516 def setCustomCss(css) if (!(!css.nil? && !css.empty?)) raise Error.new(Pdfcrowd.(css, "setCustomCss", "pdf-to-html", "The string must not be empty.", "set_custom_css"), 470); end @fields['custom_css'] = css self end |
#setDebugLog(value) ⇒ Object
4571 4572 4573 4574 |
# File 'lib/pdfcrowd.rb', line 4571 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
4454 4455 4456 4457 |
# File 'lib/pdfcrowd.rb', line 4454 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setFontMode(mode) ⇒ Object
4490 4491 4492 4493 4494 4495 4496 4497 |
# File 'lib/pdfcrowd.rb', line 4490 def setFontMode(mode) unless /(?i)^(embed|separate)$/.match(mode) raise Error.new(Pdfcrowd.(mode, "setFontMode", "pdf-to-html", "Allowed values are embed, separate.", "set_font_mode"), 470); end @fields['font_mode'] = mode self end |
#setForceZip(value) ⇒ Object
4541 4542 4543 4544 |
# File 'lib/pdfcrowd.rb', line 4541 def setForceZip(value) @fields['force_zip'] = value self end |
#setHtmlNamespace(prefix) ⇒ Object
4526 4527 4528 4529 4530 4531 4532 4533 |
# File 'lib/pdfcrowd.rb', line 4526 def setHtmlNamespace(prefix) unless /(?i)^[a-z_][a-z0-9_:-]*$/.match(prefix) raise Error.new(Pdfcrowd.(prefix, "setHtmlNamespace", "pdf-to-html", "Start with a letter or underscore, and use only letters, numbers, hyphens, underscores, or colons.", "set_html_namespace"), 470); end @fields['html_namespace'] = prefix self end |
#setHttpProxy(proxy) ⇒ Object
4618 4619 4620 4621 4622 4623 4624 4625 |
# File 'lib/pdfcrowd.rb', line 4618 def setHttpProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(proxy, "setHttpProxy", "pdf-to-html", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_http_proxy"), 470); end @fields['http_proxy'] = proxy self end |
#setHttpsProxy(proxy) ⇒ Object
4628 4629 4630 4631 4632 4633 4634 4635 |
# File 'lib/pdfcrowd.rb', line 4628 def setHttpsProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(proxy, "setHttpsProxy", "pdf-to-html", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470); end @fields['https_proxy'] = proxy self end |
#setImageFormat(image_format) ⇒ Object
4470 4471 4472 4473 4474 4475 4476 4477 |
# File 'lib/pdfcrowd.rb', line 4470 def setImageFormat(image_format) unless /(?i)^(png|jpg|svg)$/.match(image_format) raise Error.new(Pdfcrowd.(image_format, "setImageFormat", "pdf-to-html", "Allowed values are png, jpg, svg.", "set_image_format"), 470); end @fields['image_format'] = image_format self end |
#setImageMode(mode) ⇒ Object
4460 4461 4462 4463 4464 4465 4466 4467 |
# File 'lib/pdfcrowd.rb', line 4460 def setImageMode(mode) unless /(?i)^(embed|separate|none)$/.match(mode) raise Error.new(Pdfcrowd.(mode, "setImageMode", "pdf-to-html", "Allowed values are embed, separate, none.", "set_image_mode"), 470); end @fields['image_mode'] = mode self end |
#setKeywords(keywords) ⇒ Object
4565 4566 4567 4568 |
# File 'lib/pdfcrowd.rb', line 4565 def setKeywords(keywords) @fields['keywords'] = keywords self end |
#setPdfPassword(password) ⇒ Object
4428 4429 4430 4431 |
# File 'lib/pdfcrowd.rb', line 4428 def setPdfPassword(password) @fields['pdf_password'] = password self end |
#setPrintPageRange(pages) ⇒ Object
4444 4445 4446 4447 4448 4449 4450 4451 |
# File 'lib/pdfcrowd.rb', line 4444 def setPrintPageRange(pages) 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) raise Error.new(Pdfcrowd.(pages, "setPrintPageRange", "pdf-to-html", "A comma separated list of page numbers or ranges.", "set_print_page_range"), 470); end @fields['print_page_range'] = pages self end |
#setProxy(host, port, user_name, password) ⇒ Object
4666 4667 4668 4669 |
# File 'lib/pdfcrowd.rb', line 4666 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRetryCount(count) ⇒ Object
4672 4673 4674 4675 |
# File 'lib/pdfcrowd.rb', line 4672 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setScaleFactor(factor) ⇒ Object
4434 4435 4436 4437 4438 4439 4440 4441 |
# File 'lib/pdfcrowd.rb', line 4434 def setScaleFactor(factor) if (!(Integer(factor) > 0)) raise Error.new(Pdfcrowd.(factor, "setScaleFactor", "pdf-to-html", "Must be a positive integer.", "set_scale_factor"), 470); end @fields['scale_factor'] = factor self end |
#setSplitLigatures(value) ⇒ Object
4510 4511 4512 4513 |
# File 'lib/pdfcrowd.rb', line 4510 def setSplitLigatures(value) @fields['split_ligatures'] = value self end |
#setSubject(subject) ⇒ Object
4553 4554 4555 4556 |
# File 'lib/pdfcrowd.rb', line 4553 def setSubject(subject) @fields['subject'] = subject self end |
#setTag(tag) ⇒ Object
4612 4613 4614 4615 |
# File 'lib/pdfcrowd.rb', line 4612 def setTag(tag) @fields['tag'] = tag self end |
#setTitle(title) ⇒ Object
4547 4548 4549 4550 |
# File 'lib/pdfcrowd.rb', line 4547 def setTitle(title) @fields['title'] = title self end |
#setType3Mode(mode) ⇒ Object
4500 4501 4502 4503 4504 4505 4506 4507 |
# File 'lib/pdfcrowd.rb', line 4500 def setType3Mode(mode) unless /(?i)^(raster|convert)$/.match(mode) raise Error.new(Pdfcrowd.(mode, "setType3Mode", "pdf-to-html", "Allowed values are raster, convert.", "set_type3_mode"), 470); end @fields['type3_mode'] = mode self end |
#setUseHttp(value) ⇒ Object
4648 4649 4650 4651 |
# File 'lib/pdfcrowd.rb', line 4648 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
4660 4661 4662 4663 |
# File 'lib/pdfcrowd.rb', line 4660 def setUserAgent(agent) @helper.setUserAgent(agent) self end |