pdfcrowd 4.0 → 4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pdfcrowd.rb +311 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d7fd03a483ab60b722a2878ea0667838d5b12ab
4
- data.tar.gz: f8689da21d07ad695fa0ad7cf0231c687348324c
3
+ metadata.gz: b63aefeb456c70b1fa6af7a8677bd1a6fcda18b8
4
+ data.tar.gz: df49260b940ac7d7783a07cffa279d5c5fa01edc
5
5
  SHA512:
6
- metadata.gz: 1520b0395cbc545cd9b09fd345283273ad94329601178efb56fa59c15e9d8661035e4687585a3f30e2ce8daf3f09f8bfa8751d905ad29ec82fcb26a7c271ed8a
7
- data.tar.gz: 5afa89ed4450d9a064b78ab9d60fce0643041304c2ab40d1a4af35efab111d6bf87b497de294f20557aeccf245990ac9c4e4b2ecc9f33f8139ff9a53bb8185a1
6
+ metadata.gz: 476693c1c3ebe0dbd666868fe6afde5b8618066d9f7a2a9bfc1432a9030e6ecc58e4864636e2808386ce2c4e34264c231e516f84ce01e15d9957d46439e56184
7
+ data.tar.gz: 15b43c707e9739d74ef94c85710c26ed68e16f5796598107ad0dc702759809ef2051ad068d74214700047f83f362afd66d928f50d503ac14c8faae1175acd8a3
data/lib/pdfcrowd.rb CHANGED
@@ -529,7 +529,7 @@ end
529
529
  module Pdfcrowd
530
530
  HOST = ENV["PDFCROWD_HOST"] || 'api.pdfcrowd.com'
531
531
  MULTIPART_BOUNDARY = '----------ThIs_Is_tHe_bOUnDary_$'
532
- CLIENT_VERSION = '4.0'
532
+ CLIENT_VERSION = '4.1'
533
533
 
534
534
  def self.float_to_string(value)
535
535
  value.to_s.sub(',', '.')
@@ -544,7 +544,9 @@ module Pdfcrowd
544
544
 
545
545
  setProxy(nil, nil, nil, nil)
546
546
  setUseHttp(false)
547
- setUserAgent('pdfcrowd_ruby_client/4.0 (http://pdfcrowd.com)')
547
+ setUserAgent('pdfcrowd_ruby_client/4.1 (http://pdfcrowd.com)')
548
+
549
+ @retry_count = 1
548
550
  end
549
551
 
550
552
  def post(fields, files, raw_data, out_stream = nil)
@@ -559,6 +561,10 @@ module Pdfcrowd
559
561
  @user_agent = user_agent
560
562
  end
561
563
 
564
+ def setRetryCount(retry_count)
565
+ @retry_count = retry_count
566
+ end
567
+
562
568
  def setProxy(host, port, user_name, password)
563
569
  @proxy_host = host
564
570
  @proxy_port = port
@@ -599,6 +605,7 @@ module Pdfcrowd
599
605
  @job_id = ''
600
606
  @page_count = 0
601
607
  @output_size = 0
608
+ @retry = 0
602
609
  end
603
610
 
604
611
  def post_url_encoded(fields, out_stream)
@@ -670,7 +677,22 @@ module Pdfcrowd
670
677
 
671
678
  request.basic_auth(@user_name, @api_key)
672
679
  request.add_field('User-Agent', @user_agent)
673
-
680
+
681
+ while true
682
+ begin
683
+ return exec_request(request, out_stream)
684
+ rescue Error => err
685
+ if err.getCode() == '502' and @retry_count > @retry
686
+ @retry += 1
687
+ sleep(@retry * 0.1)
688
+ else
689
+ raise
690
+ end
691
+ end
692
+ end
693
+ end
694
+
695
+ def exec_request(request, out_stream)
674
696
  begin
675
697
  http = create_http_obj()
676
698
 
@@ -684,6 +706,10 @@ module Pdfcrowd
684
706
  @page_count = (response["X-Pdfcrowd-Pages"] || 0).to_i
685
707
  @output_size = (response["X-Pdfcrowd-Output-Size"] || 0).to_i
686
708
 
709
+ raise Error.new('test 502', '502') \
710
+ if ENV["PDFCROWD_UNIT_TEST_MODE"] and
711
+ @retry_count > @retry
712
+
687
713
  case response
688
714
  when Net::HTTPSuccess
689
715
  if out_stream
@@ -863,105 +889,125 @@ module Pdfcrowd
863
889
  # Set the output page size.
864
890
  #
865
891
  # * +page_size+ - Allowed values are A2, A3, A4, A5, A6, Letter.
892
+ # * *Returns* - The converter object.
866
893
  def setPageSize(page_size)
867
894
  unless /(?i)^(A2|A3|A4|A5|A6|Letter)$/.match(page_size)
868
895
  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
896
  end
870
897
 
871
898
  @fields['page_size'] = page_size
899
+ self
872
900
  end
873
901
 
874
902
  # Set the output page width.
875
903
  #
876
904
  # * +page_width+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
905
+ # * *Returns* - The converter object.
877
906
  def setPageWidth(page_width)
878
907
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(page_width)
879
908
  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
909
  end
881
910
 
882
911
  @fields['page_width'] = page_width
912
+ self
883
913
  end
884
914
 
885
915
  # Set the output page height.
886
916
  #
887
917
  # * +page_height+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
918
+ # * *Returns* - The converter object.
888
919
  def setPageHeight(page_height)
889
920
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(page_height)
890
921
  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
922
  end
892
923
 
893
924
  @fields['page_height'] = page_height
925
+ self
894
926
  end
895
927
 
896
928
  # Set the output page dimensions.
897
929
  #
898
930
  # * +width+ - Set the output page width. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
899
931
  # * +height+ - Set the output page height. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
932
+ # * *Returns* - The converter object.
900
933
  def setPageDimensions(width, height)
901
934
  setPageWidth(width)
902
935
  setPageHeight(height)
936
+ self
903
937
  end
904
938
 
905
939
  # Set the output page orientation.
906
940
  #
907
941
  # * +orientation+ - Allowed values are landscape, portrait.
942
+ # * *Returns* - The converter object.
908
943
  def setOrientation(orientation)
909
944
  unless /(?i)^(landscape|portrait)$/.match(orientation)
910
945
  raise Error.new(Pdfcrowd.create_invalid_value_message(orientation, "orientation", "html-to-pdf", "Allowed values are landscape, portrait.", "set_orientation"), 470);
911
946
  end
912
947
 
913
948
  @fields['orientation'] = orientation
949
+ self
914
950
  end
915
951
 
916
952
  # Set the output page top margin.
917
953
  #
918
954
  # * +margin_top+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
955
+ # * *Returns* - The converter object.
919
956
  def setMarginTop(margin_top)
920
957
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_top)
921
958
  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
959
  end
923
960
 
924
961
  @fields['margin_top'] = margin_top
962
+ self
925
963
  end
926
964
 
927
965
  # Set the output page right margin.
928
966
  #
929
967
  # * +margin_right+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
968
+ # * *Returns* - The converter object.
930
969
  def setMarginRight(margin_right)
