pdfcrowd 2.6.0 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -7
  2. data/lib/pdfcrowd.rb +1965 -11
  3. metadata +25 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- data.tar.gz: 7273f00210d5954933b55a053089da87e919f572
4
- metadata.gz: 85f6f74653149b6570ec41e5b51192507af27ad0
5
- SHA512:
6
- data.tar.gz: 2652b886f3ffb82e823969b3166f50fa348f842d8bbb5974ebe9c0e1e82012c6b3f1e9578163852be26ce5a04c00dc718defbeb74ca69d703487782e1c68e9d6
7
- metadata.gz: bfbedc0ddeeadd6a463b7bdc086e5424360c2d5d05fb4e227bd4346c4959bb7ab17fe0be3ce3fe3b08d84a8ab6211944adcf0850c23264cb120e3e8b9735be9b
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d7fd03a483ab60b722a2878ea0667838d5b12ab
4
+ data.tar.gz: f8689da21d07ad695fa0ad7cf0231c687348324c
5
+ SHA512:
6
+ metadata.gz: 1520b0395cbc545cd9b09fd345283273ad94329601178efb56fa59c15e9d8661035e4687585a3f30e2ce8daf3f09f8bfa8751d905ad29ec82fcb26a7c271ed8a
7
+ data.tar.gz: 5afa89ed4450d9a064b78ab9d60fce0643041304c2ab40d1a4af35efab111d6bf87b497de294f20557aeccf245990ac9c4e4b2ecc9f33f8139ff9a53bb8185a1
@@ -1,5 +1,5 @@
1
- # Copyright (C) 2009-2013 pdfcrowd.com
2
- #
1
+ # Copyright (C) 2009-2016 pdfcrowd.com
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person
4
4
  # obtaining a copy of this software and associated documentation
5
5
  # files (the "Software"), to deal in the Software without
@@ -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
@@ -24,6 +24,9 @@
24
24
  require 'net/http'
25
25
  require 'cgi'
26
26
 
27
+ # ======================================
28
+ # === PDFCrowd legacy version client ===
29
+ # ======================================
27
30
 
28
31
  module Pdfcrowd
29
32
  # constants for setPageLayout()
@@ -45,13 +48,20 @@ module Pdfcrowd
45
48
  def initialize(error, http_code=nil)
46
49
  super()
47
50
  @http_code = http_code
48
- @error = error
51
+ @error = error
49
52
  end
50
53
 
51
54
  def to_s()
52
-
53
55
  @http_code ? "#{@http_code} - #{@error}" : @error
54
56
  end
57
+
58
+ def getCode()
59
+ @http_code
60
+ end
61
+
62
+ def getMessage()
63
+ @error
64
+ end
55
65
  end
56
66
 
57
67
 
@@ -429,7 +439,9 @@ if __FILE__ == $0
429
439
 
430
440
  some_html="<html><body>Uploaded content!</body></html>"
431
441
  Dir.chdir(File.dirname($0))
432
- $test_dir = '../test_files'
442
+ $test_dir = '/tmp/legacy'
443
+ $in_dir = File.expand_path('../../../../../../tests/input/', File.dirname(__FILE__))
444
+
433
445
 
434
446
  def out_stream(name, use_ssl)
435
447
  fname = $test_dir + "/out/rb_client_#{name}"
@@ -444,10 +456,10 @@ if __FILE__ == $0
444
456
  client.useSSL(use_ssl)
445
457
  begin
446
458
  ntokens = client.numTokens()
447
- client.convertURI('http://www.web-to-pdf.com', out_stream('uri', use_ssl))
459
+ client.convertURI('https://storage.googleapis.com/pdfcrowd-legacy-tests/tests/webtopdfcom.html', out_stream('uri', use_ssl))
448
460
  client.convertHtml(some_html, out_stream('content', use_ssl))
449
- client.convertFile("#{$test_dir}/in/simple.html", out_stream('upload', use_ssl))
450
- client.convertFile("#{$test_dir}/in/archive.tar.gz", out_stream('archive', use_ssl))
461
+ client.convertFile("#{$in_dir}/hello_world.html", out_stream('upload', use_ssl))
462
+ client.convertFile("#{$in_dir}/hello_world.tar.gz", out_stream('archive', use_ssl))
451
463
  after_tokens = client.numTokens()
452
464
  if ntokens-4 != after_tokens
453
465
  raise RuntimeError, 'got unexpected number of tokens'
@@ -495,7 +507,7 @@ if __FILE__ == $0
495
507
  client = Pdfcrowd::Client.new(ARGV[0], ARGV[1])
496
508
  client.setVerticalMargin("1in")
497
509
  client.send(method, arg)
498
- client.convertFile("#{$test_dir}/in/simple.html", out_stream(method.id2name.downcase(), false))
510
+ client.convertFile("#{$in_dir}/hello_world.html", out_stream(method.id2name.downcase(), false))
499
511
  end
500
512
  rescue Pdfcrowd::Error => why
501
513
  print 'FAILED: ', why
@@ -509,3 +521,1945 @@ if __FILE__ == $0
509
521
 
510
522
 
511
523
  end
