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.
4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 |
# File 'lib/pdfcrowd.rb', line 4337 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
4390 4391 4392 4393 4394 4395 4396 4397 |
# File 'lib/pdfcrowd.rb', line 4390 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
4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 |
# File 'lib/pdfcrowd.rb', line 4410 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
4400 4401 4402 4403 4404 4405 4406 4407 |
# File 'lib/pdfcrowd.rb', line 4400 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
4431 4432 4433 4434 |
# File 'lib/pdfcrowd.rb', line 4431 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 |
# File 'lib/pdfcrowd.rb', line 4443 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
4437 4438 4439 4440 |
# File 'lib/pdfcrowd.rb', line 4437 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
4464 4465 4466 4467 |
# File 'lib/pdfcrowd.rb', line 4464 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 |
# File 'lib/pdfcrowd.rb', line 4476 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
4470 4471 4472 4473 |
# File 'lib/pdfcrowd.rb', line 4470 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
4349 4350 4351 4352 4353 4354 4355 4356 |
# File 'lib/pdfcrowd.rb', line 4349 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
4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 |
# File 'lib/pdfcrowd.rb', line 4369 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
4359 4360 4361 4362 4363 4364 4365 4366 |
# File 'lib/pdfcrowd.rb', line 4359 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
4656 4657 4658 |
# File 'lib/pdfcrowd.rb', line 4656 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
4646 4647 4648 |
# File 'lib/pdfcrowd.rb', line 4646 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
4661 4662 4663 |
# File 'lib/pdfcrowd.rb', line 4661 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
4671 4672 4673 |
# File 'lib/pdfcrowd.rb', line 4671 def getOutputSize() return @helper.getOutputSize() end |
#getPageCount ⇒ Object
4666 4667 4668 |
# File 'lib/pdfcrowd.rb', line 4666 def getPageCount() return @helper.getPageCount() end |
#getRemainingCreditCount ⇒ Object
4651 4652 4653 |
# File 'lib/pdfcrowd.rb', line 4651 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
4676 4677 4678 |
# File 'lib/pdfcrowd.rb', line 4676 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#isZippedOutput ⇒ Object
4605 4606 4607 |
# File 'lib/pdfcrowd.rb', line 4605 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
4628 4629 4630 4631 |
# File 'lib/pdfcrowd.rb', line 4628 def setAuthor() @fields['author'] = self end |
#setClientUserAgent(agent) ⇒ Object
4723 4724 4725 4726 |
# File 'lib/pdfcrowd.rb', line 4723 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setConverterVersion(version) ⇒ Object
4707 4708 4709 4710 4711 4712 4713 4714 |
# File 'lib/pdfcrowd.rb', line 4707 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
4549 4550 4551 4552 4553 4554 4555 4556 |
# File 'lib/pdfcrowd.rb', line 4549 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
4585 4586 4587 4588 4589 4590 4591 4592 |
# File 'lib/pdfcrowd.rb', line 4585 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
4640 4641 4642 4643 |
# File 'lib/pdfcrowd.rb', line 4640 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
4523 4524 4525 4526 |
# File 'lib/pdfcrowd.rb', line 4523 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setFontMode(mode) ⇒ Object
4559 4560 4561 4562 4563 4564 4565 4566 |
# File 'lib/pdfcrowd.rb', line 4559 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
4610 4611 4612 4613 |
# File 'lib/pdfcrowd.rb', line 4610 def setForceZip(value) @fields['force_zip'] = value self end |
#setHtmlNamespace(prefix) ⇒ Object
4595 4596 4597 4598 4599 4600 4601 4602 |
# File 'lib/pdfcrowd.rb', line 4595 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
4687 4688 4689 4690 4691 4692 4693 4694 |
# File 'lib/pdfcrowd.rb', line 4687 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
4697 4698 4699 4700 4701 4702 4703 4704 |
# File 'lib/pdfcrowd.rb', line 4697 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
4539 4540 4541 4542 4543 4544 4545 4546 |
# File 'lib/pdfcrowd.rb', line 4539 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
4529 4530 4531 4532 4533 4534 4535 4536 |
# File 'lib/pdfcrowd.rb', line 4529 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
4634 4635 4636 4637 |
# File 'lib/pdfcrowd.rb', line 4634 def setKeywords(keywords) @fields['keywords'] = keywords self end |
#setPdfPassword(password) ⇒ Object
4497 4498 4499 4500 |
# File 'lib/pdfcrowd.rb', line 4497 def setPdfPassword(password) @fields['pdf_password'] = password self end |
#setPrintPageRange(pages) ⇒ Object
4513 4514 4515 4516 4517 4518 4519 4520 |
# File 'lib/pdfcrowd.rb', line 4513 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
4735 4736 4737 4738 |
# File 'lib/pdfcrowd.rb', line 4735 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRetryCount(count) ⇒ Object
4741 4742 4743 4744 |
# File 'lib/pdfcrowd.rb', line 4741 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setScaleFactor(factor) ⇒ Object
4503 4504 4505 4506 4507 4508 4509 4510 |
# File 'lib/pdfcrowd.rb', line 4503 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
4579 4580 4581 4582 |
# File 'lib/pdfcrowd.rb', line 4579 def setSplitLigatures(value) @fields['split_ligatures'] = value self end |
#setSubject(subject) ⇒ Object
4622 4623 4624 4625 |
# File 'lib/pdfcrowd.rb', line 4622 def setSubject(subject) @fields['subject'] = subject self end |
#setTag(tag) ⇒ Object
4681 4682 4683 4684 |
# File 'lib/pdfcrowd.rb', line 4681 def setTag(tag) @fields['tag'] = tag self end |
#setTitle(title) ⇒ Object
4616 4617 4618 4619 |
# File 'lib/pdfcrowd.rb', line 4616 def setTitle(title) @fields['title'] = title self end |
#setType3Mode(mode) ⇒ Object
4569 4570 4571 4572 4573 4574 4575 4576 |
# File 'lib/pdfcrowd.rb', line 4569 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
4717 4718 4719 4720 |
# File 'lib/pdfcrowd.rb', line 4717 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
4729 4730 4731 4732 |
# File 'lib/pdfcrowd.rb', line 4729 def setUserAgent(agent) @helper.setUserAgent(agent) self end |