931
970
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_right)
932
971
  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
972
  end
934
973
 
935
974
  @fields['margin_right'] = margin_right
975
+ self
936
976
  end
937
977
 
938
978
  # Set the output page bottom margin.
939
979
  #
940
980
  # * +margin_bottom+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
981
+ # * *Returns* - The converter object.
941
982
  def setMarginBottom(margin_bottom)
942
983
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_bottom)
943
984
  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
985
  end
945
986
 
946
987
  @fields['margin_bottom'] = margin_bottom
988
+ self
947
989
  end
948
990
 
949
991
  # Set the output page left margin.
950
992
  #
951
993
  # * +margin_left+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
994
+ # * *Returns* - The converter object.
952
995
  def setMarginLeft(margin_left)
953
996
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(margin_left)
954
997
  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
998
  end
956
999
 
957
1000
  @fields['margin_left'] = margin_left
1001
+ self
958
1002
  end
959
1003
 
960
1004
  # Disable margins.
961
1005
  #
962
1006
  # * +no_margins+ - Set to true to disable margins.
1007
+ # * *Returns* - The converter object.
963
1008
  def setNoMargins(no_margins)
964
1009
  @fields['no_margins'] = no_margins
1010
+ self
965
1011
  end
966
1012
 
967
1013
  # Set the output page margins.
@@ -970,447 +1016,554 @@ module Pdfcrowd
970
1016
  # * +right+ - Set the output page right margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
971
1017
  # * +bottom+ - Set the output page bottom margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
972
1018
  # * +left+ - Set the output page left margin. Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
1019
+ # * *Returns* - The converter object.
973
1020
  def setPageMargins(top, right, bottom, left)
974
1021
  setMarginTop(top)
975
1022
  setMarginRight(right)
976
1023
  setMarginBottom(bottom)
977
1024
  setMarginLeft(left)
1025
+ self
978
1026
  end
979
1027
 
980
1028
  # 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
1029
  #
982
1030
  # * +header_url+ - The supported protocols are http:// and https://.
1031
+ # * *Returns* - The converter object.
983
1032
  def setHeaderUrl(header_url)
984
1033
  unless /(?i)^https?:\/\/.*$/.match(header_url)
985
1034
  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
1035
  end
987
1036
 
988
1037
  @fields['header_url'] = header_url
1038
+ self
989
1039
  end
990
1040
 
991
1041
  # 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
1042
  #
993
1043
  # * +header_html+ - The string must not be empty.
1044
+ # * *Returns* - The converter object.
994
1045
  def setHeaderHtml(header_html)
995
1046
  if (!(!header_html.nil? && !header_html.empty?))
996
1047
  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
1048
  end
998
1049
 
999
1050
  @fields['header_html'] = header_html
1051
+ self
1000
1052
  end
1001
1053
 
1002
1054
  # Set the header height.
1003
1055
  #
1004
1056
  # * +header_height+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
1057
+ # * *Returns* - The converter object.
1005
1058
  def setHeaderHeight(header_height)
1006
1059
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(header_height)
1007
1060
  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
1061
  end
1009
1062
 
1010
1063
  @fields['header_height'] = header_height
1064
+ self
1011
1065
  end
1012
1066
 
1013
1067
  # 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
1068
  #
1015
1069
  # * +footer_url+ - The supported protocols are http:// and https://.
1070
+ # * *Returns* - The converter object.
1016
1071
  def setFooterUrl(footer_url)
1017
1072
  unless /(?i)^https?:\/\/.*$/.match(footer_url)
1018
1073
  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
1074
  end
1020
1075
 
1021
1076
  @fields['footer_url'] = footer_url
1077
+ self
1022
1078
  end
1023
1079
 
1024
1080
  # 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
1081
  #
1026
1082
  # * +footer_html+ - The string must not be empty.
1083
+ # * *Returns* - The converter object.
1027
1084
  def setFooterHtml(footer_html)
1028
1085
  if (!(!footer_html.nil? && !footer_html.empty?))
1029
1086
  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
1087
  end
1031
1088
 
1032
1089
  @fields['footer_html'] = footer_html
1090
+ self
1033
1091
  end
1034
1092
 
1035
1093
  # Set the footer height.
1036
1094
  #
1037
1095
  # * +footer_height+ - Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
1096
+ # * *Returns* - The converter object.
1038
1097
  def setFooterHeight(footer_height)
1039
1098
  unless /(?i)^[0-9]*(\.[0-9]+)?(pt|px|mm|cm|in)$/.match(footer_height)
1040
1099
  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
1100
  end
1042
1101
 
1043
1102
  @fields['footer_height'] = footer_height
1103
+ self
1044
1104
  end
1045
1105
 
1046
1106
  # Set the page range to print.
1047
1107
  #
1048
1108
  # * +pages+ - A comma seperated list of page numbers or ranges.
1109
+ # * *Returns* - The converter object.
1049
1110
  def setPrintPageRange(pages)
1050
1111
  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
1112
  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
1113
  end
1053
1114
 
1054
1115
  @fields['print_page_range'] = pages
1116
+ self
1055
1117
  end
1056
1118
 
1057
1119
  # Apply the first page of the watermark PDF to every page of the output PDF.
1058
1120
  #
1059
1121
  # * +page_watermark+ - The file path to a local watermark PDF file. The file must exist and not be empty.
1122
+ # * *Returns* - The converter object.
1060
1123
  def setPageWatermark(page_watermark)
1061
1124
  if (!(File.file?(page_watermark) && !File.zero?(page_watermark)))
1062
1125
  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
1126
  end
1064
1127
 
1065
1128
  @files['page_watermark'] = page_watermark
1129
+ self
1066
1130
  end
1067
1131
 
1068
1132
  # Apply each page of the specified watermark PDF to the corresponding page of the output PDF.
1069
1133
  #
1070
1134
  # * +multipage_watermark+ - The file path to a local watermark PDF file. The file must exist and not be empty.
1135
+ # * *Returns* - The converter object.
1071
1136
  def setMultipageWatermark(multipage_watermark)
1072
1137
  if (!(File.file?(multipage_watermark) && !File.zero?(multipage_watermark)))
1073
1138
  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
1139
  end
1075
1140
 
1076
1141
  @files['multipage_watermark'] = multipage_watermark
1142
+ self
1077
1143
  end
1078
1144
 
1079
1145
  # Apply the first page of the specified PDF to the background of every page of the output PDF.
1080
1146
  #
1081
1147
  # * +page_background+ - The file path to a local background PDF file. The file must exist and not be empty.
1148
+ # * *Returns* - The converter object.
1082
1149
  def setPageBackground(page_background)
1083
1150
  if (!(File.file?(page_background) && !File.zero?(page_background)))
1084
1151
  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
1152
  end
1086
1153
 
1087
1154
  @files['page_background'] = page_background
1155
+ self
1088
1156
  end
1089
1157
 
1090
1158
  # Apply each page of the specified PDF to the background of the corresponding page of the output PDF.
1091
1159
  #
1092
1160
  # * +multipage_background+ - The file path to a local background PDF file. The file must exist and not be empty.
1161
+ # * *Returns* - The converter object.
1093
1162
  def setMultipageBackground(multipage_background)
