Class: Pdfcrowd::PdfToHtmlClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfcrowd.rb

Overview

Conversion from PDF to HTML.

Instance Method Summary collapse

Constructor Details

#initialize(user_name, api_key) ⇒ PdfToHtmlClient

Returns a new instance of PdfToHtmlClient.



4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
# File 'lib/pdfcrowd.rb', line 4288

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



4341
4342
4343
4344
4345
4346
4347
4348
# File 'lib/pdfcrowd.rb', line 4341

def convertFile(file)
    if (!(File.file?(file) && !File.zero?(file)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
# File 'lib/pdfcrowd.rb', line 4361

def convertFileToFile(file, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        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);
    end
    
    if (!(isOutputTypeValid(file_path)))
        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);
    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



4351
4352
4353
4354
4355
4356
4357
4358
# File 'lib/pdfcrowd.rb', line 4351

def convertFileToStream(file, out_stream)
    if (!(File.file?(file) && !File.zero?(file)))
        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);
    end
    
    @files['file'] = file
    @helper.post(@fields, @files, @raw_data, out_stream)
end

#convertRawData(data) ⇒ Object



4382
4383
4384
4385
# File 'lib/pdfcrowd.rb', line 4382

def convertRawData(data)
    @raw_data['file'] = data
    @helper.post(@fields, @files, @raw_data)
end

#convertRawDataToFile(data, file_path) ⇒ Object



4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
# File 'lib/pdfcrowd.rb', line 4394

def convertRawDataToFile(data, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        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);
    end
    
    if (!(isOutputTypeValid(file_path)))
        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);
    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



4388
4389
4390
4391
# File 'lib/pdfcrowd.rb', line 4388

def convertRawDataToStream(data, out_stream)
    @raw_data['file'] = data
    @helper.post(@fields, @files, @raw_data, out_stream)
end

#convertStream(in_stream) ⇒ Object



4415
4416
4417
4418
# File 'lib/pdfcrowd.rb', line 4415

def convertStream(in_stream)
    @raw_data['stream'] = in_stream.read
    @helper.post(@fields, @files, @raw_data)
end

#convertStreamToFile(in_stream, file_path) ⇒ Object



4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
# File 'lib/pdfcrowd.rb', line 4427

def convertStreamToFile(in_stream, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        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);
    end
    
    if (!(isOutputTypeValid(file_path)))
        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);
    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



4421
4422
4423
4424
# File 'lib/pdfcrowd.rb', line 4421

def convertStreamToStream(in_stream, out_stream)
    @raw_data['stream'] = in_stream.read
    @helper.post(@fields, @files, @raw_data, out_stream)
end

#convertUrl(url) ⇒ Object



4300
4301
4302
4303
4304
4305
4306
4307
# File 'lib/pdfcrowd.rb', line 4300

def convertUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
# File 'lib/pdfcrowd.rb', line 4320

def convertUrlToFile(url, file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        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);
    end
    
    if (!(isOutputTypeValid(file_path)))
        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);
    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



4310
4311
4312
4313
4314
4315
4316
4317
# File 'lib/pdfcrowd.rb', line 4310

def convertUrlToStream(url, out_stream)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(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

#getConsumedCreditCountObject



4607
4608
4609
# File 'lib/pdfcrowd.rb', line 4607

def getConsumedCreditCount()
    return @helper.getConsumedCreditCount()
end

#getDebugLogUrlObject



4597
4598
4599
# File 'lib/pdfcrowd.rb', line 4597

def getDebugLogUrl()
    return @helper.getDebugLogUrl()
end

#getJobIdObject



4612
4613
4614
# File 'lib/pdfcrowd.rb', line 4612

def getJobId()
    return @helper.getJobId()
end

#getOutputSizeObject



4622
4623
4624
# File 'lib/pdfcrowd.rb', line 4622

def getOutputSize()
    return @helper.getOutputSize()
end

#getPageCountObject



4617
4618
4619
# File 'lib/pdfcrowd.rb', line 4617

def getPageCount()
    return @helper.getPageCount()
end

#getRemainingCreditCountObject



4602
4603
4604
# File 'lib/pdfcrowd.rb', line 4602

def getRemainingCreditCount()
    return @helper.getRemainingCreditCount()
end

#getVersionObject



4627
4628
4629
# File 'lib/pdfcrowd.rb', line 4627

def getVersion()
    return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion()
end

#isZippedOutputObject



4556
4557
4558
# File 'lib/pdfcrowd.rb', line 4556

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



4579
4580
4581
4582
# File 'lib/pdfcrowd.rb', line 4579

def setAuthor(author)
    @fields['author'] = author
    self
end

#setClientUserAgent(agent) ⇒ Object



4674
4675
4676
4677
# File 'lib/pdfcrowd.rb', line 4674

def setClientUserAgent(agent)
    @helper.setUserAgent(agent)
    self
end

#setConverterVersion(version) ⇒ Object



4658
4659
4660
4661
4662
4663
4664
4665
# File 'lib/pdfcrowd.rb', line 4658

def setConverterVersion(version)
    unless /(?i)^(24.04|20.10|18.10|latest)$/.match(version)
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4500
4501
4502
4503
4504
4505
4506
4507
# File 'lib/pdfcrowd.rb', line 4500

def setCssMode(mode)
    unless /(?i)^(embed|separate)$/.match(mode)
        raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setCssMode", "pdf-to-html", "Allowed values are embed, separate.", "set_css_mode"), 470);
    end
    
    @fields['css_mode'] = mode
    self
end

#setCustomCss(css) ⇒ Object



4536
4537
4538
4539
4540
4541
4542
4543
# File 'lib/pdfcrowd.rb', line 4536

def setCustomCss(css)
    if (!(!css.nil? && !css.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4591
4592
4593
4594
# File 'lib/pdfcrowd.rb', line 4591

def setDebugLog(value)
    @fields['debug_log'] = value
    self
end

#setDpi(dpi) ⇒ Object



4474
4475
4476
4477
# File 'lib/pdfcrowd.rb', line 4474

def setDpi(dpi)
    @fields['dpi'] = dpi
    self
end

#setFontMode(mode) ⇒ Object



4510
4511
4512
4513
4514
4515
4516
4517
# File 'lib/pdfcrowd.rb', line 4510

def setFontMode(mode)
    unless /(?i)^(embed|separate)$/.match(mode)
        raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setFontMode", "pdf-to-html", "Allowed values are embed, separate.", "set_font_mode"), 470);
    end
    
    @fields['font_mode'] = mode
    self
end

#setForceZip(value) ⇒ Object



4561
4562
4563
4564
# File 'lib/pdfcrowd.rb', line 4561

def setForceZip(value)
    @fields['force_zip'] = value
    self
end

#setHtmlNamespace(prefix) ⇒ Object



4546
4547
4548
4549
4550
4551
4552
4553
# File 'lib/pdfcrowd.rb', line 4546

def setHtmlNamespace(prefix)
    unless /(?i)^[a-z_][a-z0-9_:-]*$/.match(prefix)
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4638
4639
4640
4641
4642
4643
4644
4645
# File 'lib/pdfcrowd.rb', line 4638

def setHttpProxy(proxy)
    unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy)
        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);
    end
    
    @fields['http_proxy'] = proxy
    self
end

#setHttpsProxy(proxy) ⇒ Object



4648
4649
4650
4651
4652
4653
4654
4655
# File 'lib/pdfcrowd.rb', line 4648

def setHttpsProxy(proxy)
    unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy)
        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);
    end
    
    @fields['https_proxy'] = proxy
    self