524
+
525
+ # =====================================
526
+ # === PDFCrowd cloud version client ===
527
+ # =====================================
528
+
529
+ module Pdfcrowd
530
+ HOST = ENV["PDFCROWD_HOST"] || 'api.pdfcrowd.com'
531
+ MULTIPART_BOUNDARY = '----------ThIs_Is_tHe_bOUnDary_$'
532
+ CLIENT_VERSION = '4.0'
533
+
534
+ def self.float_to_string(value)
535
+ value.to_s.sub(',', '.')
536
+ end
537
+
538
+ class ConnectionHelper
539
+ def initialize(user_name, api_key)
540
+ @user_name = user_name
541
+ @api_key = api_key
542
+
543
+ reset_response_data()
544
+
545
+ setProxy(nil, nil, nil, nil)
546
+ setUseHttp(false)
547
+ setUserAgent('pdfcrowd_ruby_client/4.0 (http://pdfcrowd.com)')
548
+ end
549
+
550
+ def post(fields, files, raw_data, out_stream = nil)
551
+ return (files.empty? and raw_data.empty?) ? post_url_encoded(fields, out_stream) : post_multipart(fields, files, raw_data, out_stream)
552
+ end
553
+
554
+ def setUseHttp(use_http)
555
+ @use_http = use_http
556
+ end
557
+
558
+ def setUserAgent(user_agent)
559
+ @user_agent = user_agent
560
+ end
561
+
562
+ def setProxy(host, port, user_name, password)
563
+ @proxy_host = host
564
+ @proxy_port = port
565
+ @proxy_user_name = user_name
566
+ @proxy_password = password
567
+ end
568
+
569
+ def getDebugLogUrl()
570
+ @debug_log_url
571
+ end
572
+
573
+ def getRemainingCreditCount()
574
+ @credits
575
+ end
576
+
577
+ def getConsumedCreditCount()
578
+ @consumed_credits
579
+ end
580
+
581
+ def getJobId()
582
+ @job_id
583
+ end
584
+
585
+ def getPageCount()
586
+ @page_count
587
+ end
588
+
589
+ def getOutputSize()
590
+ @output_size
591
+ end
592
+
593
+ private
594
+
595
+ def reset_response_data()
596
+ @debug_log_url = nil
597
+ @credits = 999999
598
+ @consumed_credits = 0
599
+ @job_id = ''
600
+ @page_count = 0
601
+ @output_size = 0
602
+ end
603
+
604
+ def post_url_encoded(fields, out_stream)
605
+ request = ConnectionHelper.create_request()
606
+ data = {}
607
+ fields.each { |key, value| data[key] = value.to_s if value }
608
+ request.set_form_data(data)
609
+ do_post(request, out_stream)
610
+ end
611
+
612
+ def post_multipart(fields, files, raw_data, out_stream)
613
+ request = ConnectionHelper.create_request()
614
+ request.body = ConnectionHelper.encode_multipart_post_data(fields, files, raw_data)
615
+ request.content_type = 'multipart/form-data; boundary=' + MULTIPART_BOUNDARY
616
+ do_post(request, out_stream)
617
+ end
618
+
619
+ def self.create_request()
620
+ Net::HTTP::Post.new('/convert/')
621
+ end
622
+
623
+ def self.add_file_field(name, file_name, data, body)
624
+ body << '--' + MULTIPART_BOUNDARY
625
+ body << 'Content-Disposition: form-data; name="%s"; filename="%s"' % [name, file_name]
626
+ body << 'Content-Type: application/octet-stream'
627
+ body << ''
628
+ body << data
629
+ end
630
+
631
+ def self.encode_multipart_post_data(fields, files, raw_data)
632
+ body = []
633
+ for field, value in fields
634
+ body << '--' + MULTIPART_BOUNDARY << 'Content-Disposition: form-data; name="%s"' % field << '' << value.to_s if value
635
+ end
636
+ for name, file_name in files
637
+ File.open(file_name, 'rb') do |f|
638
+ ConnectionHelper.add_file_field(name, file_name, f.read, body)
639
+ end
640
+ end
641
+ for name, data in raw_data
642
+ ConnectionHelper.add_file_field(name, name, data, body)
643
+ end
644
+ # finalize
645
+ body << '--' + MULTIPART_BOUNDARY + '--'
646
+ body << ''
647
+ body.join("\r\n")
648
+ end
649
+
650
+ def create_http_obj()
651
+ if !@use_http
652
+ require 'net/https' #apt-get install libopenssl-ruby
653
+ http = Net::HTTP.new(HOST, 443)
654
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless HOST == 'api.pdfcrowd.com'
655
+ http.use_ssl = true
656
+ elsif @proxy_host
657
+ http = Net::HTTP.new(HOST, 80, @proxy_host, @proxy_port, @proxy_user_name, @proxy_password)
658
+ else
659
+ http = Net::HTTP.new(HOST, 80)
660
+ end
661
+
662
+ return http
663
+ end
664
+
665
+ # sends a POST to the API
666
+ def do_post(request, out_stream)
667
+ raise Error.new("HTTPS over a proxy is not supported.") if !@use_http and @proxy_host
668
+
669
+ reset_response_data()
670
+
671
+ request.basic_auth(@user_name, @api_key)
672
+ request.add_field('User-Agent', @user_agent)
673
+
674
+ begin
675
+ http = create_http_obj()
676
+
677
+ begin
678
+ http.start {|conn|
679
+ conn.request(request) {|response|
680
+ @debug_log_url = response["X-Pdfcrowd-Debug-Log"] || ''
681
+ @credits = (response["X-Pdfcrowd-Remaining-Credits"] || 999999).to_i
682
+ @consumed_credits = (response["X-Pdfcrowd-Consumed-Credits"] || 0).to_i
683
+ @job_id = response["X-Pdfcrowd-Job-Id"] || ''
684
+ @page_count = (response["X-Pdfcrowd-Pages"] || 0).to_i
685
+ @output_size = (response["X-Pdfcrowd-Output-Size"] || 0).to_i
686
+
687
+ case response
688
+ when Net::HTTPSuccess
689
+ if out_stream
690
+ response.read_body do |chunk|
691
+ out_stream.write(chunk)
692
+ end
693
+ else
694
+ return response.body
695
+ end
696
+ else
697
+ raise Error.new(response.body, response.code)
698
+ end
699
+ }
700
+ }
701
+ rescue SystemCallError => why
702
+ raise Error.new("#{why}\n")
703
+ rescue Timeout::Error => why
704
+ raise Error.new("Operation timed out\n")
705
+ end
706
+ end
707
+ end
708
+ end
709
+
710
+ def self.create_invalid_value_message(value, field, converter, hint, id)
711
+ message = "Invalid value '%s' for a field '%s'." % [value, field]
712
+ message += " " + hint if hint
713
+ return message + " " + "Details: https://www.pdfcrowd.com/doc/api/%s/ruby/#%s" % [converter, id]
714
+ end
715
+
716
+ # generated code
717
+
718
+ # Conversion from HTML to PDF.
719
+ class HtmlToPdfClient
720
+ # Constructor for the Pdfcrowd API client.
721
+ #
722
+ # * +user_name+ - Your username at Pdfcrowd.
723
+ # * +api_key+ - Your API key.
724
+ def initialize(user_name, api_key)
725
+ @helper = ConnectionHelper.new(user_name, api_key)
726
+ @fields = {
727
+ 'input_format'=>'html',
728
+ 'output_format'=>'pdf'
729
+ }
730
+ @file_id = 1
731
+ @files = {}
732
+ @raw_data = {}
733
+ end
734
+
735
+ # Convert a web page.
736
+ #
737
+ # * +url+ - The address of the web page to convert. The supported protocols are http:// and https://.
738
+ # * *Returns* - Byte array containing the conversion output.
739
+ def convertUrl(url)
740
+ unless /(?i)^https?:\/\/.*$/.match(url)
741
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "html-to-pdf", "The supported protocols are http:// and https://.", "convert_url"), 470);
742
+ end
743
+
744
+ @fields['url'] = url
745
+ @helper.post(@fields, @files, @raw_data)
746
+ end
747
+
748
+ # Convert a web page and write the result to an output stream.
749
+ #
750
+ # * +url+ - The address of the web page to convert. The supported protocols are http:// and https://.
751
+ # * +out_stream+ - The output stream that will contain the conversion output.
752
+ def convertUrlToStream(url, out_stream)
753
+ unless /(?i)^https?:\/\/.*$/.match(url)
754
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "html-to-pdf", "The supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
755
+ end
756
+
757
+ @fields['url'] = url
758
+ @helper.post(@fields, @files, @raw_data, out_stream)
759
+ end
760
+
761
+ # Convert a web page and write the result to a local file.
762
+ #
763
+ # * +url+ - The address of the web page to convert. The supported protocols are http:// and https://.
764
+ # * +file_path+ - The output file path. The string must not be empty.
765
+ def convertUrlToFile(url, file_path)
766
+ if (!(!file_path.nil? && !file_path.empty?))
767
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "html-to-pdf", "The string must not be empty.", "convert_url_to_file"), 470);
768
+ end
769
+
770
+ output_file = open(file_path, "wb")
771
+ convertUrlToStream(url, output_file)
772
+ output_file.close()
773
+ end
774
+
775
+ # Convert a local file.
776
+ #
777
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.
778
+ # * *Returns* - Byte array containing the conversion output.
779
+ def convertFile(file)
780
+ if (!(File.file?(file) && !File.zero?(file)))
781
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-pdf", "The file must exist and not be empty.", "convert_file"), 470);
782
+ end
783
+
784
+ if (!(File.file?(file) && !File.zero?(file)))
785
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-pdf", "The file name must have a valid extension.", "convert_file"), 470);
786
+ end
787
+
788
+ @files['file'] = file
789
+ @helper.post(@fields, @files, @raw_data)
790
+ end
791
+
792
+ # Convert a local file and write the result to an output stream.
793
+ #
794
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.
795
+ # * +out_stream+ - The output stream that will contain the conversion output.
796
+ def convertFileToStream(file, out_stream)
797
+ if (!(File.file?(file) && !File.zero?(file)))
798
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-pdf", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
799
+ end
800
+
801
+ if (!(File.file?(file) && !File.zero?(file)))
802
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-pdf", "The file name must have a valid extension.", "convert_file_to_stream"), 470);
803
+ end
804
+
805
+ @files['file'] = file
806
+ @helper.post(@fields, @files, @raw_data, out_stream)
807
+ end
808
+
809
+ # Convert a local file and write the result to a local file.
810
+ #
811
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.
812
+ # * +file_path+ - The output file path. The string must not be empty.
813
+ def convertFileToFile(file, file_path)
814
+ if (!(!file_path.nil? && !file_path.empty?))
815
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "html-to-pdf", "The string must not be empty.", "convert_file_to_file"), 470);
816
+ end
817
+
818
+ output_file = open(file_path, "wb")
819
+ convertFileToStream(file, output_file)
820
+ output_file.close()
821
+ end
822
+
823
+ # Convert a string.
824
+ #
825
+ # * +text+ - The string content to convert. The string must not be empty.
826
+ # * *Returns* - Byte array containing the conversion output.
827
+ def convertString(text)
828
+ if (!(!text.nil? && !text.empty?))
829
+ raise Error.new(Pdfcrowd.create_invalid_value_message(text, "text", "html-to-pdf", "The string must not be empty.", "convert_string"), 470);
830
+ end
831
+
832
+ @fields['text'] = text
833
+ @helper.post(@fields, @files, @raw_data)
834
+ end
835
+
836
+ # Convert a string and write the output to an output stream.
837
+ #
838
+ # * +text+ - The string content to convert. The string must not be empty.
839
+ # * +out_stream+ - The output stream that will contain the conversion output.
840
+ def convertStringToStream(text, out_stream)
841
+ if (!(!text.nil? && !text.empty?))
842
+ raise Error.new(Pdfcrowd.create_invalid_value_message(text, "text", "html-to-pdf", "The string must not be empty.", "convert_string_to_stream"), 470);
843
+ end
844
+
845
+ @fields['text'] = text
846
+ @helper.post(@fields, @files, @raw_data, out_stream)
847
+ end
848
+
849
+ # Convert a string and write the output to a file.
850
+ #
851
+ # * +text+ - The string content to convert. The string must not be empty.
852
+ # * +file_path+ - The output file path. The string must not be empty.
853
+ def convertStringToFile(text, file_path)
854
+ if (!(!file_path.nil? && !file_path.empty?))
855
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "html-to-pdf", "The string must not be empty.", "convert_string_to_file"), 470);
856
+ end
857
+
858
+ output_file = open(file_path, "wb")
859
+ convertStringToStream(text, output_file)
860
+ output_file.close()
861
+ end
862
+
863
+ # Set the output page size.
864
+ #
865
+ # * +page_size+ - Allowed values are A2, A3, A4, A5, A6, Letter.
866
+ def setPageSize(page_size)
867
+ unless /(?i)^(A2|A3|A4|A5|A6|Letter)$/.match(page_size)
868
+ raise Error.new(Pdfcrowd.create_invalid_value_message(page_size, "page_size", "html-to-pdf", "Allowed values are A2, A3, A4, A5, A6, Letter.", "set_page_size"), 470);
869
+ end
870
+
871
+ @fields['page_size'] = page_size
872
+ end
873
+
874
+ # Set the output page width.
875
+ #
876
+ # * +page_width+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
877
+ def setPageWidth(page_width)
878
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(page_width)
879
+ raise Error.new(Pdfcrowd.create_invalid_value_message(page_width, "page_width", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_page_width"), 470);
880
+ end
881
+
882
+ @fields['page_width'] = page_width
883
+ end
884
+
885
+ # Set the output page height.
886
+ #
887
+ # * +page_height+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
888
+ def setPageHeight(page_height)
889
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(page_height)
890
+ raise Error.new(Pdfcrowd.create_invalid_value_message(page_height, "page_height", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_page_height"), 470);
891
+ end
892
+
893
+ @fields['page_height'] = page_height
894
+ end
895
+
896
+ # Set the output page dimensions.
897
+ #
898
+ # * +width+ - Set the output page width. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
899
+ # * +height+ - Set the output page height. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
900
+ def setPageDimensions(width, height)
901
+ setPageWidth(width)
902
+ setPageHeight(height)
903
+ end
904
+
905
+ # Set the output page orientation.
906
+ #
907
+ # * +orientation+ - Allowed values are landscape, portrait.
908
+ def setOrientation(orientation)
909
+ unless /(?i)^(landscape|portrait)$/.match(orientation)
910
+ raise Error.new(Pdfcrowd.create_invalid_value_message(orientation, "orientation", "html-to-pdf", "Allowed values are landscape, portrait.", "set_orientation"), 470);
911
+ end
912
+
913
+ @fields['orientation'] = orientation
914
+ end
915
+
916
+ # Set the output page top margin.
917
+ #
918
+ # * +margin_top+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
919
+ def setMarginTop(margin_top)
920
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_top)
921
+ raise Error.new(Pdfcrowd.create_invalid_value_message(margin_top, "margin_top", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_top"), 470);
922
+ end
923
+
924
+ @fields['margin_top'] = margin_top
925
+ end
926
+
927
+ # Set the output page right margin.
928
+ #
929
+ # * +margin_right+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
930
+ def setMarginRight(margin_right)
931
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_right)
932
+ raise Error.new(Pdfcrowd.create_invalid_value_message(margin_right, "margin_right", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_right"), 470);
933
+ end
934
+
935
+ @fields['margin_right'] = margin_right
936
+ end
937
+
938
+ # Set the output page bottom margin.
939
+ #
940
+ # * +margin_bottom+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
941
+ def setMarginBottom(margin_bottom)
942
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_bottom)
943
+ raise Error.new(Pdfcrowd.create_invalid_value_message(margin_bottom, "margin_bottom", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_bottom"), 470);
944
+ end
945
+
946
+ @fields['margin_bottom'] = margin_bottom
947
+ end
948
+
949
+ # Set the output page left margin.
950
+ #
951
+ # * +margin_left+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
952
+ def setMarginLeft(margin_left)
953
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_left)
954
+ raise Error.new(Pdfcrowd.create_invalid_value_message(margin_left, "margin_left", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_margin_left"), 470);
955
+ end
956
+
957
+ @fields['margin_left'] = margin_left
958
+ end
959
+
960
+ # Disable margins.
961
+ #
962
+ # * +no_margins+ - Set to true to disable margins.
963
+ def setNoMargins(no_margins)
964
+ @fields['no_margins'] = no_margins
965
+ end
966
+
967
+ # Set the output page margins.
968
+ #
969
+ # * +top+ - Set the output page top margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
970
+ # * +right+ - Set the output page right margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
971
+ # * +bottom+ - Set the output page bottom margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
972
+ # * +left+ - Set the output page left margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
973
+ def setPageMargins(top, right, bottom, left)
974
+ setMarginTop(top)
975
+ setMarginRight(right)
976
+ setMarginBottom(bottom)
977
+ setMarginLeft(left)
978
+ end
979
+
980
+ # Load an HTML code from the specified URL and use it as the page header. The following classes can be used in the HTML. The content of the respective elements will be expanded as follows: pdfcrowd-page-count - the total page count of printed pages pdfcrowd-page-number - the current page number pdfcrowd-source-url - the source URL of a converted document The following attributes can be used: data-pdfcrowd-number-format - specifies the type of the used numerals Arabic numerals are used by default. Roman numerals can be generated by the roman and roman-lowercase values Example: <span class='pdfcrowd-page-number' data-pdfcrowd-number-format='roman'></span> data-pdfcrowd-placement - specifies where to place the source URL, allowed values: The URL is inserted to the content Example: <span class='pdfcrowd-source-url'></span> will produce <span>http://example.com</span> href - the URL is set to the href attribute Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href'>Link to source</a> will produce <a href='http://example.com'>Link to source</a> href-and-content - the URL is set to the href attribute and to the content Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a> will produce <a href='http://example.com'>http://example.com</a>
981
+ #
982
+ # * +header_url+ - The supported protocols are http:// and https://.
983
+ def setHeaderUrl(header_url)
984
+ unless /(?i)^https?:\/\/.*$/.match(header_url)
985
+ raise Error.new(Pdfcrowd.create_invalid_value_message(header_url, "header_url", "html-to-pdf", "The supported protocols are http:// and https://.", "set_header_url"), 470);
986
+ end
987
+
988
+ @fields['header_url'] = header_url
989
+ end
990
+
991
+ # Use the specified HTML code as the page header. The following classes can be used in the HTML. The content of the respective elements will be expanded as follows: pdfcrowd-page-count - the total page count of printed pages pdfcrowd-page-number - the current page number pdfcrowd-source-url - the source URL of a converted document The following attributes can be used: data-pdfcrowd-number-format - specifies the type of the used numerals Arabic numerals are used by default. Roman numerals can be generated by the roman and roman-lowercase values Example: <span class='pdfcrowd-page-number' data-pdfcrowd-number-format='roman'></span> data-pdfcrowd-placement - specifies where to place the source URL, allowed values: The URL is inserted to the content Example: <span class='pdfcrowd-source-url'></span> will produce <span>http://example.com</span> href - the URL is set to the href attribute Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href'>Link to source</a> will produce <a href='http://example.com'>Link to source</a> href-and-content - the URL is set to the href attribute and to the content Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a> will produce <a href='http://example.com'>http://example.com</a>
992
+ #
993
+ # * +header_html+ - The string must not be empty.
994
+ def setHeaderHtml(header_html)
995
+ if (!(!header_html.nil? && !header_html.empty?))
996
+ raise Error.new(Pdfcrowd.create_invalid_value_message(header_html, "header_html", "html-to-pdf", "The string must not be empty.", "set_header_html"), 470);
997
+ end
998
+
999
+ @fields['header_html'] = header_html
1000
+ end
1001
+
1002
+ # Set the header height.
1003
+ #
1004
+ # * +header_height+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
1005
+ def setHeaderHeight(header_height)
1006
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(header_height)
1007
+ raise Error.new(Pdfcrowd.create_invalid_value_message(header_height, "header_height", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_header_height"), 470);
1008
+ end
1009
+
1010
+ @fields['header_height'] = header_height
1011
+ end
1012
+
1013
+ # Load an HTML code from the specified URL and use it as the page footer. The following classes can be used in the HTML. The content of the respective elements will be expanded as follows: pdfcrowd-page-count - the total page count of printed pages pdfcrowd-page-number - the current page number pdfcrowd-source-url - the source URL of a converted document The following attributes can be used: data-pdfcrowd-number-format - specifies the type of the used numerals Arabic numerals are used by default. Roman numerals can be generated by the roman and roman-lowercase values Example: <span class='pdfcrowd-page-number' data-pdfcrowd-number-format='roman'></span> data-pdfcrowd-placement - specifies where to place the source URL, allowed values: The URL is inserted to the content Example: <span class='pdfcrowd-source-url'></span> will produce <span>http://example.com</span> href - the URL is set to the href attribute Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href'>Link to source</a> will produce <a href='http://example.com'>Link to source</a> href-and-content - the URL is set to the href attribute and to the content Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a> will produce <a href='http://example.com'>http://example.com</a>
1014
+ #
1015
+ # * +footer_url+ - The supported protocols are http:// and https://.
1016
+ def setFooterUrl(footer_url)
1017
+ unless /(?i)^https?:\/\/.*$/.match(footer_url)
1018
+ raise Error.new(Pdfcrowd.create_invalid_value_message(footer_url, "footer_url", "html-to-pdf", "The supported protocols are http:// and https://.", "set_footer_url"), 470);
1019
+ end
1020
+
1021
+ @fields['footer_url'] = footer_url
1022
+ end
1023
+
1024
+ # Use the specified HTML as the page footer. The following classes can be used in the HTML. The content of the respective elements will be expanded as follows: pdfcrowd-page-count - the total page count of printed pages pdfcrowd-page-number - the current page number pdfcrowd-source-url - the source URL of a converted document The following attributes can be used: data-pdfcrowd-number-format - specifies the type of the used numerals Arabic numerals are used by default. Roman numerals can be generated by the roman and roman-lowercase values Example: <span class='pdfcrowd-page-number' data-pdfcrowd-number-format='roman'></span> data-pdfcrowd-placement - specifies where to place the source URL, allowed values: The URL is inserted to the content Example: <span class='pdfcrowd-source-url'></span> will produce <span>http://example.com</span> href - the URL is set to the href attribute Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href'>Link to source</a> will produce <a href='http://example.com'>Link to source</a> href-and-content - the URL is set to the href attribute and to the content Example: <a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a> will produce <a href='http://example.com'>http://example.com</a>
1025
+ #
1026
+ # * +footer_html+ - The string must not be empty.
1027
+ def setFooterHtml(footer_html)
1028
+ if (!(!footer_html.nil? && !footer_html.empty?))
1029
+ raise Error.new(Pdfcrowd.create_invalid_value_message(footer_html, "footer_html", "html-to-pdf", "The string must not be empty.", "set_footer_html"), 470);
1030
+ end
1031
+
1032
+ @fields['footer_html'] = footer_html
1033
+ end
1034
+
1035
+ # Set the footer height.
1036
+ #
1037
+ # * +footer_height+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
1038
+ def setFooterHeight(footer_height)
1039
+ unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(footer_height)
1040
+ raise Error.new(Pdfcrowd.create_invalid_value_message(footer_height, "footer_height", "html-to-pdf", "Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).", "set_footer_height"), 470);
1041
+ end
1042
+
1043
+ @fields['footer_height'] = footer_height
1044
+ end
1045
+
1046
+ # Set the page range to print.
1047
+ #
1048
+ # * +pages+ - A comma seperated list of page numbers or ranges.
1049
+ def setPrintPageRange(pages)
1050
+ 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)
1051
+ raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "pages", "html-to-pdf", "A comma seperated list of page numbers or ranges.", "set_print_page_range"), 470);
1052
+ end
1053
+
1054
+ @fields['print_page_range'] = pages
1055
+ end
1056
+
1057
+ # Apply the first page of the watermark PDF to every page of the output PDF.
1058
+ #
1059
+ # * +page_watermark+ - The file path to a local watermark PDF file. The file must exist and not be empty.
1060
+ def setPageWatermark(page_watermark)
1061
+ if (!(File.file?(page_watermark) && !File.zero?(page_watermark)))
1062
+ raise Error.new(Pdfcrowd.create_invalid_value_message(page_watermark, "page_watermark", "html-to-pdf", "The file must exist and not be empty.", "set_page_watermark"), 470);
1063
+ end
1064
+
1065
+ @files['page_watermark'] = page_watermark
1066
+ end
1067
+
1068
+ # Apply each page of the specified watermark PDF to the corresponding page of the output PDF.
1069
+ #
1070
+ # * +multipage_watermark+ - The file path to a local watermark PDF file. The file must exist and not be empty.
1071
+ def setMultipageWatermark(multipage_watermark)
1072
+ if (!(File.file?(multipage_watermark) && !File.zero?(multipage_watermark)))
1073
+ raise Error.new(Pdfcrowd.create_invalid_value_message(multipage_watermark, "multipage_watermark", "html-to-pdf", "The file must exist and not be empty.", "set_multipage_watermark"), 470);
1074
+ end
1075
+
1076
+ @files['multipage_watermark'] = multipage_watermark
1077
+ end
1078
+
1079
+ # Apply the first page of the specified PDF to the background of every page of the output PDF.
1080
+ #
1081
+ # * +page_background+ - The file path to a local background PDF file. The file must exist and not be empty.
1082
+ def setPageBackground(page_background)
1083
+ if (!(File.file?(page_background) && !File.zero?(page_background)))
1084
+ raise Error.new(Pdfcrowd.create_invalid_value_message(page_background, "page_background", "html-to-pdf", "The file must exist and not be empty.", "set_page_background"), 470);
1085
+ end
1086
+
1087
+ @files['page_background'] = page_background
1088
+ end
1089
+
1090
+ # Apply each page of the specified PDF to the background of the corresponding page of the output PDF.
1091
+ #
1092
+ # * +multipage_background+ - The file path to a local background PDF file. The file must exist and not be empty.
1093
+ def setMultipageBackground(multipage_background)
1094
+ if (!(File.file?(multipage_background) && !File.zero?(multipage_background)))
1095
+ raise Error.new(Pdfcrowd.create_invalid_value_message(multipage_background, "multipage_background", "html-to-pdf", "The file must exist and not be empty.", "set_multipage_background"), 470);
1096
+ end
1097
+
1098
+ @files['multipage_background'] = multipage_background
1099
+ end
1100
+
1101
+ # The page header is not printed on the specified pages.
1102
+ #
1103
+ # * +pages+ - List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on. A comma seperated list of page numbers.
1104
+ def setExcludeHeaderOnPages(pages)
1105
+ unless /^(?:\s*\-?\d+\s*,)*\s*\-?\d+\s*$/.match(pages)
1106
+ raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "pages", "html-to-pdf", "A comma seperated list of page numbers.", "set_exclude_header_on_pages"), 470);
1107
+ end
1108
+
1109
+ @fields['exclude_header_on_pages'] = pages
1110
+ end
1111
+
1112
+ # The page footer is not printed on the specified pages.
1113
+ #
1114
+ # * +pages+ - List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on. A comma seperated list of page numbers.
1115
+ def setExcludeFooterOnPages(pages)
1116
+ unless /^(?:\s*\-?\d+\s*,)*\s*\-?\d+\s*$/.match(pages)
1117
+ raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "pages", "html-to-pdf", "A comma seperated list of page numbers.", "set_exclude_footer_on_pages"), 470);
1118
+ end
1119
+
1120
+ @fields['exclude_footer_on_pages'] = pages
1121
+ end
1122
+
1123
+ # Set an offset between physical and logical page numbers.
1124
+ #
1125
+ # * +offset+ - Integer specifying page offset.
1126
+ def setPageNumberingOffset(offset)
1127
+ @fields['page_numbering_offset'] = offset
1128
+ end
1129
+
1130
+ # Do not print the background graphics.
1131
+ #
1132
+ # * +no_background+ - Set to true to disable the background graphics.
1133
+ def setNoBackground(no_background)
1134
+ @fields['no_background'] = no_background
1135
+ end
1136
+
1137
+ # Do not execute JavaScript.
1138
+ #
1139
+ # * +disable_javascript+ - Set to true to disable JavaScript in web pages.
1140
+ def setDisableJavascript(disable_javascript)
1141
+ @fields['disable_javascript'] = disable_javascript
1142
+ end
1143
+
1144
+ # Do not load images.
1145
+ #
1146
+ # * +disable_image_loading+ - Set to true to disable loading of images.
1147
+ def setDisableImageLoading(disable_image_loading)
1148
+ @fields['disable_image_loading'] = disable_image_loading
1149
+ end
1150
+
1151
+ # Disable loading fonts from remote sources.
1152
+ #
1153
+ # * +disable_remote_fonts+ - Set to true disable loading remote fonts.
1154
+ def setDisableRemoteFonts(disable_remote_fonts)
1155
+ @fields['disable_remote_fonts'] = disable_remote_fonts
1156
+ end
1157
+
1158
+ # Set the default HTML content text encoding.
1159
+ #
1160
+ # * +default_encoding+ - The text encoding of the HTML content.
1161
+ def setDefaultEncoding(default_encoding)
1162
+ @fields['default_encoding'] = default_encoding
1163
+ end
1164
+
1165
+ # Set the HTTP authentication user name.
1166
+ #
1167
+ # * +user_name+ - The user name.
1168
+ def setHttpAuthUserName(user_name)
1169
+ @fields['http_auth_user_name'] = user_name
1170
+ end
1171
+
1172
+ # Set the HTTP authentication password.
1173
+ #
1174
+ # * +password+ - The password.
1175
+ def setHttpAuthPassword(password)
1176
+ @fields['http_auth_password'] = password
1177
+ end
1178
+
1179
+ # Set the HTTP authentication.
1180
+ #
1181
+ # * +user_name+ - Set the HTTP authentication user name.
1182
+ # * +password+ - Set the HTTP authentication password.
1183
+ def setHttpAuth(user_name, password)
1184
+ setHttpAuthUserName(user_name)
1185
+ setHttpAuthPassword(password)
1186
+ end
1187
+
1188
+ # Use the print version of the page if available (@media print).
1189
+ #
1190
+ # * +use_print_media+ - Set to true to use the print version of the page.
1191
+ def setUsePrintMedia(use_print_media)
1192
+ @fields['use_print_media'] = use_print_media
1193
+ end
1194
+
1195
+ # Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
1196
+ #
1197
+ # * +no_xpdfcrowd_header+ - Set to true to disable sending X-Pdfcrowd HTTP header.
1198
+ def setNoXpdfcrowdHeader(no_xpdfcrowd_header)
1199
+ @fields['no_xpdfcrowd_header'] = no_xpdfcrowd_header
1200
+ end
1201
+
1202
+ # Set cookies that are sent in Pdfcrowd HTTP requests.
1203
+ #
1204
+ # * +cookies+ - The cookie string.
1205
+ def setCookies(cookies)
1206
+ @fields['cookies'] = cookies
1207
+ end
1208
+
1209
+ # Do not allow insecure HTTPS connections.
1210
+ #
1211
+ # * +verify_ssl_certificates+ - Set to true to enable SSL certificate verification.
1212
+ def setVerifySslCertificates(verify_ssl_certificates)
1213
+ @fields['verify_ssl_certificates'] = verify_ssl_certificates
1214
+ end
1215
+
1216
+ # Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
1217
+ #
1218
+ # * +fail_on_error+ - Set to true to abort the conversion.
1219
+ def setFailOnMainUrlError(fail_on_error)
1220
+ @fields['fail_on_main_url_error'] = fail_on_error
1221
+ end
1222
+
1223
+ # Abort the conversion if any of the sub-request HTTP status code is greater than or equal to 400.
1224
+ #
1225
+ # * +fail_on_error+ - Set to true to abort the conversion.
1226
+ def setFailOnAnyUrlError(fail_on_error)
1227
+ @fields['fail_on_any_url_error'] = fail_on_error
1228
+ end
1229
+
1230
+ # Run a custom JavaScript after the document is loaded. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, ...).
1231
+ #
1232
+ # * +custom_javascript+ - String containing a JavaScript code. The string must not be empty.
1233
+ def setCustomJavascript(custom_javascript)
1234
+ if (!(!custom_javascript.nil? && !custom_javascript.empty?))
1235
+ raise Error.new(Pdfcrowd.create_invalid_value_message(custom_javascript, "custom_javascript", "html-to-pdf", "The string must not be empty.", "set_custom_javascript"), 470);
1236
+ end
1237
+
1238
+ @fields['custom_javascript'] = custom_javascript
1239
+ end
1240
+
1241
+ # Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
1242
+ #
1243
+ # * +custom_http_header+ - A string containing the header name and value separated by a colon.
1244
+ def setCustomHttpHeader(custom_http_header)
1245
+ unless /^.+:.+$/.match(custom_http_header)
1246
+ raise Error.new(Pdfcrowd.create_invalid_value_message(custom_http_header, "custom_http_header", "html-to-pdf", "A string containing the header name and value separated by a colon.", "set_custom_http_header"), 470);
1247
+ end
1248
+
1249
+ @fields['custom_http_header'] = custom_http_header
1250
+ end
1251
+
1252
+ # Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. The maximum value is determined by your API license.
1253
+ #
1254
+ # * +javascript_delay+ - The number of milliseconds to wait. Must be a positive integer number or 0.
1255
+ def setJavascriptDelay(javascript_delay)
1256
+ if (!(Integer(javascript_delay) >= 0))
1257
+ raise Error.new(Pdfcrowd.create_invalid_value_message(javascript_delay, "javascript_delay", "html-to-pdf", "Must be a positive integer number or 0.", "set_javascript_delay"), 470);
1258
+ end
1259
+
1260
+ @fields['javascript_delay'] = javascript_delay
1261
+ end
1262
+
1263
+ # Convert only the specified element and its children. The element is specified by one or more CSS selectors. If the element is not found, the conversion fails. If multiple elements are found, the first one is used.
1264
+ #
1265
+ # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1266
+ def setElementToConvert(selectors)
1267
+ if (!(!selectors.nil? && !selectors.empty?))
1268
+ raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "selectors", "html-to-pdf", "The string must not be empty.", "set_element_to_convert"), 470);
1269
+ end
1270
+
1271
+ @fields['element_to_convert'] = selectors
1272
+ end
1273
+
1274
+ # Specify the DOM handling when only a part of the document is converted.
1275
+ #
1276
+ # * +mode+ - Allowed values are cut-out, remove-siblings, hide-siblings.
1277
+ def setElementToConvertMode(mode)
1278
+ unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode)
1279
+ raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "mode", "html-to-pdf", "Allowed values are cut-out, remove-siblings, hide-siblings.", "set_element_to_convert_mode"), 470);
1280
+ end
1281
+
1282
+ @fields['element_to_convert_mode'] = mode
1283
+ end
1284
+
1285
+ # Wait for the specified element in a source document. The element is specified by one or more CSS selectors. If the element is not found, the conversion fails.
1286
+ #
1287
+ # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1288
+ def setWaitForElement(selectors)
1289
+ if (!(!selectors.nil? && !selectors.empty?))
1290
+ raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "selectors", "html-to-pdf", "The string must not be empty.", "set_wait_for_element"), 470);
1291
+ end
1292
+
1293
+ @fields['wait_for_element'] = selectors
1294
+ end
1295
+
1296
+ # Set the viewport width in pixels. The viewport is the user's visible area of the page.
1297
+ #
1298
+ # * +viewport_width+ - The value must be in a range 96-7680.
1299
+ def setViewportWidth(viewport_width)
1300
+ if (!(Integer(viewport_width) >= 96 && Integer(viewport_width) <= 7680))
1301
+ raise Error.new(Pdfcrowd.create_invalid_value_message(viewport_width, "viewport_width", "html-to-pdf", "The value must be in a range 96-7680.", "set_viewport_width"), 470);
1302
+ end
1303
+
1304
+ @fields['viewport_width'] = viewport_width
1305
+ end
1306
+
1307
+ # Set the viewport height in pixels. The viewport is the user's visible area of the page.
1308
+ #
1309
+ # * +viewport_height+ - Must be a positive integer number.
1310
+ def setViewportHeight(viewport_height)
1311
+ if (!(Integer(viewport_height) > 0))
1312
+ raise Error.new(Pdfcrowd.create_invalid_value_message(viewport_height, "viewport_height", "html-to-pdf", "Must be a positive integer number.", "set_viewport_height"), 470);
1313
+ end
1314
+
1315
+ @fields['viewport_height'] = viewport_height
1316
+ end
1317
+
1318
+ # Set the viewport size. The viewport is the user's visible area of the page.
1319
+ #
1320
+ # * +width+ - Set the viewport width in pixels. The viewport is the user's visible area of the page. The value must be in a range 96-7680.
1321
+ # * +height+ - Set the viewport height in pixels. The viewport is the user's visible area of the page. Must be a positive integer number.
1322
+ def setViewport(width, height)
1323
+ setViewportWidth(width)
1324
+ setViewportHeight(height)
1325
+ end
1326
+
1327
+ # Sets the rendering mode.
1328
+ #
1329
+ # * +rendering_mode+ - The rendering mode. Allowed values are default, viewport.
1330
+ def setRenderingMode(rendering_mode)
1331
+ unless /(?i)^(default|viewport)$/.match(rendering_mode)
1332
+ raise Error.new(Pdfcrowd.create_invalid_value_message(rendering_mode, "rendering_mode", "html-to-pdf", "Allowed values are default, viewport.", "set_rendering_mode"), 470);
1333
+ end
1334
+
1335
+ @fields['rendering_mode'] = rendering_mode
1336
+ end
1337
+
1338
+ # Set the scaling factor (zoom) for the main page area.
1339
+ #
1340
+ # * +scale_factor+ - The scale factor. The value must be in a range 10-500.
1341
+ def setScaleFactor(scale_factor)
1342
+ if (!(Integer(scale_factor) >= 10 && Integer(scale_factor) <= 500))
1343
+ raise Error.new(Pdfcrowd.create_invalid_value_message(scale_factor, "scale_factor", "html-to-pdf", "The value must be in a range 10-500.", "set_scale_factor"), 470);
1344
+ end
1345
+
1346
+ @fields['scale_factor'] = scale_factor
1347
+ end
1348
+
1349
+ # Set the scaling factor (zoom) for the header and footer.
1350
+ #
1351
+ # * +header_footer_scale_factor+ - The scale factor. The value must be in a range 10-500.
1352
+ def setHeaderFooterScaleFactor(header_footer_scale_factor)
1353
+ if (!(Integer(header_footer_scale_factor) >= 10 && Integer(header_footer_scale_factor) <= 500))
1354
+ raise Error.new(Pdfcrowd.create_invalid_value_message(header_footer_scale_factor, "header_footer_scale_factor", "html-to-pdf", "The value must be in a range 10-500.", "set_header_footer_scale_factor"), 470);
1355
+ end
1356
+
1357
+ @fields['header_footer_scale_factor'] = header_footer_scale_factor
1358
+ end
1359
+
1360
+ # Create linearized PDF. This is also known as Fast Web View.
1361
+ #
1362
+ # * +linearize+ - Set to true to create linearized PDF.
1363
+ def setLinearize(linearize)
1364
+ @fields['linearize'] = linearize
1365
+ end
1366
+
1367
+ # Encrypt the PDF. This prevents search engines from indexing the contents.
1368
+ #
1369
+ # * +encrypt+ - Set to true to enable PDF encryption.
1370
+ def setEncrypt(encrypt)
1371
+ @fields['encrypt'] = encrypt
1372
+ end
1373
+
1374
+ # Protect the PDF with a user password. When a PDF has a user password, it must be supplied in order to view the document and to perform operations allowed by the access permissions.
1375
+ #
1376
+ # * +user_password+ - The user password.
1377
+ def setUserPassword(user_password)
1378
+ @fields['user_password'] = user_password
1379
+ end
1380
+
1381
+ # Protect the PDF with an owner password. Supplying an owner password grants unlimited access to the PDF including changing the passwords and access permissions.
1382
+ #
1383
+ # * +owner_password+ - The owner password.
1384
+ def setOwnerPassword(owner_password)
1385
+ @fields['owner_password'] = owner_password
1386
+ end
1387
+
1388
+ # Disallow printing of the output PDF.
1389
+ #
1390
+ # * +no_print+ - Set to true to set the no-print flag in the output PDF.
1391
+ def setNoPrint(no_print)
1392
+ @fields['no_print'] = no_print
1393
+ end
1394
+
1395
+ # Disallow modification of the ouput PDF.
1396
+ #
1397
+ # * +no_modify+ - Set to true to set the read-only only flag in the output PDF.
1398
+ def setNoModify(no_modify)
1399
+ @fields['no_modify'] = no_modify
1400
+ end
1401
+
1402
+ # Disallow text and graphics extraction from the output PDF.
1403
+ #
1404
+ # * +no_copy+ - Set to true to set the no-copy flag in the output PDF.
1405
+ def setNoCopy(no_copy)
1406
+ @fields['no_copy'] = no_copy
1407
+ end
1408
+
1409
+ # Turn on the debug logging.
1410
+ #
1411
+ # * +debug_log+ - Set to true to enable the debug logging.
1412
+ def setDebugLog(debug_log)
1413
+ @fields['debug_log'] = debug_log
1414
+ end
1415
+
1416
+ # Get the URL of the debug log for the last conversion.
1417
+ # * *Returns* - The link to the debug log.
1418
+ def getDebugLogUrl()
1419
+ return @helper.getDebugLogUrl()
1420
+ end
1421
+
1422
+ # Get the number of conversion credits available in your account.
1423
+ # The returned value can differ from the actual count if you run parallel conversions.
1424
+ # The special value 999999 is returned if the information is not available.
1425
+ # * *Returns* - The number of credits.
1426
+ def getRemainingCreditCount()
1427
+ return @helper.getRemainingCreditCount()
1428
+ end
1429
+
1430
+ # Get the number of credits consumed by the last conversion.
1431
+ # * *Returns* - The number of credits.
1432
+ def getConsumedCreditCount()
1433
+ return @helper.getConsumedCreditCount()
1434
+ end
1435
+
1436
+ # Get the job id.
1437
+ # * *Returns* - The unique job identifier.
1438
+ def getJobId()
1439
+ return @helper.getJobId()
1440
+ end
1441
+
1442
+ # Get the total number of pages in the output document.
1443
+ # * *Returns* - The page count.
1444
+ def getPageCount()
1445
+ return @helper.getPageCount()
1446
+ end
1447
+
1448
+ # Get the size of the output in bytes.
1449
+ # * *Returns* - The count of bytes.
1450
+ def getOutputSize()
1451
+ return @helper.getOutputSize()
1452
+ end
1453
+
1454
+ # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
1455
+ #
1456
+ # * +use_http+ - Set to true to use HTTP.
1457
+ def setUseHttp(use_http)
1458
+ @helper.setUseHttp(use_http)
1459
+ end
1460
+
1461
+ # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
1462
+ #
1463
+ # * +user_agent+ - The user agent string.
1464
+ def setUserAgent(user_agent)
1465
+ @helper.setUserAgent(user_agent)
1466
+ end
1467
+
1468
+ # Specifies an HTTP proxy that the API client library will use to connect to the internet.
1469
+ #
1470
+ # * +host+ - The proxy hostname.
1471
+ # * +port+ - The proxy port.
1472
+ # * +user_name+ - The username.
1473
+ # * +password+ - The password.
1474
+ def setProxy(host, port, user_name, password)
1475
+ @helper.setProxy(host, port, user_name, password)
1476
+ end
1477
+
1478
+ end
1479
+
1480
+ # Conversion from HTML to image.
1481
+ class HtmlToImageClient
1482
+ # Constructor for the Pdfcrowd API client.
1483
+ #
1484
+ # * +user_name+ - Your username at Pdfcrowd.
1485
+ # * +api_key+ - Your API key.
1486
+ def initialize(user_name, api_key)
1487
+ @helper = ConnectionHelper.new(user_name, api_key)
1488
+ @fields = {
1489
+ 'input_format'=>'html',
1490
+ 'output_format'=>'png'
1491
+ }
1492
+ @file_id = 1
1493
+ @files = {}
1494
+ @raw_data = {}
1495
+ end
1496
+
1497
+ # The format of the output file.
1498
+ #
1499
+ # * +output_format+ - Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.
1500
+ def setOutputFormat(output_format)
1501
+ unless /(?i)^(png|jpg|gif|tiff|bmp|ico|ppm|pgm|pbm|pnm|psb|pct|ras|tga|sgi|sun|webp)$/.match(output_format)
1502
+ raise Error.new(Pdfcrowd.create_invalid_value_message(output_format, "output_format", "html-to-image", "Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.", "set_output_format"), 470);
1503
+ end
1504
+
1505
+ @fields['output_format'] = output_format
1506
+ end
1507
+
1508
+ # Convert a web page.
1509
+ #
1510
+ # * +url+ - The address of the web page to convert. The supported protocols are http:// and https://.
1511
+ # * *Returns* - Byte array containing the conversion output.
1512
+ def convertUrl(url)
1513
+ unless /(?i)^https?:\/\/.*$/.match(url)
1514
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "html-to-image", "The supported protocols are http:// and https://.", "convert_url"), 470);
1515
+ end
1516
+
1517
+ @fields['url'] = url
1518
+ @helper.post(@fields, @files, @raw_data)
1519
+ end
1520
+
1521
+ # Convert a web page and write the result to an output stream.
1522
+ #
1523
+ # * +url+ - The address of the web page to convert. The supported protocols are http:// and https://.
1524
+ # * +out_stream+ - The output stream that will contain the conversion output.
1525
+ def convertUrlToStream(url, out_stream)
1526
+ unless /(?i)^https?:\/\/.*$/.match(url)
1527
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "html-to-image", "The supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
1528
+ end
1529
+
1530
+ @fields['url'] = url
1531
+ @helper.post(@fields, @files, @raw_data, out_stream)
1532
+ end
1533
+
1534
+ # Convert a web page and write the result to a local file.
1535
+ #
1536
+ # * +url+ - The address of the web page to convert. The supported protocols are http:// and https://.
1537
+ # * +file_path+ - The output file path. The string must not be empty.
1538
+ def convertUrlToFile(url, file_path)
1539
+ if (!(!file_path.nil? && !file_path.empty?))
1540
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "html-to-image", "The string must not be empty.", "convert_url_to_file"), 470);
1541
+ end
1542
+
1543
+ output_file = open(file_path, "wb")
1544
+ convertUrlToStream(url, output_file)
1545
+ output_file.close()
1546
+ end
1547
+
1548
+ # Convert a local file.
1549
+ #
1550
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.
1551
+ # * *Returns* - Byte array containing the conversion output.
1552
+ def convertFile(file)
1553
+ if (!(File.file?(file) && !File.zero?(file)))
1554
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-image", "The file must exist and not be empty.", "convert_file"), 470);
1555
+ end
1556
+
1557
+ if (!(File.file?(file) && !File.zero?(file)))
1558
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-image", "The file name must have a valid extension.", "convert_file"), 470);
1559
+ end
1560
+
1561
+ @files['file'] = file
1562
+ @helper.post(@fields, @files, @raw_data)
1563
+ end
1564
+
1565
+ # Convert a local file and write the result to an output stream.
1566
+ #
1567
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.
1568
+ # * +out_stream+ - The output stream that will contain the conversion output.
1569
+ def convertFileToStream(file, out_stream)
1570
+ if (!(File.file?(file) && !File.zero?(file)))
1571
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
1572
+ end
1573
+
1574
+ if (!(File.file?(file) && !File.zero?(file)))
1575
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "html-to-image", "The file name must have a valid extension.", "convert_file_to_stream"), 470);
1576
+ end
1577
+
1578
+ @files['file'] = file
1579
+ @helper.post(@fields, @files, @raw_data, out_stream)
1580
+ end
1581
+
1582
+ # Convert a local file and write the result to a local file.
1583
+ #
1584
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty. The file name must have a valid extension.
1585
+ # * +file_path+ - The output file path. The string must not be empty.
1586
+ def convertFileToFile(file, file_path)
1587
+ if (!(!file_path.nil? && !file_path.empty?))
1588
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "html-to-image", "The string must not be empty.", "convert_file_to_file"), 470);
1589
+ end
1590
+
1591
+ output_file = open(file_path, "wb")
1592
+ convertFileToStream(file, output_file)
1593
+ output_file.close()
1594
+ end
1595
+
1596
+ # Convert a string.
1597
+ #
1598
+ # * +text+ - The string content to convert. The string must not be empty.
1599
+ # * *Returns* - Byte array containing the conversion output.
1600
+ def convertString(text)
1601
+ if (!(!text.nil? && !text.empty?))
1602
+ raise Error.new(Pdfcrowd.create_invalid_value_message(text, "text", "html-to-image", "The string must not be empty.", "convert_string"), 470);
1603
+ end
1604
+
1605
+ @fields['text'] = text
1606
+ @helper.post(@fields, @files, @raw_data)
1607
+ end
1608
+
1609
+ # Convert a string and write the output to an output stream.
1610
+ #
1611
+ # * +text+ - The string content to convert. The string must not be empty.
1612
+ # * +out_stream+ - The output stream that will contain the conversion output.
1613
+ def convertStringToStream(text, out_stream)
1614
+ if (!(!text.nil? && !text.empty?))
1615
+ raise Error.new(Pdfcrowd.create_invalid_value_message(text, "text", "html-to-image", "The string must not be empty.", "convert_string_to_stream"), 470);
1616
+ end
1617
+
1618
+ @fields['text'] = text
1619
+ @helper.post(@fields, @files, @raw_data, out_stream)
1620
+ end
1621
+
1622
+ # Convert a string and write the output to a file.
1623
+ #
1624
+ # * +text+ - The string content to convert. The string must not be empty.
1625
+ # * +file_path+ - The output file path. The string must not be empty.
1626
+ def convertStringToFile(text, file_path)
1627
+ if (!(!file_path.nil? && !file_path.empty?))
1628
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "html-to-image", "The string must not be empty.", "convert_string_to_file"), 470);
1629
+ end
1630
+
1631
+ output_file = open(file_path, "wb")
1632
+ convertStringToStream(text, output_file)
1633
+ output_file.close()
1634
+ end
1635
+
1636
+ # Do not print the background graphics.
1637
+ #
1638
+ # * +no_background+ - Set to true to disable the background graphics.
1639
+ def setNoBackground(no_background)
1640
+ @fields['no_background'] = no_background
1641
+ end
1642
+
1643
+ # Do not execute JavaScript.
1644
+ #
1645
+ # * +disable_javascript+ - Set to true to disable JavaScript in web pages.
1646
+ def setDisableJavascript(disable_javascript)
1647
+ @fields['disable_javascript'] = disable_javascript
1648
+ end
1649
+
1650
+ # Do not load images.
1651
+ #
1652
+ # * +disable_image_loading+ - Set to true to disable loading of images.
1653
+ def setDisableImageLoading(disable_image_loading)
1654
+ @fields['disable_image_loading'] = disable_image_loading
1655
+ end
1656
+
1657
+ # Disable loading fonts from remote sources.
1658
+ #
1659
+ # * +disable_remote_fonts+ - Set to true disable loading remote fonts.
1660
+ def setDisableRemoteFonts(disable_remote_fonts)
1661
+ @fields['disable_remote_fonts'] = disable_remote_fonts
1662
+ end
1663
+
1664
+ # Set the default HTML content text encoding.
1665
+ #
1666
+ # * +default_encoding+ - The text encoding of the HTML content.
1667
+ def setDefaultEncoding(default_encoding)
1668
+ @fields['default_encoding'] = default_encoding
1669
+ end
1670
+
1671
+ # Set the HTTP authentication user name.
1672
+ #
1673
+ # * +user_name+ - The user name.
1674
+ def setHttpAuthUserName(user_name)
1675
+ @fields['http_auth_user_name'] = user_name
1676
+ end
1677
+
1678
+ # Set the HTTP authentication password.
1679
+ #
1680
+ # * +password+ - The password.
1681
+ def setHttpAuthPassword(password)
1682
+ @fields['http_auth_password'] = password
1683
+ end
1684
+
1685
+ # Set the HTTP authentication.
1686
+ #
1687
+ # * +user_name+ - Set the HTTP authentication user name.
1688
+ # * +password+ - Set the HTTP authentication password.
1689
+ def setHttpAuth(user_name, password)
1690
+ setHttpAuthUserName(user_name)
1691
+ setHttpAuthPassword(password)
1692
+ end
1693
+
1694
+ # Use the print version of the page if available (@media print).
1695
+ #
1696
+ # * +use_print_media+ - Set to true to use the print version of the page.
1697
+ def setUsePrintMedia(use_print_media)
1698
+ @fields['use_print_media'] = use_print_media
1699
+ end
1700
+
1701
+ # Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
1702
+ #
1703
+ # * +no_xpdfcrowd_header+ - Set to true to disable sending X-Pdfcrowd HTTP header.
1704
+ def setNoXpdfcrowdHeader(no_xpdfcrowd_header)
1705
+ @fields['no_xpdfcrowd_header'] = no_xpdfcrowd_header
1706
+ end
1707
+
1708
+ # Set cookies that are sent in Pdfcrowd HTTP requests.
1709
+ #
1710
+ # * +cookies+ - The cookie string.
1711
+ def setCookies(cookies)
1712
+ @fields['cookies'] = cookies
1713
+ end
1714
+
1715
+ # Do not allow insecure HTTPS connections.
1716
+ #
1717
+ # * +verify_ssl_certificates+ - Set to true to enable SSL certificate verification.
1718
+ def setVerifySslCertificates(verify_ssl_certificates)
1719
+ @fields['verify_ssl_certificates'] = verify_ssl_certificates
1720
+ end
1721
+
1722
+ # Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
1723
+ #
1724
+ # * +fail_on_error+ - Set to true to abort the conversion.
1725
+ def setFailOnMainUrlError(fail_on_error)
1726
+ @fields['fail_on_main_url_error'] = fail_on_error
1727
+ end
1728
+
1729
+ # Abort the conversion if any of the sub-request HTTP status code is greater than or equal to 400.
1730
+ #
1731
+ # * +fail_on_error+ - Set to true to abort the conversion.
1732
+ def setFailOnAnyUrlError(fail_on_error)
1733
+ @fields['fail_on_any_url_error'] = fail_on_error
1734
+ end
1735
+
1736
+ # Run a custom JavaScript after the document is loaded. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, ...).
1737
+ #
1738
+ # * +custom_javascript+ - String containing a JavaScript code. The string must not be empty.
1739
+ def setCustomJavascript(custom_javascript)
1740
+ if (!(!custom_javascript.nil? && !custom_javascript.empty?))
1741
+ raise Error.new(Pdfcrowd.create_invalid_value_message(custom_javascript, "custom_javascript", "html-to-image", "The string must not be empty.", "set_custom_javascript"), 470);
1742
+ end
1743
+
1744
+ @fields['custom_javascript'] = custom_javascript
1745
+ end
1746
+
1747
+ # Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
1748
+ #
1749
+ # * +custom_http_header+ - A string containing the header name and value separated by a colon.
1750
+ def setCustomHttpHeader(custom_http_header)
1751
+ unless /^.+:.+$/.match(custom_http_header)
1752
+ raise Error.new(Pdfcrowd.create_invalid_value_message(custom_http_header, "custom_http_header", "html-to-image", "A string containing the header name and value separated by a colon.", "set_custom_http_header"), 470);
1753
+ end
1754
+
1755
+ @fields['custom_http_header'] = custom_http_header
1756
+ end
1757
+
1758
+ # Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. The maximum value is determined by your API license.
1759
+ #
1760
+ # * +javascript_delay+ - The number of milliseconds to wait. Must be a positive integer number or 0.
1761
+ def setJavascriptDelay(javascript_delay)
1762
+ if (!(Integer(javascript_delay) >= 0))
1763
+ raise Error.new(Pdfcrowd.create_invalid_value_message(javascript_delay, "javascript_delay", "html-to-image", "Must be a positive integer number or 0.", "set_javascript_delay"), 470);
1764
+ end
1765
+
1766
+ @fields['javascript_delay'] = javascript_delay
1767
+ end
1768
+
1769
+ # Convert only the specified element and its children. The element is specified by one or more CSS selectors. If the element is not found, the conversion fails. If multiple elements are found, the first one is used.
1770
+ #
1771
+ # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1772
+ def setElementToConvert(selectors)
1773
+ if (!(!selectors.nil? && !selectors.empty?))
1774
+ raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "selectors", "html-to-image", "The string must not be empty.", "set_element_to_convert"), 470);
1775
+ end
1776
+
1777
+ @fields['element_to_convert'] = selectors
1778
+ end
1779
+
1780
+ # Specify the DOM handling when only a part of the document is converted.
1781
+ #
1782
+ # * +mode+ - Allowed values are cut-out, remove-siblings, hide-siblings.
1783
+ def setElementToConvertMode(mode)
1784
+ unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode)
1785
+ raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "mode", "html-to-image", "Allowed values are cut-out, remove-siblings, hide-siblings.", "set_element_to_convert_mode"), 470);
1786
+ end
1787
+
1788
+ @fields['element_to_convert_mode'] = mode
1789
+ end
1790
+
1791
+ # Wait for the specified element in a source document. The element is specified by one or more CSS selectors. If the element is not found, the conversion fails.
1792
+ #
1793
+ # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1794
+ def setWaitForElement(selectors)
1795
+ if (!(!selectors.nil? && !selectors.empty?))
1796
+ raise Error.new(Pdfcrowd.create_invalid_value_message(selectors, "selectors", "html-to-image", "The string must not be empty.", "set_wait_for_element"), 470);
1797
+ end
1798
+
1799
+ @fields['wait_for_element'] = selectors
1800
+ end
1801
+
1802
+ # Set the output image width in pixels.
1803
+ #
1804
+ # * +screenshot_width+ - The value must be in a range 96-7680.
1805
+ def setScreenshotWidth(screenshot_width)
1806
+ if (!(Integer(screenshot_width) >= 96 && Integer(screenshot_width) <= 7680))
1807
+ raise Error.new(Pdfcrowd.create_invalid_value_message(screenshot_width, "screenshot_width", "html-to-image", "The value must be in a range 96-7680.", "set_screenshot_width"), 470);
1808
+ end
1809
+
1810
+ @fields['screenshot_width'] = screenshot_width
1811
+ end
1812
+
1813
+ # Set the output image height in pixels. If it's not specified, actual document height is used.
1814
+ #
1815
+ # * +screenshot_height+ - Must be a positive integer number.
1816
+ def setScreenshotHeight(screenshot_height)
1817
+ if (!(Integer(screenshot_height) > 0))
1818
+ raise Error.new(Pdfcrowd.create_invalid_value_message(screenshot_height, "screenshot_height", "html-to-image", "Must be a positive integer number.", "set_screenshot_height"), 470);
1819
+ end
1820
+
1821
+ @fields['screenshot_height'] = screenshot_height
1822
+ end
1823
+
1824
+ # Turn on the debug logging.
1825
+ #
1826
+ # * +debug_log+ - Set to true to enable the debug logging.
1827
+ def setDebugLog(debug_log)
1828
+ @fields['debug_log'] = debug_log
1829
+ end
1830
+
1831
+ # Get the URL of the debug log for the last conversion.
1832
+ # * *Returns* - The link to the debug log.
1833
+ def getDebugLogUrl()
1834
+ return @helper.getDebugLogUrl()
1835
+ end
1836
+
1837
+ # Get the number of conversion credits available in your account.
1838
+ # The returned value can differ from the actual count if you run parallel conversions.
1839
+ # The special value 999999 is returned if the information is not available.
1840
+ # * *Returns* - The number of credits.
1841
+ def getRemainingCreditCount()
1842
+ return @helper.getRemainingCreditCount()
1843
+ end
1844
+
1845
+ # Get the number of credits consumed by the last conversion.
1846
+ # * *Returns* - The number of credits.
1847
+ def getConsumedCreditCount()
1848
+ return @helper.getConsumedCreditCount()
1849
+ end
1850
+
1851
+ # Get the job id.
1852
+ # * *Returns* - The unique job identifier.
1853
+ def getJobId()
1854
+ return @helper.getJobId()
1855
+ end
1856
+
1857
+ # Get the size of the output in bytes.
1858
+ # * *Returns* - The count of bytes.
1859
+ def getOutputSize()
1860
+ return @helper.getOutputSize()
1861
+ end
1862
+
1863
+ # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
1864
+ #
1865
+ # * +use_http+ - Set to true to use HTTP.
1866
+ def setUseHttp(use_http)
1867
+ @helper.setUseHttp(use_http)
1868
+ end
1869
+
1870
+ # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
1871
+ #
1872
+ # * +user_agent+ - The user agent string.
1873
+ def setUserAgent(user_agent)
1874
+ @helper.setUserAgent(user_agent)
1875
+ end
1876
+
1877
+ # Specifies an HTTP proxy that the API client library will use to connect to the internet.
1878
+ #
1879
+ # * +host+ - The proxy hostname.
1880
+ # * +port+ - The proxy port.
1881
+ # * +user_name+ - The username.
1882
+ # * +password+ - The password.
1883
+ def setProxy(host, port, user_name, password)
1884
+ @helper.setProxy(host, port, user_name, password)
1885
+ end
1886
+
1887
+ end
1888
+
1889
+ # Conversion from one image format to another image format.
1890
+ class ImageToImageClient
1891
+ # Constructor for the Pdfcrowd API client.
1892
+ #
1893
+ # * +user_name+ - Your username at Pdfcrowd.
1894
+ # * +api_key+ - Your API key.
1895
+ def initialize(user_name, api_key)
1896
+ @helper = ConnectionHelper.new(user_name, api_key)
1897
+ @fields = {
1898
+ 'input_format'=>'image',
1899
+ 'output_format'=>'png'
1900
+ }
1901
+ @file_id = 1
1902
+ @files = {}
1903
+ @raw_data = {}
1904
+ end
1905
+
1906
+ # Convert an image.
1907
+ #
1908
+ # * +url+ - The address of the image to convert. The supported protocols are http:// and https://.
1909
+ # * *Returns* - Byte array containing the conversion output.
1910
+ def convertUrl(url)
1911
+ unless /(?i)^https?:\/\/.*$/.match(url)
1912
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "image-to-image", "The supported protocols are http:// and https://.", "convert_url"), 470);
1913
+ end
1914
+
1915
+ @fields['url'] = url
1916
+ @helper.post(@fields, @files, @raw_data)
1917
+ end
1918
+
1919
+ # Convert an image and write the result to an output stream.
1920
+ #
1921
+ # * +url+ - The address of the image to convert. The supported protocols are http:// and https://.
1922
+ # * +out_stream+ - The output stream that will contain the conversion output.
1923
+ def convertUrlToStream(url, out_stream)
1924
+ unless /(?i)^https?:\/\/.*$/.match(url)
1925
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "image-to-image", "The supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
1926
+ end
1927
+
1928
+ @fields['url'] = url
1929
+ @helper.post(@fields, @files, @raw_data, out_stream)
1930
+ end
1931
+
1932
+ # Convert an image and write the result to a local file.
1933
+ #
1934
+ # * +url+ - The address of the image to convert. The supported protocols are http:// and https://.
1935
+ # * +file_path+ - The output file path. The string must not be empty.
1936
+ def convertUrlToFile(url, file_path)
1937
+ if (!(!file_path.nil? && !file_path.empty?))
1938
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "image-to-image", "The string must not be empty.", "convert_url_to_file"), 470);
1939
+ end
1940
+
1941
+ output_file = open(file_path, "wb")
1942
+ convertUrlToStream(url, output_file)
1943
+ output_file.close()
1944
+ end
1945
+
1946
+ # Convert a local file.
1947
+ #
1948
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty.
1949
+ # * *Returns* - Byte array containing the conversion output.
1950
+ def convertFile(file)
1951
+ if (!(File.file?(file) && !File.zero?(file)))
1952
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "image-to-image", "The file must exist and not be empty.", "convert_file"), 470);
1953
+ end
1954
+
1955
+ @files['file'] = file
1956
+ @helper.post(@fields, @files, @raw_data)
1957
+ end
1958
+
1959
+ # Convert a local file and write the result to an output stream.
1960
+ #
1961
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty.
1962
+ # * +out_stream+ - The output stream that will contain the conversion output.
1963
+ def convertFileToStream(file, out_stream)
1964
+ if (!(File.file?(file) && !File.zero?(file)))
1965
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "image-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
1966
+ end
1967
+
1968
+ @files['file'] = file
1969
+ @helper.post(@fields, @files, @raw_data, out_stream)
1970
+ end
1971
+
1972
+ # Convert a local file and write the result to a local file.
1973
+ #
1974
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty.
1975
+ # * +file_path+ - The output file path. The string must not be empty.
1976
+ def convertFileToFile(file, file_path)
1977
+ if (!(!file_path.nil? && !file_path.empty?))
1978
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "image-to-image", "The string must not be empty.", "convert_file_to_file"), 470);
1979
+ end
1980
+
1981
+ output_file = open(file_path, "wb")
1982
+ convertFileToStream(file, output_file)
1983
+ output_file.close()
1984
+ end
1985
+
1986
+ # Convert raw data.
1987
+ #
1988
+ # * +data+ - The raw content to be converted.
1989
+ # * *Returns* - Byte array with the output.
1990
+ def convertRawData(data)
1991
+ @raw_data['file'] = data
1992
+ @helper.post(@fields, @files, @raw_data)
1993
+ end
1994
+
1995
+ # Convert raw data and write the result to an output stream.
1996
+ #
1997
+ # * +data+ - The raw content to be converted.
1998
+ # * +out_stream+ - The output stream that will contain the conversion output.
1999
+ def convertRawDataToStream(data, out_stream)
2000
+ @raw_data['file'] = data
2001
+ @helper.post(@fields, @files, @raw_data, out_stream)
2002
+ end
2003
+
2004
+ # Convert raw data to a file.
2005
+ #
2006
+ # * +data+ - The raw content to be converted.
2007
+ # * +file_path+ - The output file path. The string must not be empty.
2008
+ def convertRawDataToFile(data, file_path)
2009
+ if (!(!file_path.nil? && !file_path.empty?))
2010
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "image-to-image", "The string must not be empty.", "convert_raw_data_to_file"), 470);
2011
+ end
2012
+
2013
+ output_file = open(file_path, "wb")
2014
+ convertRawDataToStream(data, output_file)
2015
+ output_file.close()
2016
+ end
2017
+
2018
+ # The format of the output file.
2019
+ #
2020
+ # * +output_format+ - Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.
2021
+ def setOutputFormat(output_format)
2022
+ unless /(?i)^(png|jpg|gif|tiff|bmp|ico|ppm|pgm|pbm|pnm|psb|pct|ras|tga|sgi|sun|webp)$/.match(output_format)
2023
+ raise Error.new(Pdfcrowd.create_invalid_value_message(output_format, "output_format", "image-to-image", "Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.", "set_output_format"), 470);
2024
+ end
2025
+
2026
+ @fields['output_format'] = output_format
2027
+ end
2028
+
2029
+ # Resize the image.
2030
+ #
2031
+ # * +resize+ - The resize percentage or new image dimensions.
2032
+ def setResize(resize)
2033
+ @fields['resize'] = resize
2034
+ end
2035
+
2036
+ # Rotate the image.
2037
+ #
2038
+ # * +rotate+ - The rotation specified in degrees.
2039
+ def setRotate(rotate)
2040
+ @fields['rotate'] = rotate
2041
+ end
2042
+
2043
+ # Turn on the debug logging.
2044
+ #
2045
+ # * +debug_log+ - Set to true to enable the debug logging.
2046
+ def setDebugLog(debug_log)
2047
+ @fields['debug_log'] = debug_log
2048
+ end
2049
+
2050
+ # Get the URL of the debug log for the last conversion.
2051
+ # * *Returns* - The link to the debug log.
2052
+ def getDebugLogUrl()
2053
+ return @helper.getDebugLogUrl()
2054
+ end
2055
+
2056
+ # Get the number of conversion credits available in your account.
2057
+ # The returned value can differ from the actual count if you run parallel conversions.
2058
+ # The special value 999999 is returned if the information is not available.
2059
+ # * *Returns* - The number of credits.
2060
+ def getRemainingCreditCount()
2061
+ return @helper.getRemainingCreditCount()
2062
+ end
2063
+
2064
+ # Get the number of credits consumed by the last conversion.
2065
+ # * *Returns* - The number of credits.
2066
+ def getConsumedCreditCount()
2067
+ return @helper.getConsumedCreditCount()
2068
+ end
2069
+
2070
+ # Get the job id.
2071
+ # * *Returns* - The unique job identifier.
2072
+ def getJobId()
2073
+ return @helper.getJobId()
2074
+ end
2075
+
2076
+ # Get the size of the output in bytes.
2077
+ # * *Returns* - The count of bytes.
2078
+ def getOutputSize()
2079
+ return @helper.getOutputSize()
2080
+ end
2081
+
2082
+ # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
2083
+ #
2084
+ # * +use_http+ - Set to true to use HTTP.
2085
+ def setUseHttp(use_http)
2086
+ @helper.setUseHttp(use_http)
2087
+ end
2088
+
2089
+ # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
2090
+ #
2091
+ # * +user_agent+ - The user agent string.
2092
+ def setUserAgent(user_agent)
2093
+ @helper.setUserAgent(user_agent)
2094
+ end
2095
+
2096
+ # Specifies an HTTP proxy that the API client library will use to connect to the internet.
2097
+ #
2098
+ # * +host+ - The proxy hostname.
2099
+ # * +port+ - The proxy port.
2100
+ # * +user_name+ - The username.
2101
+ # * +password+ - The password.
2102
+ def setProxy(host, port, user_name, password)
2103
+ @helper.setProxy(host, port, user_name, password)
2104
+ end
2105
+
2106
+ end
2107
+
2108
+ # Conversion from PDF to PDF.
2109
+ class PdfToPdfClient
2110
+ # Constructor for the Pdfcrowd API client.
2111
+ #
2112
+ # * +user_name+ - Your username at Pdfcrowd.
2113
+ # * +api_key+ - Your API key.
2114
+ def initialize(user_name, api_key)
2115
+ @helper = ConnectionHelper.new(user_name, api_key)
2116
+ @fields = {
2117
+ 'input_format'=>'pdf',
2118
+ 'output_format'=>'pdf'
2119
+ }
2120
+ @file_id = 1
2121
+ @files = {}
2122
+ @raw_data = {}
2123
+ end
2124
+
2125
+ # Specifies the action to be performed on the input PDFs.
2126
+ #
2127
+ # * +action+ - Allowed values are join, shuffle.
2128
+ def setAction(action)
2129
+ unless /(?i)^(join|shuffle)$/.match(action)
2130
+ raise Error.new(Pdfcrowd.create_invalid_value_message(action, "action", "pdf-to-pdf", "Allowed values are join, shuffle.", "set_action"), 470);
2131
+ end
2132
+
2133
+ @fields['action'] = action
2134
+ end
2135
+
2136
+ # Perform an action on the input files.
2137
+ # * *Returns* - Byte array containing the output PDF.
2138
+ def convertFiles()
2139
+ @helper.post(@fields, @files, @raw_data)
2140
+ end
2141
+
2142
+ # Perform an action on the input files and write the output PDF to an output stream.
2143
+ #
2144
+ # * +out_stream+ - The output stream that will contain the output PDF.
2145
+ def convertFilesToStream(out_stream)
2146
+ @helper.post(@fields, @files, @raw_data, out_stream)
2147
+ end
2148
+
2149
+ # Perform an action on the input files and write the output PDF to a file.
2150
+ #
2151
+ # * +file_path+ - The output file path. The string must not be empty.
2152
+ def convertFilesToFile(file_path)
2153
+ if (!(!file_path.nil? && !file_path.empty?))
2154
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "pdf-to-pdf", "The string must not be empty.", "convert_files_to_file"), 470);
2155
+ end
2156
+
2157
+ output_file = open(file_path, "wb")
2158
+ convertFilesToStream(output_file)
2159
+ output_file.close()
2160
+ end
2161
+
2162
+ # Add a PDF file to the list of the input PDFs.
2163
+ #
2164
+ # * +file_path+ - The file path to a local PDF file. The file must exist and not be empty.
2165
+ def addPdfFile(file_path)
2166
+ if (!(File.file?(file_path) && !File.zero?(file_path)))
2167
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "pdf-to-pdf", "The file must exist and not be empty.", "add_pdf_file"), 470);
2168
+ end
2169
+
2170
+ @files['f_%s' % @file_id] = file_path
2171
+ @file_id += 1
2172
+ end
2173
+
2174
+ # Add in-memory raw PDF data to the list of the input PDFs.
2175
+ #
2176
+ # * +pdf_raw_data+ - The raw PDF data. The input data must be PDF content.
2177
+ def addPdfRawData(pdf_raw_data)
2178
+ if (!(!pdf_raw_data.nil? && pdf_raw_data.length > 300 and pdf_raw_data[0...4] == '%PDF'))
2179
+ raise Error.new(Pdfcrowd.create_invalid_value_message("raw PDF data", "pdf_raw_data", "pdf-to-pdf", "The input data must be PDF content.", "add_pdf_raw_data"), 470);
2180
+ end
2181
+
2182
+ @raw_data['f_%s' % @file_id] = pdf_raw_data
2183
+ @file_id += 1
2184
+ end
2185
+
2186
+ # Turn on the debug logging.
2187
+ #
2188
+ # * +debug_log+ - Set to true to enable the debug logging.
2189
+ def setDebugLog(debug_log)
2190
+ @fields['debug_log'] = debug_log
2191
+ end
2192
+
2193
+ # Get the URL of the debug log for the last conversion.
2194
+ # * *Returns* - The link to the debug log.
2195
+ def getDebugLogUrl()
2196
+ return @helper.getDebugLogUrl()
2197
+ end
2198
+
2199
+ # Get the number of conversion credits available in your account.
2200
+ # The returned value can differ from the actual count if you run parallel conversions.
2201
+ # The special value 999999 is returned if the information is not available.
2202
+ # * *Returns* - The number of credits.
2203
+ def getRemainingCreditCount()
2204
+ return @helper.getRemainingCreditCount()
2205
+ end
2206
+
2207
+ # Get the number of credits consumed by the last conversion.
2208
+ # * *Returns* - The number of credits.
2209
+ def getConsumedCreditCount()
2210
+ return @helper.getConsumedCreditCount()
2211
+ end
2212
+
2213
+ # Get the job id.
2214
+ # * *Returns* - The unique job identifier.
2215
+ def getJobId()
2216
+ return @helper.getJobId()
2217
+ end
2218
+
2219
+ # Get the total number of pages in the output document.
2220
+ # * *Returns* - The page count.
2221
+ def getPageCount()
2222
+ return @helper.getPageCount()
2223
+ end
2224
+
2225
+ # Get the size of the output in bytes.
2226
+ # * *Returns* - The count of bytes.
2227
+ def getOutputSize()
2228
+ return @helper.getOutputSize()
2229
+ end
2230
+
2231
+ # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
2232
+ #
2233
+ # * +use_http+ - Set to true to use HTTP.
2234
+ def setUseHttp(use_http)
2235
+ @helper.setUseHttp(use_http)
2236
+ end
2237
+
2238
+ # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
2239
+ #
2240
+ # * +user_agent+ - The user agent string.
2241
+ def setUserAgent(user_agent)
2242
+ @helper.setUserAgent(user_agent)
2243
+ end
2244
+
2245
+ # Specifies an HTTP proxy that the API client library will use to connect to the internet.
2246
+ #
2247
+ # * +host+ - The proxy hostname.
2248
+ # * +port+ - The proxy port.
2249
+ # * +user_name+ - The username.
2250
+ # * +password+ - The password.
2251
+ def setProxy(host, port, user_name, password)
2252
+ @helper.setProxy(host, port, user_name, password)
2253
+ end
2254
+
2255
+ end
2256
+
2257
+ # Conversion from an image to PDF.
2258
+ class ImageToPdfClient
2259
+ # Constructor for the Pdfcrowd API client.
2260
+ #
2261
+ # * +user_name+ - Your username at Pdfcrowd.
2262
+ # * +api_key+ - Your API key.
2263
+ def initialize(user_name, api_key)
2264
+ @helper = ConnectionHelper.new(user_name, api_key)
2265
+ @fields = {
2266
+ 'input_format'=>'image',
2267
+ 'output_format'=>'pdf'
2268
+ }
2269
+ @file_id = 1
2270
+ @files = {}
2271
+ @raw_data = {}
2272
+ end
2273
+
2274
+ # Convert an image.
2275
+ #
2276
+ # * +url+ - The address of the image to convert. The supported protocols are http:// and https://.
2277
+ # * *Returns* - Byte array containing the conversion output.
2278
+ def convertUrl(url)
2279
+ unless /(?i)^https?:\/\/.*$/.match(url)
2280
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "image-to-pdf", "The supported protocols are http:// and https://.", "convert_url"), 470);
2281
+ end
2282
+
2283
+ @fields['url'] = url
2284
+ @helper.post(@fields, @files, @raw_data)
2285
+ end
2286
+
2287
+ # Convert an image and write the result to an output stream.
2288
+ #
2289
+ # * +url+ - The address of the image to convert. The supported protocols are http:// and https://.
2290
+ # * +out_stream+ - The output stream that will contain the conversion output.
2291
+ def convertUrlToStream(url, out_stream)
2292
+ unless /(?i)^https?:\/\/.*$/.match(url)
2293
+ raise Error.new(Pdfcrowd.create_invalid_value_message(url, "url", "image-to-pdf", "The supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
2294
+ end
2295
+
2296
+ @fields['url'] = url
2297
+ @helper.post(@fields, @files, @raw_data, out_stream)
2298
+ end
2299
+
2300
+ # Convert an image and write the result to a local file.
2301
+ #
2302
+ # * +url+ - The address of the image to convert. The supported protocols are http:// and https://.
2303
+ # * +file_path+ - The output file path. The string must not be empty.
2304
+ def convertUrlToFile(url, file_path)
2305
+ if (!(!file_path.nil? && !file_path.empty?))
2306
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "image-to-pdf", "The string must not be empty.", "convert_url_to_file"), 470);
2307
+ end
2308
+
2309
+ output_file = open(file_path, "wb")
2310
+ convertUrlToStream(url, output_file)
2311
+ output_file.close()
2312
+ end
2313
+
2314
+ # Convert a local file.
2315
+ #
2316
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty.
2317
+ # * *Returns* - Byte array containing the conversion output.
2318
+ def convertFile(file)
2319
+ if (!(File.file?(file) && !File.zero?(file)))
2320
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "image-to-pdf", "The file must exist and not be empty.", "convert_file"), 470);
2321
+ end
2322
+
2323
+ @files['file'] = file
2324
+ @helper.post(@fields, @files, @raw_data)
2325
+ end
2326
+
2327
+ # Convert a local file and write the result to an output stream.
2328
+ #
2329
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty.
2330
+ # * +out_stream+ - The output stream that will contain the conversion output.
2331
+ def convertFileToStream(file, out_stream)
2332
+ if (!(File.file?(file) && !File.zero?(file)))
2333
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file, "file", "image-to-pdf", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
2334
+ end
2335
+
2336
+ @files['file'] = file
2337
+ @helper.post(@fields, @files, @raw_data, out_stream)
2338
+ end
2339
+
2340
+ # Convert a local file and write the result to a local file.
2341
+ #
2342
+ # * +file+ - The path to a local file to convert. The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). The file must exist and not be empty.
2343
+ # * +file_path+ - The output file path. The string must not be empty.
2344
+ def convertFileToFile(file, file_path)
2345
+ if (!(!file_path.nil? && !file_path.empty?))
2346
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "image-to-pdf", "The string must not be empty.", "convert_file_to_file"), 470);
2347
+ end
2348
+
2349
+ output_file = open(file_path, "wb")
2350
+ convertFileToStream(file, output_file)
2351
+ output_file.close()
2352
+ end
2353
+
2354
+ # Convert raw data.
2355
+ #
2356
+ # * +data+ - The raw content to be converted.
2357
+ # * *Returns* - Byte array with the output.
2358
+ def convertRawData(data)
2359
+ @raw_data['file'] = data
2360
+ @helper.post(@fields, @files, @raw_data)
2361
+ end
2362
+
2363
+ # Convert raw data and write the result to an output stream.
2364
+ #
2365
+ # * +data+ - The raw content to be converted.
2366
+ # * +out_stream+ - The output stream that will contain the conversion output.
2367
+ def convertRawDataToStream(data, out_stream)
2368
+ @raw_data['file'] = data
2369
+ @helper.post(@fields, @files, @raw_data, out_stream)
2370
+ end
2371
+
2372
+ # Convert raw data to a file.
2373
+ #
2374
+ # * +data+ - The raw content to be converted.
2375
+ # * +file_path+ - The output file path. The string must not be empty.
2376
+ def convertRawDataToFile(data, file_path)
2377
+ if (!(!file_path.nil? && !file_path.empty?))
2378
+ raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "file_path", "image-to-pdf", "The string must not be empty.", "convert_raw_data_to_file"), 470);
2379
+ end
2380
+
2381
+ output_file = open(file_path, "wb")
2382
+ convertRawDataToStream(data, output_file)
2383
+ output_file.close()
2384
+ end
2385
+
2386
+ # Resize the image.
2387
+ #
2388
+ # * +resize+ - The resize percentage or new image dimensions.
2389
+ def setResize(resize)
2390
+ @fields['resize'] = resize
2391
+ end
2392
+
2393
+ # Rotate the image.
2394
+ #
2395
+ # * +rotate+ - The rotation specified in degrees.
2396
+ def setRotate(rotate)
2397
+ @fields['rotate'] = rotate
2398
+ end
2399
+
2400
+ # Turn on the debug logging.
2401
+ #
2402
+ # * +debug_log+ - Set to true to enable the debug logging.
2403
+ def setDebugLog(debug_log)
2404
+ @fields['debug_log'] = debug_log
2405
+ end
2406
+
2407
+ # Get the URL of the debug log for the last conversion.
2408
+ # * *Returns* - The link to the debug log.
2409
+ def getDebugLogUrl()
2410
+ return @helper.getDebugLogUrl()
2411
+ end
2412
+
2413
+ # Get the number of conversion credits available in your account.
2414
+ # The returned value can differ from the actual count if you run parallel conversions.
2415
+ # The special value 999999 is returned if the information is not available.
2416
+ # * *Returns* - The number of credits.
2417
+ def getRemainingCreditCount()
2418
+ return @helper.getRemainingCreditCount()
2419
+ end
2420
+
2421
+ # Get the number of credits consumed by the last conversion.
2422
+ # * *Returns* - The number of credits.
2423
+ def getConsumedCreditCount()
2424
+ return @helper.getConsumedCreditCount()
2425
+ end
2426
+
2427
+ # Get the job id.
2428
+ # * *Returns* - The unique job identifier.
2429
+ def getJobId()
2430
+ return @helper.getJobId()
2431
+ end
2432
+
2433
+ # Get the size of the output in bytes.
2434
+ # * *Returns* - The count of bytes.
2435
+ def getOutputSize()
2436
+ return @helper.getOutputSize()
2437
+ end
2438
+
2439
+ # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
2440
+ #
2441
+ # * +use_http+ - Set to true to use HTTP.
2442
+ def setUseHttp(use_http)
2443
+ @helper.setUseHttp(use_http)
2444
+ end
2445
+
2446
+ # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
2447
+ #
2448
+ # * +user_agent+ - The user agent string.
2449
+ def setUserAgent(user_agent)
2450
+ @helper.setUserAgent(user_agent)
2451
+ end
2452
+
2453
+ # Specifies an HTTP proxy that the API client library will use to connect to the internet.
2454
+ #
2455
+ # * +host+ - The proxy hostname.
2456
+ # * +port+ - The proxy port.
2457
+ # * +user_name+ - The username.
2458
+ # * +password+ - The password.
2459
+ def setProxy(host, port, user_name, password)
2460
+ @helper.setProxy(host, port, user_name, password)
2461
+ end
2462
+
2463
+ end
2464
+
2465
+ end