1094
1163
  if (!(File.file?(multipage_background) && !File.zero?(multipage_background)))
1095
1164
  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
1165
  end
1097
1166
 
1098
1167
  @files['multipage_background'] = multipage_background
1168
+ self
1099
1169
  end
1100
1170
 
1101
1171
  # The page header is not printed on the specified pages.
1102
1172
  #
1103
1173
  # * +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.
1174
+ # * *Returns* - The converter object.
1104
1175
  def setExcludeHeaderOnPages(pages)
1105
1176
  unless /^(?:\s*\-?\d+\s*,)*\s*\-?\d+\s*$/.match(pages)
1106
1177
  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
1178
  end
1108
1179
 
1109
1180
  @fields['exclude_header_on_pages'] = pages
1181
+ self
1110
1182
  end
1111
1183
 
1112
1184
  # The page footer is not printed on the specified pages.
1113
1185
  #
1114
1186
  # * +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.
1187
+ # * *Returns* - The converter object.
1115
1188
  def setExcludeFooterOnPages(pages)
1116
1189
  unless /^(?:\s*\-?\d+\s*,)*\s*\-?\d+\s*$/.match(pages)
1117
1190
  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
1191
  end
1119
1192
 
1120
1193
  @fields['exclude_footer_on_pages'] = pages
1194
+ self
1121
1195
  end
1122
1196
 
1123
1197
  # Set an offset between physical and logical page numbers.
1124
1198
  #
1125
1199
  # * +offset+ - Integer specifying page offset.
1200
+ # * *Returns* - The converter object.
1126
1201
  def setPageNumberingOffset(offset)
1127
1202
  @fields['page_numbering_offset'] = offset
1203
+ self
1128
1204
  end
1129
1205
 
1130
1206
  # Do not print the background graphics.
1131
1207
  #
1132
1208
  # * +no_background+ - Set to true to disable the background graphics.
1209
+ # * *Returns* - The converter object.
1133
1210
  def setNoBackground(no_background)
1134
1211
  @fields['no_background'] = no_background
1212
+ self
1135
1213
  end
1136
1214
 
1137
1215
  # Do not execute JavaScript.
1138
1216
  #
1139
1217
  # * +disable_javascript+ - Set to true to disable JavaScript in web pages.
1218
+ # * *Returns* - The converter object.
1140
1219
  def setDisableJavascript(disable_javascript)
1141
1220
  @fields['disable_javascript'] = disable_javascript
1221
+ self
1142
1222
  end
1143
1223
 
1144
1224
  # Do not load images.
1145
1225
  #
1146
1226
  # * +disable_image_loading+ - Set to true to disable loading of images.
1227
+ # * *Returns* - The converter object.
1147
1228
  def setDisableImageLoading(disable_image_loading)
1148
1229
  @fields['disable_image_loading'] = disable_image_loading
1230
+ self
1149
1231
  end
1150
1232
 
1151
1233
  # Disable loading fonts from remote sources.
1152
1234
  #
1153
1235
  # * +disable_remote_fonts+ - Set to true disable loading remote fonts.
1236
+ # * *Returns* - The converter object.
1154
1237
  def setDisableRemoteFonts(disable_remote_fonts)
1155
1238
  @fields['disable_remote_fonts'] = disable_remote_fonts
1239
+ self
1240
+ end
1241
+
1242
+ # Try to block ads. Enabling this option can produce smaller output and speed up the conversion.
1243
+ #
1244
+ # * +block_ads+ - Set to true to block ads in web pages.
1245
+ # * *Returns* - The converter object.
1246
+ def setBlockAds(block_ads)
1247
+ @fields['block_ads'] = block_ads
1248
+ self
1156
1249
  end
1157
1250
 
1158
1251
  # Set the default HTML content text encoding.
1159
1252
  #
1160
1253
  # * +default_encoding+ - The text encoding of the HTML content.
1254
+ # * *Returns* - The converter object.
1161
1255
  def setDefaultEncoding(default_encoding)
1162
1256
  @fields['default_encoding'] = default_encoding
1257
+ self
1163
1258
  end
1164
1259
 
1165
1260
  # Set the HTTP authentication user name.
1166
1261
  #
1167
1262
  # * +user_name+ - The user name.
1263
+ # * *Returns* - The converter object.
1168
1264
  def setHttpAuthUserName(user_name)
1169
1265
  @fields['http_auth_user_name'] = user_name
1266
+ self
1170
1267
  end
1171
1268
 
1172
1269
  # Set the HTTP authentication password.
1173
1270
  #
1174
1271
  # * +password+ - The password.
1272
+ # * *Returns* - The converter object.
1175
1273
  def setHttpAuthPassword(password)
1176
1274
  @fields['http_auth_password'] = password
1275
+ self
1177
1276
  end
1178
1277
 
1179
1278
  # Set the HTTP authentication.
1180
1279
  #
1181
1280
  # * +user_name+ - Set the HTTP authentication user name.
1182
1281
  # * +password+ - Set the HTTP authentication password.
1282
+ # * *Returns* - The converter object.
1183
1283
  def setHttpAuth(user_name, password)
1184
1284
  setHttpAuthUserName(user_name)
1185
1285
  setHttpAuthPassword(password)
1286
+ self
1186
1287
  end
1187
1288
 
1188
1289
  # Use the print version of the page if available (@media print).
1189
1290
  #
1190
1291
  # * +use_print_media+ - Set to true to use the print version of the page.
1292
+ # * *Returns* - The converter object.
1191
1293
  def setUsePrintMedia(use_print_media)
1192
1294
  @fields['use_print_media'] = use_print_media
1295
+ self
1193
1296
  end
1194
1297
 
1195
1298
  # Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
1196
1299
  #
1197
1300
  # * +no_xpdfcrowd_header+ - Set to true to disable sending X-Pdfcrowd HTTP header.
1301
+ # * *Returns* - The converter object.
1198
1302
  def setNoXpdfcrowdHeader(no_xpdfcrowd_header)
1199
1303
  @fields['no_xpdfcrowd_header'] = no_xpdfcrowd_header
1304
+ self
1200
1305
  end
1201
1306
 
1202
1307
  # Set cookies that are sent in Pdfcrowd HTTP requests.
1203
1308
  #
1204
1309
  # * +cookies+ - The cookie string.
1310
+ # * *Returns* - The converter object.
1205
1311
  def setCookies(cookies)
1206
1312
  @fields['cookies'] = cookies
1313
+ self
1207
1314
  end
1208
1315
 
1209
1316
  # Do not allow insecure HTTPS connections.
1210
1317
  #
1211
1318
  # * +verify_ssl_certificates+ - Set to true to enable SSL certificate verification.
1319
+ # * *Returns* - The converter object.
1212
1320
  def setVerifySslCertificates(verify_ssl_certificates)
1213
1321
  @fields['verify_ssl_certificates'] = verify_ssl_certificates
1322
+ self
1214
1323
  end
1215
1324
 
1216
1325
  # Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
1217
1326
  #
1218
1327
  # * +fail_on_error+ - Set to true to abort the conversion.