end

#setImageFormat(image_format) ⇒ Object



4490
4491
4492
4493
4494
4495
4496
4497
# File 'lib/pdfcrowd.rb', line 4490

def setImageFormat(image_format)
    unless /(?i)^(png|jpg|svg)$/.match(image_format)
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4480
4481
4482
4483
4484
4485
4486
4487
# File 'lib/pdfcrowd.rb', line 4480

def setImageMode(mode)
    unless /(?i)^(embed|separate|none)$/.match(mode)
        raise Error.new(Pdfcrowd.create_invalid_value_message(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



4585
4586
4587
4588
# File 'lib/pdfcrowd.rb', line 4585

def setKeywords(keywords)
    @fields['keywords'] = keywords
    self
end

#setPdfPassword(password) ⇒ Object



4448
4449
4450
4451
# File 'lib/pdfcrowd.rb', line 4448

def setPdfPassword(password)
    @fields['pdf_password'] = password
    self
end

#setPrintPageRange(pages) ⇒ Object



4464
4465
4466
4467
4468
4469
4470
4471
# File 'lib/pdfcrowd.rb', line 4464

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.create_invalid_value_message(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



4686
4687
4688
4689
# File 'lib/pdfcrowd.rb', line 4686

def setProxy(host, port, user_name, password)
    @helper.setProxy(host, port, user_name, password)
    self
end

#setRetryCount(count) ⇒ Object



4692
4693
4694
4695
# File 'lib/pdfcrowd.rb', line 4692

def setRetryCount(count)
    @helper.setRetryCount(count)
    self
end

#setScaleFactor(factor) ⇒ Object



4454
4455
4456
4457
4458
4459
4460
4461
# File 'lib/pdfcrowd.rb', line 4454

def setScaleFactor(factor)
    if (!(Integer(factor) > 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(factor, "setScaleFactor", "pdf-to-html", "Must be a positive integer.", "set_scale_factor"), 470);
    end
    
    @fields['scale_factor'] = factor
    self
end

#setSplitLigatures(value) ⇒ Object



4530
4531
4532
4533
# File 'lib/pdfcrowd.rb', line 4530

def setSplitLigatures(value)
    @fields['split_ligatures'] = value
    self
end

#setSubject(subject) ⇒ Object



4573
4574
4575
4576
# File 'lib/pdfcrowd.rb', line 4573

def setSubject(subject)
    @fields['subject'] = subject
    self
end

#setTag(tag) ⇒ Object



4632
4633
4634
4635
# File 'lib/pdfcrowd.rb', line 4632

def setTag(tag)
    @fields['tag'] = tag
    self
end

#setTitle(title) ⇒ Object



4567
4568
4569
4570
# File 'lib/pdfcrowd.rb', line 4567

def setTitle(title)
    @fields['title'] = title
    self
end

#setType3Mode(mode) ⇒ Object



4520
4521
4522
4523
4524
4525
4526
4527
# File 'lib/pdfcrowd.rb', line 4520

def setType3Mode(mode)
    unless /(?i)^(raster|convert)$/.match(mode)
        raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setType3Mode", "pdf-to-html", "Allowed values are raster, convert.", "set_type3_mode"), 470);
    end
    
    @fields['type3_mode'] = mode
    self
end

#setUseHttp(value) ⇒ Object



4668
4669
4670
4671
# File 'lib/pdfcrowd.rb', line 4668

def setUseHttp(value)
    @helper.setUseHttp(value)
    self
end

#setUserAgent(agent) ⇒ Object



4680
4681
4682
4683
# File 'lib/pdfcrowd.rb', line 4680

def setUserAgent(agent)
    @helper.setUserAgent(agent)
    self
end