1328
+ # * *Returns* - The converter object.
1219
1329
  def setFailOnMainUrlError(fail_on_error)
1220
1330
  @fields['fail_on_main_url_error'] = fail_on_error
1331
+ self
1221
1332
  end
1222
1333
 
1223
1334
  # Abort the conversion if any of the sub-request HTTP status code is greater than or equal to 400.
1224
1335
  #
1225
1336
  # * +fail_on_error+ - Set to true to abort the conversion.
1337
+ # * *Returns* - The converter object.
1226
1338
  def setFailOnAnyUrlError(fail_on_error)
1227
1339
  @fields['fail_on_any_url_error'] = fail_on_error
1340
+ self
1228
1341
  end
1229
1342
 
1230
1343
  # Run a custom JavaScript after the document is loaded. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, ...).
1231
1344
  #
1232
1345
  # * +custom_javascript+ - String containing a JavaScript code. The string must not be empty.
1346
+ # * *Returns* - The converter object.
1233
1347
  def setCustomJavascript(custom_javascript)
1234
1348
  if (!(!custom_javascript.nil? && !custom_javascript.empty?))
1235
1349
  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
1350
  end
1237
1351
 
1238
1352
  @fields['custom_javascript'] = custom_javascript
1353
+ self
1239
1354
  end
1240
1355
 
1241
1356
  # Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
1242
1357
  #
1243
1358
  # * +custom_http_header+ - A string containing the header name and value separated by a colon.
1359
+ # * *Returns* - The converter object.
1244
1360
  def setCustomHttpHeader(custom_http_header)
1245
1361
  unless /^.+:.+$/.match(custom_http_header)
1246
1362
  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
1363
  end
1248
1364
 
1249
1365
  @fields['custom_http_header'] = custom_http_header
1366
+ self
1250
1367
  end
1251
1368
 
1252
1369
  # 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
1370
  #
1254
1371
  # * +javascript_delay+ - The number of milliseconds to wait. Must be a positive integer number or 0.
1372
+ # * *Returns* - The converter object.
1255
1373
  def setJavascriptDelay(javascript_delay)
1256
1374
  if (!(Integer(javascript_delay) >= 0))
1257
1375
  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
1376
  end
1259
1377
 
1260
1378
  @fields['javascript_delay'] = javascript_delay
1379
+ self
1261
1380
  end
1262
1381
 
1263
1382
  # 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
1383
  #
1265
1384
  # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1385
+ # * *Returns* - The converter object.
1266
1386
  def setElementToConvert(selectors)
1267
1387
  if (!(!selectors.nil? && !selectors.empty?))
1268
1388
  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
1389
  end
1270
1390
 
1271
1391
  @fields['element_to_convert'] = selectors
1392
+ self
1272
1393
  end
1273
1394
 
1274
1395
  # Specify the DOM handling when only a part of the document is converted.
1275
1396
  #
1276
1397
  # * +mode+ - Allowed values are cut-out, remove-siblings, hide-siblings.
1398
+ # * *Returns* - The converter object.
1277
1399
  def setElementToConvertMode(mode)
1278
1400
  unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode)
1279
1401
  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
1402
  end
1281
1403
 
1282
1404
  @fields['element_to_convert_mode'] = mode
1405
+ self
1283
1406
  end
1284
1407
 
1285
1408
  # 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
1409
  #
1287
1410
  # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1411
+ # * *Returns* - The converter object.
1288
1412
  def setWaitForElement(selectors)
1289
1413
  if (!(!selectors.nil? && !selectors.empty?))
1290
1414
  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
1415
  end
1292
1416
 
1293
1417
  @fields['wait_for_element'] = selectors
1418
+ self
1294
1419
  end
1295
1420
 
1296
1421
  # Set the viewport width in pixels. The viewport is the user's visible area of the page.
1297
1422
  #
1298
1423
  # * +viewport_width+ - The value must be in a range 96-7680.
1424
+ # * *Returns* - The converter object.
1299
1425
  def setViewportWidth(viewport_width)
1300
1426
  if (!(Integer(viewport_width) >= 96 && Integer(viewport_width) <= 7680))
1301
1427
  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
1428
  end
1303
1429
 
1304
1430
  @fields['viewport_width'] = viewport_width
1431
+ self
1305
1432
  end
1306
1433
 
1307
1434
  # Set the viewport height in pixels. The viewport is the user's visible area of the page.
1308
1435
  #
1309
1436
  # * +viewport_height+ - Must be a positive integer number.
1437
+ # * *Returns* - The converter object.
1310
1438
  def setViewportHeight(viewport_height)
1311
1439
  if (!(Integer(viewport_height) > 0))
1312
1440
  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
1441
  end
1314
1442
 
1315
1443
  @fields['viewport_height'] = viewport_height
1444
+ self
1316
1445
  end
1317
1446
 
1318
1447
  # Set the viewport size. The viewport is the user's visible area of the page.
1319
1448
  #
1320
1449
  # * +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
1450
  # * +height+ - Set the viewport height in pixels. The viewport is the user's visible area of the page. Must be a positive integer number.
1451
+ # * *Returns* - The converter object.
1322
1452
  def setViewport(width, height)
1323
1453
  setViewportWidth(width)
1324
1454
  setViewportHeight(height)
1455
+ self
1325
1456
  end
1326
1457
 
1327
1458
  # Sets the rendering mode.
1328
1459
  #
1329
1460
  # * +rendering_mode+ - The rendering mode. Allowed values are default, viewport.
1461
+ # * *Returns* - The converter object.
1330
1462
  def setRenderingMode(rendering_mode)
1331
1463
  unless /(?i)^(default|viewport)$/.match(rendering_mode)
1332
1464
  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
1465
  end
1334
1466
 
1335
1467
  @fields['rendering_mode'] = rendering_mode
1468
+ self
1336
1469
  end
1337
1470
 
1338
1471
  # Set the scaling factor (zoom) for the main page area.
1339
1472
  #
1340
1473
  # * +scale_factor+ - The scale factor. The value must be in a range 10-500.
1474
+ # * *Returns* - The converter object.
1341
1475
  def setScaleFactor(scale_factor)
1342
1476
  if (!(Integer(scale_factor) >= 10 && Integer(scale_factor) <= 500))
1343
1477
  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
1478
  end
1345
1479
 
1346
1480
  @fields['scale_factor'] = scale_factor
1481
+ self
1347
1482
  end
1348
1483
 
1349
1484
  # Set the scaling factor (zoom) for the header and footer.
1350
1485
  #
1351
1486
  # * +header_footer_scale_factor+ - The scale factor. The value must be in a range 10-500.
1487
+ # * *Returns* - The converter object.
1352
1488
  def setHeaderFooterScaleFactor(header_footer_scale_factor)
1353
1489
  if (!(Integer(header_footer_scale_factor) >= 10 && Integer(header_footer_scale_factor) <= 500))
1354
1490
  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
1491
  end
1356
1492
 
1357
1493
  @fields['header_footer_scale_factor'] = header_footer_scale_factor
1494
+ self
1358
1495
  end
1359
1496
 
1360
1497
  # Create linearized PDF. This is also known as Fast Web View.
1361
1498
  #
1362
1499
  # * +linearize+ - Set to true to create linearized PDF.
1500
+ # * *Returns* - The converter object.
1363
1501
  def setLinearize(linearize)
1364
1502
  @fields['linearize'] = linearize
1503
+ self
1365
1504
  end
1366
1505
 
1367
1506
  # Encrypt the PDF. This prevents search engines from indexing the contents.
1368
1507
  #
1369
1508
  # * +encrypt+ - Set to true to enable PDF encryption.
1509
+ # * *Returns* - The converter object.
1370
1510
  def setEncrypt(encrypt)
1371
1511
  @fields['encrypt'] = encrypt
1512
+ self
1372
1513
  end
1373
1514
 
1374
1515
  # 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
1516
  #
1376
1517
  # * +user_password+ - The user password.
1518
+ # * *Returns* - The converter object.
1377
1519
  def setUserPassword(user_password)
1378
1520
  @fields['user_password'] = user_password
1521
+ self
1379
1522
  end
1380
1523
 
1381
1524
  # 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
1525
  #
1383
1526
  # * +owner_password+ - The owner password.
1527
+ # * *Returns* - The converter object.
1384
1528
  def setOwnerPassword(owner_password)
1385
1529
  @fields['owner_password'] = owner_password
1530
+ self
1386
1531
  end
1387
1532
 
1388
1533
  # Disallow printing of the output PDF.
1389
1534
  #
1390
1535
  # * +no_print+ - Set to true to set the no-print flag in the output PDF.
1536
+ # * *Returns* - The converter object.
1391
1537
  def setNoPrint(no_print)
1392
1538
  @fields['no_print'] = no_print
1539
+ self
1393
1540
  end
1394
1541
 
1395
1542
  # Disallow modification of the ouput PDF.
1396
1543
  #
1397
1544
  # * +no_modify+ - Set to true to set the read-only only flag in the output PDF.
1545
+ # * *Returns* - The converter object.
1398
1546
  def setNoModify(no_modify)
1399
1547
  @fields['no_modify'] = no_modify
1548
+ self
1400
1549
  end
1401
1550
 
1402
1551
  # Disallow text and graphics extraction from the output PDF.
1403
1552
  #
1404
1553
  # * +no_copy+ - Set to true to set the no-copy flag in the output PDF.
1554
+ # * *Returns* - The converter object.
1405
1555
  def setNoCopy(no_copy)
1406
1556
  @fields['no_copy'] = no_copy
1557
+ self
1407
1558
  end
1408
1559
 
1409
1560
  # Turn on the debug logging.
1410
1561
  #
1411
1562
  # * +debug_log+ - Set to true to enable the debug logging.
1563
+ # * *Returns* - The converter object.
1412
1564
  def setDebugLog(debug_log)
1413
1565
  @fields['debug_log'] = debug_log
1566
+ self
1414
1567
  end
1415
1568
 
1416
1569
  # Get the URL of the debug log for the last conversion.
@@ -1454,15 +1607,19 @@ module Pdfcrowd
1454
1607
  # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
1455
1608
  #
1456
1609
  # * +use_http+ - Set to true to use HTTP.
1610
+ # * *Returns* - The converter object.
1457
1611
  def setUseHttp(use_http)
1458
1612
  @helper.setUseHttp(use_http)
1613
+ self
1459
1614
  end
1460
1615
 
1461
1616
  # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
1462
1617
  #
1463
1618
  # * +user_agent+ - The user agent string.
1619
+ # * *Returns* - The converter object.
1464
1620
  def setUserAgent(user_agent)
1465
1621
  @helper.setUserAgent(user_agent)
1622
+ self
1466
1623
  end
1467
1624
 
1468
1625
  # Specifies an HTTP proxy that the API client library will use to connect to the internet.
@@ -1471,8 +1628,19 @@ module Pdfcrowd
1471
1628
  # * +port+ - The proxy port.
1472
1629
  # * +user_name+ - The username.
1473
1630
  # * +password+ - The password.
1631
+ # * *Returns* - The converter object.
1474
1632
  def setProxy(host, port, user_name, password)
1475
1633
  @helper.setProxy(host, port, user_name, password)
1634
+ self
1635
+ end
1636
+
1637
+ # Specifies number of retries after HTTP status code 502 was received. The status 502 occurs seldom due to network problems. This feature can be disabled by setting to 0.
1638
+ #
1639
+ # * +retry_count+ - Number of retries wanted.
1640
+ # * *Returns* - The converter object.
1641
+ def setRetryCount(retry_count)
1642
+ @helper.setRetryCount(retry_count)
1643
+ self
1476
1644
  end
1477
1645
 
1478
1646
  end
@@ -1497,12 +1665,14 @@ module Pdfcrowd
1497
1665
  # The format of the output file.
1498
1666
  #
1499
1667
  # * +output_format+ - Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.
1668
+ # * *Returns* - The converter object.
1500
1669
  def setOutputFormat(output_format)
1501
1670
  unless /(?i)^(png|jpg|gif|tiff|bmp|ico|ppm|pgm|pbm|pnm|psb|pct|ras|tga|sgi|sun|webp)$/.match(output_format)
1502
1671
  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
1672
  end
1504
1673
 
1505
1674
  @fields['output_format'] = output_format
1675
+ self
1506
1676
  end
1507
1677
 
1508
1678
  # Convert a web page.
@@ -1636,196 +1806,251 @@ module Pdfcrowd
1636
1806
  # Do not print the background graphics.
1637
1807
  #
1638
1808
  # * +no_background+ - Set to true to disable the background graphics.
1809
+ # * *Returns* - The converter object.
1639
1810
  def setNoBackground(no_background)
1640
1811
  @fields['no_background'] = no_background
1812
+ self
1641
1813
  end
1642
1814
 
1643
1815
  # Do not execute JavaScript.
1644
1816
  #
1645
1817
  # * +disable_javascript+ - Set to true to disable JavaScript in web pages.
1818
+ # * *Returns* - The converter object.
1646
1819
  def setDisableJavascript(disable_javascript)
1647
1820
  @fields['disable_javascript'] = disable_javascript
1821
+ self
1648
1822
  end
1649
1823
 
1650
1824
  # Do not load images.
1651
1825
  #
1652
1826
  # * +disable_image_loading+ - Set to true to disable loading of images.
1827
+ # * *Returns* - The converter object.
1653
1828
  def setDisableImageLoading(disable_image_loading)
1654
1829
  @fields['disable_image_loading'] = disable_image_loading
1830
+ self
1655
1831
  end
1656
1832
 
1657
1833
  # Disable loading fonts from remote sources.
1658
1834
  #
1659
1835
  # * +disable_remote_fonts+ - Set to true disable loading remote fonts.
1836
+ # * *Returns* - The converter object.
1660
1837
  def setDisableRemoteFonts(disable_remote_fonts)
1661
1838
  @fields['disable_remote_fonts'] = disable_remote_fonts
1839
+ self
1840
+ end
1841
+
1842
+ # Try to block ads. Enabling this option can produce smaller output and speed up the conversion.
1843
+ #
1844
+ # * +block_ads+ - Set to true to block ads in web pages.
1845
+ # * *Returns* - The converter object.
1846
+ def setBlockAds(block_ads)
1847
+ @fields['block_ads'] = block_ads
1848
+ self
1662
1849
  end
1663
1850
 
1664
1851
  # Set the default HTML content text encoding.
1665
1852
  #
1666
1853
  # * +default_encoding+ - The text encoding of the HTML content.
1854
+ # * *Returns* - The converter object.
1667
1855
  def setDefaultEncoding(default_encoding)
1668
1856
  @fields['default_encoding'] = default_encoding
1857
+ self
1669
1858
  end
1670
1859
 
1671
1860
  # Set the HTTP authentication user name.
1672
1861
  #
1673
1862
  # * +user_name+ - The user name.
1863
+ # * *Returns* - The converter object.
1674
1864
  def setHttpAuthUserName(user_name)
1675
1865
  @fields['http_auth_user_name'] = user_name
1866
+ self
1676
1867
  end
1677
1868
 
1678
1869
  # Set the HTTP authentication password.
1679
1870
  #
1680
1871
  # * +password+ - The password.
1872
+ # * *Returns* - The converter object.
1681
1873
  def setHttpAuthPassword(password)
1682
1874
  @fields['http_auth_password'] = password
1875
+ self
1683
1876
  end
1684
1877
 
1685
1878
  # Set the HTTP authentication.
1686
1879
  #
1687
1880
  # * +user_name+ - Set the HTTP authentication user name.
1688
1881
  # * +password+ - Set the HTTP authentication password.
1882
+ # * *Returns* - The converter object.
1689
1883
  def setHttpAuth(user_name, password)
1690
1884
  setHttpAuthUserName(user_name)
1691
1885
  setHttpAuthPassword(password)
1886
+ self
1692
1887
  end
1693
1888
 
1694
1889
  # Use the print version of the page if available (@media print).
1695
1890
  #
1696
1891
  # * +use_print_media+ - Set to true to use the print version of the page.
1892
+ # * *Returns* - The converter object.
1697
1893
  def setUsePrintMedia(use_print_media)
1698
1894
  @fields['use_print_media'] = use_print_media
1895
+ self
1699
1896
  end
1700
1897
 
1701
1898
  # Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
1702
1899
  #
1703
1900
  # * +no_xpdfcrowd_header+ - Set to true to disable sending X-Pdfcrowd HTTP header.
1901
+ # * *Returns* - The converter object.
1704
1902
  def setNoXpdfcrowdHeader(no_xpdfcrowd_header)
1705
1903
  @fields['no_xpdfcrowd_header'] = no_xpdfcrowd_header
1904
+ self
1706
1905
  end
1707
1906
 
1708
1907
  # Set cookies that are sent in Pdfcrowd HTTP requests.
1709
1908
  #
1710
1909
  # * +cookies+ - The cookie string.
1910
+ # * *Returns* - The converter object.
1711
1911
  def setCookies(cookies)
1712
1912
  @fields['cookies'] = cookies
1913
+ self
1713
1914
  end
1714
1915
 
1715
1916
  # Do not allow insecure HTTPS connections.
1716
1917
  #
1717
1918
  # * +verify_ssl_certificates+ - Set to true to enable SSL certificate verification.
1919
+ # * *Returns* - The converter object.
1718
1920
  def setVerifySslCertificates(verify_ssl_certificates)
1719
1921
  @fields['verify_ssl_certificates'] = verify_ssl_certificates
1922
+ self
1720
1923
  end
1721
1924
 
1722
1925
  # Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
1723
1926
  #
1724
1927
  # * +fail_on_error+ - Set to true to abort the conversion.
1928
+ # * *Returns* - The converter object.
1725
1929
  def setFailOnMainUrlError(fail_on_error)
1726
1930
  @fields['fail_on_main_url_error'] = fail_on_error
1931
+ self
1727
1932
  end
1728
1933
 
1729
1934
  # Abort the conversion if any of the sub-request HTTP status code is greater than or equal to 400.
1730
1935
  #
1731
1936
  # * +fail_on_error+ - Set to true to abort the conversion.
1937
+ # * *Returns* - The converter object.
1732
1938
  def setFailOnAnyUrlError(fail_on_error)
1733
1939
  @fields['fail_on_any_url_error'] = fail_on_error
1940
+ self
1734
1941
  end
1735
1942
 
1736
1943
  # Run a custom JavaScript after the document is loaded. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, ...).
1737
1944
  #
1738
1945
  # * +custom_javascript+ - String containing a JavaScript code. The string must not be empty.
1946
+ # * *Returns* - The converter object.
1739
1947
  def setCustomJavascript(custom_javascript)
1740
1948
  if (!(!custom_javascript.nil? && !custom_javascript.empty?))
1741
1949
  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
1950
  end
1743
1951
 
1744
1952
  @fields['custom_javascript'] = custom_javascript
1953
+ self
1745
1954
  end
1746
1955
 
1747
1956
  # Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
1748
1957
  #
1749
1958
  # * +custom_http_header+ - A string containing the header name and value separated by a colon.
1959
+ # * *Returns* - The converter object.
1750
1960
  def setCustomHttpHeader(custom_http_header)
1751
1961
  unless /^.+:.+$/.match(custom_http_header)
1752
1962
  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
1963
  end
1754
1964
 
1755
1965
  @fields['custom_http_header'] = custom_http_header
1966
+ self
1756
1967
  end
1757
1968
 
1758
1969
  # 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
1970
  #
1760
1971
  # * +javascript_delay+ - The number of milliseconds to wait. Must be a positive integer number or 0.
1972
+ # * *Returns* - The converter object.
1761
1973
  def setJavascriptDelay(javascript_delay)
1762
1974
  if (!(Integer(javascript_delay) >= 0))
1763
1975
  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
1976
  end
1765
1977
 
1766
1978
  @fields['javascript_delay'] = javascript_delay
1979
+ self
1767
1980
  end
1768
1981
 
1769
1982
  # 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
1983
  #
1771
1984
  # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
1985
+ # * *Returns* - The converter object.
1772
1986
  def setElementToConvert(selectors)
1773
1987
  if (!(!selectors.nil? && !selectors.empty?))
1774
1988
  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
1989
  end
1776
1990
 
1777
1991
  @fields['element_to_convert'] = selectors
1992
+ self
1778
1993
  end
1779
1994
 
1780
1995
  # Specify the DOM handling when only a part of the document is converted.
1781
1996
  #
1782
1997
  # * +mode+ - Allowed values are cut-out, remove-siblings, hide-siblings.
1998
+ # * *Returns* - The converter object.
1783
1999
  def setElementToConvertMode(mode)
1784
2000
  unless /(?i)^(cut-out|remove-siblings|hide-siblings)$/.match(mode)
1785
2001
  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
2002
  end
1787
2003
 
1788
2004
  @fields['element_to_convert_mode'] = mode
2005
+ self
1789
2006
  end
1790
2007
 
1791
2008
  # 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
2009
  #
1793
2010
  # * +selectors+ - One or more CSS selectors separated by commas. The string must not be empty.
2011
+ # * *Returns* - The converter object.
1794
2012
  def setWaitForElement(selectors)
1795
2013
  if (!(!selectors.nil? && !selectors.empty?))
1796
2014
  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
2015
  end
1798
2016
 
1799
2017
  @fields['wait_for_element'] = selectors
2018
+ self
1800
2019
  end
1801
2020
 
1802
2021
  # Set the output image width in pixels.
1803
2022
  #
1804
2023
  # * +screenshot_width+ - The value must be in a range 96-7680.
2024
+ # * *Returns* - The converter object.
1805
2025
  def setScreenshotWidth(screenshot_width)
1806
2026
  if (!(Integer(screenshot_width) >= 96 && Integer(screenshot_width) <= 7680))
1807
2027
  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
2028
  end
1809
2029
 
1810
2030
  @fields['screenshot_width'] = screenshot_width
2031
+ self
1811
2032
  end
1812
2033
 
1813
2034
  # Set the output image height in pixels. If it's not specified, actual document height is used.
1814
2035
  #
1815
2036
  # * +screenshot_height+ - Must be a positive integer number.
2037
+ # * *Returns* - The converter object.
1816
2038
  def setScreenshotHeight(screenshot_height)
1817
2039
  if (!(Integer(screenshot_height) > 0))
1818
2040
  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
2041
  end
1820
2042
 
1821
2043
  @fields['screenshot_height'] = screenshot_height
2044
+ self
1822
2045
  end
1823
2046
 
1824
2047
  # Turn on the debug logging.
1825
2048
  #
1826
2049
  # * +debug_log+ - Set to true to enable the debug logging.
2050
+ # * *Returns* - The converter object.
1827
2051
  def setDebugLog(debug_log)
1828
2052
  @fields['debug_log'] = debug_log
2053
+ self
1829
2054
  end
1830
2055
 
1831
2056
  # Get the URL of the debug log for the last conversion.
@@ -1863,15 +2088,19 @@ module Pdfcrowd
1863
2088
  # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
1864
2089
  #
1865
2090
  # * +use_http+ - Set to true to use HTTP.
2091
+ # * *Returns* - The converter object.
1866
2092
  def setUseHttp(use_http)
1867
2093
  @helper.setUseHttp(use_http)
2094
+ self
1868
2095
  end
1869
2096
 
1870
2097
  # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
1871
2098
  #
1872
2099
  # * +user_agent+ - The user agent string.
2100
+ # * *Returns* - The converter object.
1873
2101
  def setUserAgent(user_agent)
1874
2102
  @helper.setUserAgent(user_agent)
2103
+ self
1875
2104
  end
1876
2105
 
1877
2106
  # Specifies an HTTP proxy that the API client library will use to connect to the internet.
@@ -1880,8 +2109,19 @@ module Pdfcrowd
1880
2109
  # * +port+ - The proxy port.
1881
2110
  # * +user_name+ - The username.
1882
2111
  # * +password+ - The password.
2112
+ # * *Returns* - The converter object.
1883
2113
  def setProxy(host, port, user_name, password)
1884
2114
  @helper.setProxy(host, port, user_name, password)
2115
+ self
2116
+ end
2117
+
2118
+ # Specifies number of retries after HTTP status code 502 was received. The status 502 occurs seldom due to network problems. This feature can be disabled by setting to 0.
2119
+ #
2120
+ # * +retry_count+ - Number of retries wanted.
2121
+ # * *Returns* - The converter object.
2122
+ def setRetryCount(retry_count)
2123
+ @helper.setRetryCount(retry_count)
2124
+ self
1885
2125
  end
1886
2126
 
1887
2127
  end
@@ -2018,33 +2258,41 @@ module Pdfcrowd
2018
2258
  # The format of the output file.
2019
2259
  #
2020
2260
  # * +output_format+ - Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.
2261
+ # * *Returns* - The converter object.
2021
2262
  def setOutputFormat(output_format)
2022
2263
  unless /(?i)^(png|jpg|gif|tiff|bmp|ico|ppm|pgm|pbm|pnm|psb|pct|ras|tga|sgi|sun|webp)$/.match(output_format)
2023
2264
  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
2265
  end
2025
2266
 
2026
2267
  @fields['output_format'] = output_format
2268
+ self
2027
2269
  end
2028
2270
 
2029
2271
  # Resize the image.
2030
2272
  #
2031
2273
  # * +resize+ - The resize percentage or new image dimensions.
2274
+ # * *Returns* - The converter object.
2032
2275
  def setResize(resize)
2033
2276
  @fields['resize'] = resize
2277
+ self
2034
2278
  end
2035
2279
 
2036
2280
  # Rotate the image.
2037
2281
  #
2038
2282
  # * +rotate+ - The rotation specified in degrees.
2283
+ # * *Returns* - The converter object.
2039
2284
  def setRotate(rotate)
2040
2285
  @fields['rotate'] = rotate
2286
+ self
2041
2287
  end
2042
2288
 
2043
2289
  # Turn on the debug logging.
2044
2290
  #
2045
2291
  # * +debug_log+ - Set to true to enable the debug logging.
2292
+ # * *Returns* - The converter object.
2046
2293
  def setDebugLog(debug_log)
2047
2294
  @fields['debug_log'] = debug_log
2295
+ self
2048
2296
  end
2049
2297
 
2050
2298
  # Get the URL of the debug log for the last conversion.
@@ -2082,15 +2330,19 @@ module Pdfcrowd
2082
2330
  # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
2083
2331
  #
2084
2332
  # * +use_http+ - Set to true to use HTTP.
2333
+ # * *Returns* - The converter object.
2085
2334
  def setUseHttp(use_http)
2086
2335
  @helper.setUseHttp(use_http)
2336
+ self
2087
2337
  end
2088
2338
 
2089
2339
  # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
2090
2340
  #
2091
2341
  # * +user_agent+ - The user agent string.
2342
+ # * *Returns* - The converter object.
2092
2343
  def setUserAgent(user_agent)
2093
2344
  @helper.setUserAgent(user_agent)
2345
+ self
2094
2346
  end
2095
2347
 
2096
2348
  # Specifies an HTTP proxy that the API client library will use to connect to the internet.
@@ -2099,8 +2351,19 @@ module Pdfcrowd
2099
2351
  # * +port+ - The proxy port.
2100
2352
  # * +user_name+ - The username.
2101
2353
  # * +password+ - The password.
2354
+ # * *Returns* - The converter object.
2102
2355
  def setProxy(host, port, user_name, password)
2103
2356
  @helper.setProxy(host, port, user_name, password)
2357
+ self
2358
+ end
2359
+
2360
+ # Specifies number of retries after HTTP status code 502 was received. The status 502 occurs seldom due to network problems. This feature can be disabled by setting to 0.
2361
+ #
2362
+ # * +retry_count+ - Number of retries wanted.
2363
+ # * *Returns* - The converter object.
2364
+ def setRetryCount(retry_count)
2365
+ @helper.setRetryCount(retry_count)
2366
+ self
2104
2367
  end
2105
2368
 
2106
2369
  end
@@ -2125,12 +2388,14 @@ module Pdfcrowd
2125
2388
  # Specifies the action to be performed on the input PDFs.
2126
2389
  #
2127
2390
  # * +action+ - Allowed values are join, shuffle.
2391
+ # * *Returns* - The converter object.
2128
2392
  def setAction(action)
2129
2393
  unless /(?i)^(join|shuffle)$/.match(action)
2130
2394
  raise Error.new(Pdfcrowd.create_invalid_value_message(action, "action", "pdf-to-pdf", "Allowed values are join, shuffle.", "set_action"), 470);
2131
2395
  end
2132
2396
 
2133
2397
  @fields['action'] = action
2398
+ self
2134
2399
  end
2135
2400
 
2136
2401
  # Perform an action on the input files.
@@ -2162,6 +2427,7 @@ module Pdfcrowd
2162
2427
  # Add a PDF file to the list of the input PDFs.
2163
2428
  #
2164
2429
  # * +file_path+ - The file path to a local PDF file. The file must exist and not be empty.
2430
+ # * *Returns* - The converter object.
2165
2431
  def addPdfFile(file_path)
2166
2432
  if (!(File.file?(file_path) && !File.zero?(file_path)))
2167
2433
  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);
@@ -2169,11 +2435,13 @@ module Pdfcrowd
2169
2435
 
2170
2436
  @files['f_%s' % @file_id] = file_path
2171
2437
  @file_id += 1
2438
+ self
2172
2439
  end
2173
2440
 
2174
2441
  # Add in-memory raw PDF data to the list of the input PDFs.
2175
2442
  #
2176
2443
  # * +pdf_raw_data+ - The raw PDF data. The input data must be PDF content.
2444
+ # * *Returns* - The converter object.
2177
2445
  def addPdfRawData(pdf_raw_data)
2178
2446
  if (!(!pdf_raw_data.nil? && pdf_raw_data.length > 300 and pdf_raw_data[0...4] == '%PDF'))
2179
2447
  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);
@@ -2181,13 +2449,16 @@ module Pdfcrowd
2181
2449
 
2182
2450
  @raw_data['f_%s' % @file_id] = pdf_raw_data
2183
2451
  @file_id += 1
2452
+ self
2184
2453
  end
2185
2454
 
2186
2455
  # Turn on the debug logging.
2187
2456
  #
2188
2457
  # * +debug_log+ - Set to true to enable the debug logging.
2458
+ # * *Returns* - The converter object.
2189
2459
  def setDebugLog(debug_log)
2190
2460
  @fields['debug_log'] = debug_log
2461
+ self
2191
2462
  end
2192
2463
 
2193
2464
  # Get the URL of the debug log for the last conversion.
@@ -2231,15 +2502,19 @@ module Pdfcrowd
2231
2502
  # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
2232
2503
  #
2233
2504
  # * +use_http+ - Set to true to use HTTP.
2505
+ # * *Returns* - The converter object.
2234
2506
  def setUseHttp(use_http)
2235
2507
  @helper.setUseHttp(use_http)
2508
+ self
2236
2509
  end
2237
2510
 
2238
2511
  # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
2239
2512
  #
2240
2513
  # * +user_agent+ - The user agent string.
2514
+ # * *Returns* - The converter object.
2241
2515
  def setUserAgent(user_agent)
2242
2516
  @helper.setUserAgent(user_agent)
2517
+ self
2243
2518
  end
2244
2519
 
2245
2520
  # Specifies an HTTP proxy that the API client library will use to connect to the internet.
@@ -2248,8 +2523,19 @@ module Pdfcrowd
2248
2523
  # * +port+ - The proxy port.
2249
2524
  # * +user_name+ - The username.
2250
2525
  # * +password+ - The password.
2526
+ # * *Returns* - The converter object.
2251
2527
  def setProxy(host, port, user_name, password)
2252
2528
  @helper.setProxy(host, port, user_name, password)
2529
+ self
2530
+ end
2531
+
2532
+ # Specifies number of retries after HTTP status code 502 was received. The status 502 occurs seldom due to network problems. This feature can be disabled by setting to 0.
2533
+ #
2534
+ # * +retry_count+ - Number of retries wanted.
2535
+ # * *Returns* - The converter object.
2536
+ def setRetryCount(retry_count)
2537
+ @helper.setRetryCount(retry_count)
2538
+ self
2253
2539
  end
2254
2540
 
2255
2541
  end
@@ -2386,22 +2672,28 @@ module Pdfcrowd
2386
2672
  # Resize the image.
2387
2673
  #
2388
2674
  # * +resize+ - The resize percentage or new image dimensions.
2675
+ # * *Returns* - The converter object.
2389
2676
  def setResize(resize)
2390
2677
  @fields['resize'] = resize
2678
+ self
2391
2679
  end
2392
2680
 
2393
2681
  # Rotate the image.
2394
2682
  #
2395
2683
  # * +rotate+ - The rotation specified in degrees.
2684
+ # * *Returns* - The converter object.
2396
2685
  def setRotate(rotate)
2397
2686
  @fields['rotate'] = rotate
2687
+ self
2398
2688
  end
2399
2689
 
2400
2690
  # Turn on the debug logging.
2401
2691
  #
2402
2692
  # * +debug_log+ - Set to true to enable the debug logging.
2693
+ # * *Returns* - The converter object.
2403
2694
  def setDebugLog(debug_log)
2404
2695
  @fields['debug_log'] = debug_log
2696
+ self
2405
2697
  end
2406
2698
 
2407
2699
  # Get the URL of the debug log for the last conversion.
@@ -2439,15 +2731,19 @@ module Pdfcrowd
2439
2731
  # Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
2440
2732
  #
2441
2733
  # * +use_http+ - Set to true to use HTTP.
2734
+ # * *Returns* - The converter object.
2442
2735
  def setUseHttp(use_http)
2443
2736
  @helper.setUseHttp(use_http)
2737
+ self
2444
2738
  end
2445
2739
 
2446
2740
  # Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
2447
2741
  #
2448
2742
  # * +user_agent+ - The user agent string.
2743
+ # * *Returns* - The converter object.
2449
2744
  def setUserAgent(user_agent)
2450
2745
  @helper.setUserAgent(user_agent)
2746
+ self
2451
2747
  end
2452
2748
 
2453
2749
  # Specifies an HTTP proxy that the API client library will use to connect to the internet.
@@ -2456,10 +2752,21 @@ module Pdfcrowd
2456
2752
  # * +port+ - The proxy port.
2457
2753
  # * +user_name+ - The username.
2458
2754
  # * +password+ - The password.
2755
+ # * *Returns* - The converter object.
2459
2756
  def setProxy(host, port, user_name, password)
2460
2757
  @helper.setProxy(host, port, user_name, password)
2758
+ self
2759
+ end
2760
+
2761
+ # Specifies number of retries after HTTP status code 502 was received. The status 502 occurs seldom due to network problems. This feature can be disabled by setting to 0.
2762
+ #
2763
+ # * +retry_count+ - Number of retries wanted.
2764
+ # * *Returns* - The converter object.
2765
+ def setRetryCount(retry_count)
2766
+ @helper.setRetryCount(retry_count)
2767
+ self
2461
2768
  end
2462
2769
 
2463
2770
  end
2464
2771
 
2465
- end
2772
+ end