pdfcrowd 6.7.0 → 6.7.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 +591 -172
  3. metadata +2 -2
data/lib/pdfcrowd.rb CHANGED
@@ -558,7 +558,7 @@ end
558
558
  module Pdfcrowd
559
559
  HOST = ENV["PDFCROWD_HOST"] || 'api.pdfcrowd.com'
560
560
  MULTIPART_BOUNDARY = '----------ThIs_Is_tHe_bOUnDary_$'
561
- CLIENT_VERSION = '6.7.0'
561
+ CLIENT_VERSION = '6.7.1'
562
562
 
563
563
  class ConnectionHelper
564
564
  def initialize(user_name, api_key)
@@ -569,12 +569,21 @@ module Pdfcrowd
569
569
 
570
570
  setProxy(nil, nil, nil, nil)
571
571
  setUseHttp(false)
572
- setUserAgent('pdfcrowd_ruby_client/6.7.0 (https://pdfcrowd.com)')
572
+ setUserAgent('pdfcrowd_ruby_client/6.7.1 (https://pdfcrowd.com)')
573
573
 
574
574
  @retry_count = 1
575
575
  @converter_version = '24.04'
576
576
  end
577
577
 
578
+ def reset_input(fields, files, raw_data)
579
+ # Preserve conversion options and auxiliary files between requests.
580
+ fields.delete('url')
581
+ fields.delete('text')
582
+ files.delete('file')
583
+ raw_data.delete('file')
584
+ raw_data.delete('stream')
585
+ end
586
+
578
587
  def post(fields, files, raw_data, out_stream = nil)
579
588
  request = create_request()
580
589
  request.body = ConnectionHelper.encode_multipart_post_data(fields, files, raw_data)
@@ -792,6 +801,7 @@ module Pdfcrowd
792
801
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "html-to-pdf", "Supported protocols are http:// and https://.", "convert_url"), 470);
793
802
  end
794
803
 
804
+ @helper.reset_input(@fields, @files, @raw_data)
795
805
  @fields['url'] = url
796
806
  @helper.post(@fields, @files, @raw_data)
797
807
  end
@@ -802,6 +812,7 @@ module Pdfcrowd
802
812
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "html-to-pdf", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
803
813
  end
804
814
 
815
+ @helper.reset_input(@fields, @files, @raw_data)
805
816
  @fields['url'] = url
806
817
  @helper.post(@fields, @files, @raw_data, out_stream)
807
818
  end
@@ -813,13 +824,25 @@ module Pdfcrowd
813
824
  end
814
825
 
815
826
  output_file = open(file_path, "wb")
827
+ succeeded = false
816
828
  begin
817
- convertUrlToStream(url, output_file)
818
- output_file.close()
819
- rescue Error => why
820
- output_file.close()
821
- FileUtils.rm(file_path)
822
- raise
829
+ convertUrlToStream(url,output_file)
830
+ succeeded = true
831
+ ensure
832
+ if succeeded
833
+ output_file.close()
834
+ else
835
+ begin
836
+ output_file.close()
837
+ rescue Exception
838
+ # Preserve the conversion failure.
839
+ end
840
+ begin
841
+ FileUtils.rm(file_path)
842
+ rescue Exception
843
+ # Removing a failed output must not mask the original failure.
844
+ end
845
+ end
823
846
  end
824
847
  end
825
848
 
@@ -829,6 +852,7 @@ module Pdfcrowd
829
852
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "html-to-pdf", "The file must exist and not be empty.", "convert_file"), 470);
830
853
  end
831
854
 
855
+ @helper.reset_input(@fields, @files, @raw_data)
832
856
  @files['file'] = file
833
857
  @helper.post(@fields, @files, @raw_data)
834
858
  end
@@ -839,6 +863,7 @@ module Pdfcrowd
839
863
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "html-to-pdf", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
840
864
  end
841
865
 
866
+ @helper.reset_input(@fields, @files, @raw_data)
842
867
  @files['file'] = file
843
868
  @helper.post(@fields, @files, @raw_data, out_stream)
844
869
  end
@@ -850,13 +875,25 @@ module Pdfcrowd
850
875
  end
851
876
 
852
877
  output_file = open(file_path, "wb")
878
+ succeeded = false
853
879
  begin
854
- convertFileToStream(file, output_file)
855
- output_file.close()
856
- rescue Error => why
857
- output_file.close()
858
- FileUtils.rm(file_path)
859
- raise
880
+ convertFileToStream(file,output_file)
881
+ succeeded = true
882
+ ensure
883
+ if succeeded
884
+ output_file.close()
885
+ else
886
+ begin
887
+ output_file.close()
888
+ rescue Exception
889
+ # Preserve the conversion failure.
890
+ end
891
+ begin
892
+ FileUtils.rm(file_path)
893
+ rescue Exception
894
+ # Removing a failed output must not mask the original failure.
895
+ end
896
+ end
860
897
  end
861
898
  end
862
899
 
@@ -866,6 +903,7 @@ module Pdfcrowd
866
903
  raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertString", "html-to-pdf", "The string must not be empty.", "convert_string"), 470);
867
904
  end
868
905
 
906
+ @helper.reset_input(@fields, @files, @raw_data)
869
907
  @fields['text'] = text
870
908
  @helper.post(@fields, @files, @raw_data)
871
909
  end
@@ -876,6 +914,7 @@ module Pdfcrowd
876
914
  raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertStringToStream::text", "html-to-pdf", "The string must not be empty.", "convert_string_to_stream"), 470);
877
915
  end
878
916
 
917
+ @helper.reset_input(@fields, @files, @raw_data)
879
918
  @fields['text'] = text
880
919
  @helper.post(@fields, @files, @raw_data, out_stream)
881
920
  end
@@ -887,24 +926,38 @@ module Pdfcrowd
887
926
  end
888
927
 
889
928
  output_file = open(file_path, "wb")
929
+ succeeded = false
890
930
  begin
891
- convertStringToStream(text, output_file)
892
- output_file.close()
893
- rescue Error => why
894
- output_file.close()
895
- FileUtils.rm(file_path)
896
- raise
931
+ convertStringToStream(text,output_file)
932
+ succeeded = true
933
+ ensure
934
+ if succeeded
935
+ output_file.close()
936
+ else
937
+ begin
938
+ output_file.close()
939
+ rescue Exception
940
+ # Preserve the conversion failure.
941
+ end
942
+ begin
943
+ FileUtils.rm(file_path)
944
+ rescue Exception
945
+ # Removing a failed output must not mask the original failure.
946
+ end
947
+ end
897
948
  end
898
949
  end
899
950
 
900
951
  # @see https://pdfcrowd.com/api/html-to-pdf-ruby/ref/#convert_stream
901
952
  def convertStream(in_stream)
953
+ @helper.reset_input(@fields, @files, @raw_data)
902
954
  @raw_data['stream'] = in_stream.read
903
955
  @helper.post(@fields, @files, @raw_data)
904
956
  end
905
957
 
906
958
  # @see https://pdfcrowd.com/api/html-to-pdf-ruby/ref/#convert_stream_to_stream
907
959
  def convertStreamToStream(in_stream, out_stream)
960
+ @helper.reset_input(@fields, @files, @raw_data)
908
961
  @raw_data['stream'] = in_stream.read
909
962
  @helper.post(@fields, @files, @raw_data, out_stream)
910
963
  end
@@ -916,13 +969,25 @@ module Pdfcrowd
916
969
  end
917
970
 
918
971
  output_file = open(file_path, "wb")
972
+ succeeded = false
919
973
  begin
920
- convertStreamToStream(in_stream, output_file)
921
- output_file.close()
922
- rescue Error => why
923
- output_file.close()
924
- FileUtils.rm(file_path)
925
- raise
974
+ convertStreamToStream(in_stream,output_file)
975
+ succeeded = true
976
+ ensure
977
+ if succeeded
978
+ output_file.close()
979
+ else
980
+ begin
981
+ output_file.close()
982
+ rescue Exception
983
+ # Preserve the conversion failure.
984
+ end
985
+ begin
986
+ FileUtils.rm(file_path)
987
+ rescue Exception
988
+ # Removing a failed output must not mask the original failure.
989
+ end
990
+ end
926
991
  end
927
992
  end
928
993
 
@@ -2148,6 +2213,7 @@ module Pdfcrowd
2148
2213
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "html-to-image", "Supported protocols are http:// and https://.", "convert_url"), 470);
2149
2214
  end
2150
2215
 
2216
+ @helper.reset_input(@fields, @files, @raw_data)
2151
2217
  @fields['url'] = url
2152
2218
  @helper.post(@fields, @files, @raw_data)
2153
2219
  end
@@ -2158,6 +2224,7 @@ module Pdfcrowd
2158
2224
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "html-to-image", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
2159
2225
  end
2160
2226
 
2227
+ @helper.reset_input(@fields, @files, @raw_data)
2161
2228
  @fields['url'] = url
2162
2229
  @helper.post(@fields, @files, @raw_data, out_stream)
2163
2230
  end
@@ -2169,13 +2236,25 @@ module Pdfcrowd
2169
2236
  end
2170
2237
 
2171
2238
  output_file = open(file_path, "wb")
2239
+ succeeded = false
2172
2240
  begin
2173
- convertUrlToStream(url, output_file)
2174
- output_file.close()
2175
- rescue Error => why
2176
- output_file.close()
2177
- FileUtils.rm(file_path)
2178
- raise
2241
+ convertUrlToStream(url,output_file)
2242
+ succeeded = true
2243
+ ensure
2244
+ if succeeded
2245
+ output_file.close()
2246
+ else
2247
+ begin
2248
+ output_file.close()
2249
+ rescue Exception
2250
+ # Preserve the conversion failure.
2251
+ end
2252
+ begin
2253
+ FileUtils.rm(file_path)
2254
+ rescue Exception
2255
+ # Removing a failed output must not mask the original failure.
2256
+ end
2257
+ end
2179
2258
  end
2180
2259
  end
2181
2260
 
@@ -2185,6 +2264,7 @@ module Pdfcrowd
2185
2264
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "html-to-image", "The file must exist and not be empty.", "convert_file"), 470);
2186
2265
  end
2187
2266
 
2267
+ @helper.reset_input(@fields, @files, @raw_data)
2188
2268
  @files['file'] = file
2189
2269
  @helper.post(@fields, @files, @raw_data)
2190
2270
  end
@@ -2195,6 +2275,7 @@ module Pdfcrowd
2195
2275
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "html-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
2196
2276
  end
2197
2277
 
2278
+ @helper.reset_input(@fields, @files, @raw_data)
2198
2279
  @files['file'] = file
2199
2280
  @helper.post(@fields, @files, @raw_data, out_stream)
2200
2281
  end
@@ -2206,13 +2287,25 @@ module Pdfcrowd
2206
2287
  end
2207
2288
 
2208
2289
  output_file = open(file_path, "wb")
2290
+ succeeded = false
2209
2291
  begin
2210
- convertFileToStream(file, output_file)
2211
- output_file.close()
2212
- rescue Error => why
2213
- output_file.close()
2214
- FileUtils.rm(file_path)
2215
- raise
2292
+ convertFileToStream(file,output_file)
2293
+ succeeded = true
2294
+ ensure
2295
+ if succeeded
2296
+ output_file.close()
2297
+ else
2298
+ begin
2299
+ output_file.close()
2300
+ rescue Exception
2301
+ # Preserve the conversion failure.
2302
+ end
2303
+ begin
2304
+ FileUtils.rm(file_path)
2305
+ rescue Exception
2306
+ # Removing a failed output must not mask the original failure.
2307
+ end
2308
+ end
2216
2309
  end
2217
2310
  end
2218
2311
 
@@ -2222,6 +2315,7 @@ module Pdfcrowd
2222
2315
  raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertString", "html-to-image", "The string must not be empty.", "convert_string"), 470);
2223
2316
  end
2224
2317
 
2318
+ @helper.reset_input(@fields, @files, @raw_data)
2225
2319
  @fields['text'] = text
2226
2320
  @helper.post(@fields, @files, @raw_data)
2227
2321
  end
@@ -2232,6 +2326,7 @@ module Pdfcrowd
2232
2326
  raise Error.new(Pdfcrowd.create_invalid_value_message(text, "convertStringToStream::text", "html-to-image", "The string must not be empty.", "convert_string_to_stream"), 470);
2233
2327
  end
2234
2328
 
2329
+ @helper.reset_input(@fields, @files, @raw_data)
2235
2330
  @fields['text'] = text
2236
2331
  @helper.post(@fields, @files, @raw_data, out_stream)
2237
2332
  end
@@ -2243,24 +2338,38 @@ module Pdfcrowd
2243
2338
  end
2244
2339
 
2245
2340
  output_file = open(file_path, "wb")
2341
+ succeeded = false
2246
2342
  begin
2247
- convertStringToStream(text, output_file)
2248
- output_file.close()
2249
- rescue Error => why
2250
- output_file.close()
2251
- FileUtils.rm(file_path)
2252
- raise
2343
+ convertStringToStream(text,output_file)
2344
+ succeeded = true
2345
+ ensure
2346
+ if succeeded
2347
+ output_file.close()
2348
+ else
2349
+ begin
2350
+ output_file.close()
2351
+ rescue Exception
2352
+ # Preserve the conversion failure.
2353
+ end
2354
+ begin
2355
+ FileUtils.rm(file_path)
2356
+ rescue Exception
2357
+ # Removing a failed output must not mask the original failure.
2358
+ end
2359
+ end
2253
2360
  end
2254
2361
  end
2255
2362
 
2256
2363
  # @see https://pdfcrowd.com/api/html-to-image-ruby/ref/#convert_stream
2257
2364
  def convertStream(in_stream)
2365
+ @helper.reset_input(@fields, @files, @raw_data)
2258
2366
  @raw_data['stream'] = in_stream.read
2259
2367
  @helper.post(@fields, @files, @raw_data)
2260
2368
  end
2261
2369
 
2262
2370
  # @see https://pdfcrowd.com/api/html-to-image-ruby/ref/#convert_stream_to_stream
2263
2371
  def convertStreamToStream(in_stream, out_stream)
2372
+ @helper.reset_input(@fields, @files, @raw_data)
2264
2373
  @raw_data['stream'] = in_stream.read
2265
2374
  @helper.post(@fields, @files, @raw_data, out_stream)
2266
2375
  end
@@ -2272,13 +2381,25 @@ module Pdfcrowd
2272
2381
  end
2273
2382
 
2274
2383
  output_file = open(file_path, "wb")
2384
+ succeeded = false
2275
2385
  begin
2276
- convertStreamToStream(in_stream, output_file)
2277
- output_file.close()
2278
- rescue Error => why
2279
- output_file.close()
2280
- FileUtils.rm(file_path)
2281
- raise
2386
+ convertStreamToStream(in_stream,output_file)
2387
+ succeeded = true
2388
+ ensure
2389
+ if succeeded
2390
+ output_file.close()
2391
+ else
2392
+ begin
2393
+ output_file.close()
2394
+ rescue Exception
2395
+ # Preserve the conversion failure.
2396
+ end
2397
+ begin
2398
+ FileUtils.rm(file_path)
2399
+ rescue Exception
2400
+ # Removing a failed output must not mask the original failure.
2401
+ end
2402
+ end
2282
2403
  end
2283
2404
  end
2284
2405
 
@@ -2763,6 +2884,7 @@ module Pdfcrowd
2763
2884
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "image-to-image", "Supported protocols are http:// and https://.", "convert_url"), 470);
2764
2885
  end
2765
2886
 
2887
+ @helper.reset_input(@fields, @files, @raw_data)
2766
2888
  @fields['url'] = url
2767
2889
  @helper.post(@fields, @files, @raw_data)
2768
2890
  end
@@ -2773,6 +2895,7 @@ module Pdfcrowd
2773
2895
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "image-to-image", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
2774
2896
  end
2775
2897
 
2898
+ @helper.reset_input(@fields, @files, @raw_data)
2776
2899
  @fields['url'] = url
2777
2900
  @helper.post(@fields, @files, @raw_data, out_stream)
2778
2901
  end
@@ -2784,13 +2907,25 @@ module Pdfcrowd
2784
2907
  end
2785
2908
 
2786
2909
  output_file = open(file_path, "wb")
2910
+ succeeded = false
2787
2911
  begin
2788
- convertUrlToStream(url, output_file)
2789
- output_file.close()
2790
- rescue Error => why
2791
- output_file.close()
2792
- FileUtils.rm(file_path)
2793
- raise
2912
+ convertUrlToStream(url,output_file)
2913
+ succeeded = true
2914
+ ensure
2915
+ if succeeded
2916
+ output_file.close()
2917
+ else
2918
+ begin
2919
+ output_file.close()
2920
+ rescue Exception
2921
+ # Preserve the conversion failure.
2922
+ end
2923
+ begin
2924
+ FileUtils.rm(file_path)
2925
+ rescue Exception
2926
+ # Removing a failed output must not mask the original failure.
2927
+ end
2928
+ end
2794
2929
  end
2795
2930
  end
2796
2931
 
@@ -2800,6 +2935,7 @@ module Pdfcrowd
2800
2935
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "image-to-image", "The file must exist and not be empty.", "convert_file"), 470);
2801
2936
  end
2802
2937
 
2938
+ @helper.reset_input(@fields, @files, @raw_data)
2803
2939
  @files['file'] = file
2804
2940
  @helper.post(@fields, @files, @raw_data)
2805
2941
  end
@@ -2810,6 +2946,7 @@ module Pdfcrowd
2810
2946
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "image-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
2811
2947
  end
2812
2948
 
2949
+ @helper.reset_input(@fields, @files, @raw_data)
2813
2950
  @files['file'] = file
2814
2951
  @helper.post(@fields, @files, @raw_data, out_stream)
2815
2952
  end
@@ -2821,24 +2958,38 @@ module Pdfcrowd
2821
2958
  end
2822
2959
 
2823
2960
  output_file = open(file_path, "wb")
2961
+ succeeded = false
2824
2962
  begin
2825
- convertFileToStream(file, output_file)
2826
- output_file.close()
2827
- rescue Error => why
2828
- output_file.close()
2829
- FileUtils.rm(file_path)
2830
- raise
2963
+ convertFileToStream(file,output_file)
2964
+ succeeded = true
2965
+ ensure
2966
+ if succeeded
2967
+ output_file.close()
2968
+ else
2969
+ begin
2970
+ output_file.close()
2971
+ rescue Exception
2972
+ # Preserve the conversion failure.
2973
+ end
2974
+ begin
2975
+ FileUtils.rm(file_path)
2976
+ rescue Exception
2977
+ # Removing a failed output must not mask the original failure.
2978
+ end
2979
+ end
2831
2980
  end
2832
2981
  end
2833
2982
 
2834
2983
  # @see https://pdfcrowd.com/api/image-to-image-ruby/ref/#convert_raw_data
2835
2984
  def convertRawData(data)
2985
+ @helper.reset_input(@fields, @files, @raw_data)
2836
2986
  @raw_data['file'] = data
2837
2987
  @helper.post(@fields, @files, @raw_data)
2838
2988
  end
2839
2989
 
2840
2990
  # @see https://pdfcrowd.com/api/image-to-image-ruby/ref/#convert_raw_data_to_stream
2841
2991
  def convertRawDataToStream(data, out_stream)
2992
+ @helper.reset_input(@fields, @files, @raw_data)
2842
2993
  @raw_data['file'] = data
2843
2994
  @helper.post(@fields, @files, @raw_data, out_stream)
2844
2995
  end
@@ -2850,24 +3001,38 @@ module Pdfcrowd
2850
3001
  end
2851
3002
 
2852
3003
  output_file = open(file_path, "wb")
3004
+ succeeded = false
2853
3005
  begin
2854
- convertRawDataToStream(data, output_file)
2855
- output_file.close()
2856
- rescue Error => why
2857
- output_file.close()
2858
- FileUtils.rm(file_path)
2859
- raise
3006
+ convertRawDataToStream(data,output_file)
3007
+ succeeded = true
3008
+ ensure
3009
+ if succeeded
3010
+ output_file.close()
3011
+ else
3012
+ begin
3013
+ output_file.close()
3014
+ rescue Exception
3015
+ # Preserve the conversion failure.
3016
+ end
3017
+ begin
3018
+ FileUtils.rm(file_path)
3019
+ rescue Exception
3020
+ # Removing a failed output must not mask the original failure.
3021
+ end
3022
+ end
2860
3023
  end
2861
3024
  end
2862
3025
 
2863
3026
  # @see https://pdfcrowd.com/api/image-to-image-ruby/ref/#convert_stream
2864
3027
  def convertStream(in_stream)
3028
+ @helper.reset_input(@fields, @files, @raw_data)
2865
3029
  @raw_data['stream'] = in_stream.read
2866
3030
  @helper.post(@fields, @files, @raw_data)
2867
3031
  end
2868
3032
 
2869
3033
  # @see https://pdfcrowd.com/api/image-to-image-ruby/ref/#convert_stream_to_stream
2870
3034
  def convertStreamToStream(in_stream, out_stream)
3035
+ @helper.reset_input(@fields, @files, @raw_data)
2871
3036
  @raw_data['stream'] = in_stream.read
2872
3037
  @helper.post(@fields, @files, @raw_data, out_stream)
2873
3038
  end
@@ -2879,13 +3044,25 @@ module Pdfcrowd
2879
3044
  end
2880
3045
 
2881
3046
  output_file = open(file_path, "wb")
3047
+ succeeded = false
2882
3048
  begin
2883
- convertStreamToStream(in_stream, output_file)
2884
- output_file.close()
2885
- rescue Error => why
2886
- output_file.close()
2887
- FileUtils.rm(file_path)
2888
- raise
3049
+ convertStreamToStream(in_stream,output_file)
3050
+ succeeded = true
3051
+ ensure
3052
+ if succeeded
3053
+ output_file.close()
3054
+ else
3055
+ begin
3056
+ output_file.close()
3057
+ rescue Exception
3058
+ # Preserve the conversion failure.
3059
+ end
3060
+ begin
3061
+ FileUtils.rm(file_path)
3062
+ rescue Exception
3063
+ # Removing a failed output must not mask the original failure.
3064
+ end
3065
+ end
2889
3066
  end
2890
3067
  end
2891
3068
 
@@ -3245,8 +3422,26 @@ module Pdfcrowd
3245
3422
  end
3246
3423
 
3247
3424
  output_file = open(file_path, "wb")
3248
- convertToStream(output_file)
3249
- output_file.close()
3425
+ succeeded = false
3426
+ begin
3427
+ convertToStream(output_file)
3428
+ succeeded = true
3429
+ ensure
3430
+ if succeeded
3431
+ output_file.close()
3432
+ else
3433
+ begin
3434
+ output_file.close()
3435
+ rescue Exception
3436
+ # Preserve the conversion failure.
3437
+ end
3438
+ begin
3439
+ FileUtils.rm(file_path)
3440
+ rescue Exception
3441
+ # Removing a failed output must not mask the original failure.
3442
+ end
3443
+ end
3444
+ end
3250
3445
  end
3251
3446
 
3252
3447
  # @see https://pdfcrowd.com/api/pdf-to-pdf-ruby/ref/#add_pdf_file
@@ -3657,6 +3852,7 @@ module Pdfcrowd
3657
3852
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "image-to-pdf", "Supported protocols are http:// and https://.", "convert_url"), 470);
3658
3853
  end
3659
3854
 
3855
+ @helper.reset_input(@fields, @files, @raw_data)
3660
3856
  @fields['url'] = url
3661
3857
  @helper.post(@fields, @files, @raw_data)
3662
3858
  end
@@ -3667,6 +3863,7 @@ module Pdfcrowd
3667
3863
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "image-to-pdf", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
3668
3864
  end
3669
3865
 
3866
+ @helper.reset_input(@fields, @files, @raw_data)
3670
3867
  @fields['url'] = url
3671
3868
  @helper.post(@fields, @files, @raw_data, out_stream)
3672
3869
  end
@@ -3678,13 +3875,25 @@ module Pdfcrowd
3678
3875
  end
3679
3876
 
3680
3877
  output_file = open(file_path, "wb")
3878
+ succeeded = false
3681
3879
  begin
3682
- convertUrlToStream(url, output_file)
3683
- output_file.close()
3684
- rescue Error => why
3685
- output_file.close()
3686
- FileUtils.rm(file_path)
3687
- raise
3880
+ convertUrlToStream(url,output_file)
3881
+ succeeded = true
3882
+ ensure
3883
+ if succeeded
3884
+ output_file.close()
3885
+ else
3886
+ begin
3887
+ output_file.close()
3888
+ rescue Exception
3889
+ # Preserve the conversion failure.
3890
+ end
3891
+ begin
3892
+ FileUtils.rm(file_path)
3893
+ rescue Exception
3894
+ # Removing a failed output must not mask the original failure.
3895
+ end
3896
+ end
3688
3897
  end
3689
3898
  end
3690
3899
 
@@ -3694,6 +3903,7 @@ module Pdfcrowd
3694
3903
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "image-to-pdf", "The file must exist and not be empty.", "convert_file"), 470);
3695
3904
  end
3696
3905
 
3906
+ @helper.reset_input(@fields, @files, @raw_data)
3697
3907
  @files['file'] = file
3698
3908
  @helper.post(@fields, @files, @raw_data)
3699
3909
  end
@@ -3704,6 +3914,7 @@ module Pdfcrowd
3704
3914
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "image-to-pdf", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
3705
3915
  end
3706
3916
 
3917
+ @helper.reset_input(@fields, @files, @raw_data)
3707
3918
  @files['file'] = file
3708
3919
  @helper.post(@fields, @files, @raw_data, out_stream)
3709
3920
  end
@@ -3715,24 +3926,38 @@ module Pdfcrowd
3715
3926
  end
3716
3927
 
3717
3928
  output_file = open(file_path, "wb")
3929
+ succeeded = false
3718
3930
  begin
3719
- convertFileToStream(file, output_file)
3720
- output_file.close()
3721
- rescue Error => why
3722
- output_file.close()
3723
- FileUtils.rm(file_path)
3724
- raise
3931
+ convertFileToStream(file,output_file)
3932
+ succeeded = true
3933
+ ensure
3934
+ if succeeded
3935
+ output_file.close()
3936
+ else
3937
+ begin
3938
+ output_file.close()
3939
+ rescue Exception
3940
+ # Preserve the conversion failure.
3941
+ end
3942
+ begin
3943
+ FileUtils.rm(file_path)
3944
+ rescue Exception
3945
+ # Removing a failed output must not mask the original failure.
3946
+ end
3947
+ end
3725
3948
  end
3726
3949
  end
3727
3950
 
3728
3951
  # @see https://pdfcrowd.com/api/image-to-pdf-ruby/ref/#convert_raw_data
3729
3952
  def convertRawData(data)
3953
+ @helper.reset_input(@fields, @files, @raw_data)
3730
3954
  @raw_data['file'] = data
3731
3955
  @helper.post(@fields, @files, @raw_data)
3732
3956
  end
3733
3957
 
3734
3958
  # @see https://pdfcrowd.com/api/image-to-pdf-ruby/ref/#convert_raw_data_to_stream
3735
3959
  def convertRawDataToStream(data, out_stream)
3960
+ @helper.reset_input(@fields, @files, @raw_data)
3736
3961
  @raw_data['file'] = data
3737
3962
  @helper.post(@fields, @files, @raw_data, out_stream)
3738
3963
  end
@@ -3744,24 +3969,38 @@ module Pdfcrowd
3744
3969
  end
3745
3970
 
3746
3971
  output_file = open(file_path, "wb")
3972
+ succeeded = false
3747
3973
  begin
3748
- convertRawDataToStream(data, output_file)
3749
- output_file.close()
3750
- rescue Error => why
3751
- output_file.close()
3752
- FileUtils.rm(file_path)
3753
- raise
3974
+ convertRawDataToStream(data,output_file)
3975
+ succeeded = true
3976
+ ensure
3977
+ if succeeded
3978
+ output_file.close()
3979
+ else
3980
+ begin
3981
+ output_file.close()
3982
+ rescue Exception
3983
+ # Preserve the conversion failure.
3984
+ end
3985
+ begin
3986
+ FileUtils.rm(file_path)
3987
+ rescue Exception
3988
+ # Removing a failed output must not mask the original failure.
3989
+ end
3990
+ end
3754
3991
  end
3755
3992
  end
3756
3993
 
3757
3994
  # @see https://pdfcrowd.com/api/image-to-pdf-ruby/ref/#convert_stream
3758
3995
  def convertStream(in_stream)
3996
+ @helper.reset_input(@fields, @files, @raw_data)
3759
3997
  @raw_data['stream'] = in_stream.read
3760
3998
  @helper.post(@fields, @files, @raw_data)
3761
3999
  end
3762
4000
 
3763
4001
  # @see https://pdfcrowd.com/api/image-to-pdf-ruby/ref/#convert_stream_to_stream
3764
4002
  def convertStreamToStream(in_stream, out_stream)
4003
+ @helper.reset_input(@fields, @files, @raw_data)
3765
4004
  @raw_data['stream'] = in_stream.read
3766
4005
  @helper.post(@fields, @files, @raw_data, out_stream)
3767
4006
  end
@@ -3773,13 +4012,25 @@ module Pdfcrowd
3773
4012
  end
3774
4013
 
3775
4014
  output_file = open(file_path, "wb")
4015
+ succeeded = false
3776
4016
  begin
3777
- convertStreamToStream(in_stream, output_file)
3778
- output_file.close()
3779
- rescue Error => why
3780
- output_file.close()
3781
- FileUtils.rm(file_path)
3782
- raise
4017
+ convertStreamToStream(in_stream,output_file)
4018
+ succeeded = true
4019
+ ensure
4020
+ if succeeded
4021
+ output_file.close()
4022
+ else
4023
+ begin
4024
+ output_file.close()
4025
+ rescue Exception
4026
+ # Preserve the conversion failure.
4027
+ end
4028
+ begin
4029
+ FileUtils.rm(file_path)
4030
+ rescue Exception
4031
+ # Removing a failed output must not mask the original failure.
4032
+ end
4033
+ end
3783
4034
  end
3784
4035
  end
3785
4036
 
@@ -4351,6 +4602,7 @@ module Pdfcrowd
4351
4602
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "pdf-to-html", "Supported protocols are http:// and https://.", "convert_url"), 470);
4352
4603
  end
4353
4604
 
4605
+ @helper.reset_input(@fields, @files, @raw_data)
4354
4606
  @fields['url'] = url
4355
4607
  @helper.post(@fields, @files, @raw_data)
4356
4608
  end
@@ -4361,6 +4613,7 @@ module Pdfcrowd
4361
4613
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "pdf-to-html", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
4362
4614
  end
4363
4615
 
4616
+ @helper.reset_input(@fields, @files, @raw_data)
4364
4617
  @fields['url'] = url
4365
4618
  @helper.post(@fields, @files, @raw_data, out_stream)
4366
4619
  end
@@ -4376,13 +4629,25 @@ module Pdfcrowd
4376
4629
  end
4377
4630
 
4378
4631
  output_file = open(file_path, "wb")
4632
+ succeeded = false
4379
4633
  begin
4380
- convertUrlToStream(url, output_file)
4381
- output_file.close()
4382
- rescue Error => why
4383
- output_file.close()
4384
- FileUtils.rm(file_path)
4385
- raise
4634
+ convertUrlToStream(url,output_file)
4635
+ succeeded = true
4636
+ ensure
4637
+ if succeeded
4638
+ output_file.close()
4639
+ else
4640
+ begin
4641
+ output_file.close()
4642
+ rescue Exception
4643
+ # Preserve the conversion failure.
4644
+ end
4645
+ begin
4646
+ FileUtils.rm(file_path)
4647
+ rescue Exception
4648
+ # Removing a failed output must not mask the original failure.
4649
+ end
4650
+ end
4386
4651
  end
4387
4652
  end
4388
4653
 
@@ -4392,6 +4657,7 @@ module Pdfcrowd
4392
4657
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "pdf-to-html", "The file must exist and not be empty.", "convert_file"), 470);
4393
4658
  end
4394
4659
 
4660
+ @helper.reset_input(@fields, @files, @raw_data)
4395
4661
  @files['file'] = file
4396
4662
  @helper.post(@fields, @files, @raw_data)
4397
4663
  end
@@ -4402,6 +4668,7 @@ module Pdfcrowd
4402
4668
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "pdf-to-html", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
4403
4669
  end
4404
4670
 
4671
+ @helper.reset_input(@fields, @files, @raw_data)
4405
4672
  @files['file'] = file
4406
4673
  @helper.post(@fields, @files, @raw_data, out_stream)
4407
4674
  end
@@ -4417,24 +4684,38 @@ module Pdfcrowd
4417
4684
  end
4418
4685
 
4419
4686
  output_file = open(file_path, "wb")
4687
+ succeeded = false
4420
4688
  begin
4421
- convertFileToStream(file, output_file)
4422
- output_file.close()
4423
- rescue Error => why
4424
- output_file.close()
4425
- FileUtils.rm(file_path)
4426
- raise
4689
+ convertFileToStream(file,output_file)
4690
+ succeeded = true
4691
+ ensure
4692
+ if succeeded
4693
+ output_file.close()
4694
+ else
4695
+ begin
4696
+ output_file.close()
4697
+ rescue Exception
4698
+ # Preserve the conversion failure.
4699
+ end
4700
+ begin
4701
+ FileUtils.rm(file_path)
4702
+ rescue Exception
4703
+ # Removing a failed output must not mask the original failure.
4704
+ end
4705
+ end
4427
4706
  end
4428
4707
  end
4429
4708
 
4430
4709
  # @see https://pdfcrowd.com/api/pdf-to-html-ruby/ref/#convert_raw_data
4431
4710
  def convertRawData(data)
4711
+ @helper.reset_input(@fields, @files, @raw_data)
4432
4712
  @raw_data['file'] = data
4433
4713
  @helper.post(@fields, @files, @raw_data)
4434
4714
  end
4435
4715
 
4436
4716
  # @see https://pdfcrowd.com/api/pdf-to-html-ruby/ref/#convert_raw_data_to_stream
4437
4717
  def convertRawDataToStream(data, out_stream)
4718
+ @helper.reset_input(@fields, @files, @raw_data)
4438
4719
  @raw_data['file'] = data
4439
4720
  @helper.post(@fields, @files, @raw_data, out_stream)
4440
4721
  end
@@ -4450,24 +4731,38 @@ module Pdfcrowd
4450
4731
  end
4451
4732
 
4452
4733
  output_file = open(file_path, "wb")
4734
+ succeeded = false
4453
4735
  begin
4454
- convertRawDataToStream(data, output_file)
4455
- output_file.close()
4456
- rescue Error => why
4457
- output_file.close()
4458
- FileUtils.rm(file_path)
4459
- raise
4736
+ convertRawDataToStream(data,output_file)
4737
+ succeeded = true
4738
+ ensure
4739
+ if succeeded
4740
+ output_file.close()
4741
+ else
4742
+ begin
4743
+ output_file.close()
4744
+ rescue Exception
4745
+ # Preserve the conversion failure.
4746
+ end
4747
+ begin
4748
+ FileUtils.rm(file_path)
4749
+ rescue Exception
4750
+ # Removing a failed output must not mask the original failure.
4751
+ end
4752
+ end
4460
4753
  end
4461
4754
  end
4462
4755
 
4463
4756
  # @see https://pdfcrowd.com/api/pdf-to-html-ruby/ref/#convert_stream
4464
4757
  def convertStream(in_stream)
4758
+ @helper.reset_input(@fields, @files, @raw_data)
4465
4759
  @raw_data['stream'] = in_stream.read
4466
4760
  @helper.post(@fields, @files, @raw_data)
4467
4761
  end
4468
4762
 
4469
4763
  # @see https://pdfcrowd.com/api/pdf-to-html-ruby/ref/#convert_stream_to_stream
4470
4764
  def convertStreamToStream(in_stream, out_stream)
4765
+ @helper.reset_input(@fields, @files, @raw_data)
4471
4766
  @raw_data['stream'] = in_stream.read
4472
4767
  @helper.post(@fields, @files, @raw_data, out_stream)
4473
4768
  end
@@ -4483,13 +4778,25 @@ module Pdfcrowd
4483
4778
  end
4484
4779
 
4485
4780
  output_file = open(file_path, "wb")
4781
+ succeeded = false
4486
4782
  begin
4487
- convertStreamToStream(in_stream, output_file)
4488
- output_file.close()
4489
- rescue Error => why
4490
- output_file.close()
4491
- FileUtils.rm(file_path)
4492
- raise
4783
+ convertStreamToStream(in_stream,output_file)
4784
+ succeeded = true
4785
+ ensure
4786
+ if succeeded
4787
+ output_file.close()
4788
+ else
4789
+ begin
4790
+ output_file.close()
4791
+ rescue Exception
4792
+ # Preserve the conversion failure.
4793
+ end
4794
+ begin
4795
+ FileUtils.rm(file_path)
4796
+ rescue Exception
4797
+ # Removing a failed output must not mask the original failure.
4798
+ end
4799
+ end
4493
4800
  end
4494
4801
  end
4495
4802
 
@@ -4773,6 +5080,7 @@ module Pdfcrowd
4773
5080
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "pdf-to-text", "Supported protocols are http:// and https://.", "convert_url"), 470);
4774
5081
  end
4775
5082
 
5083
+ @helper.reset_input(@fields, @files, @raw_data)
4776
5084
  @fields['url'] = url
4777
5085
  @helper.post(@fields, @files, @raw_data)
4778
5086
  end
@@ -4783,6 +5091,7 @@ module Pdfcrowd
4783
5091
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "pdf-to-text", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
4784
5092
  end
4785
5093
 
5094
+ @helper.reset_input(@fields, @files, @raw_data)
4786
5095
  @fields['url'] = url
4787
5096
  @helper.post(@fields, @files, @raw_data, out_stream)
4788
5097
  end
@@ -4794,13 +5103,25 @@ module Pdfcrowd
4794
5103
  end
4795
5104
 
4796
5105
  output_file = open(file_path, "wb")
5106
+ succeeded = false
4797
5107
  begin
4798
- convertUrlToStream(url, output_file)
4799
- output_file.close()
4800
- rescue Error => why
4801
- output_file.close()
4802
- FileUtils.rm(file_path)
4803
- raise
5108
+ convertUrlToStream(url,output_file)
5109
+ succeeded = true
5110
+ ensure
5111
+ if succeeded
5112
+ output_file.close()
5113
+ else
5114
+ begin
5115
+ output_file.close()
5116
+ rescue Exception
5117
+ # Preserve the conversion failure.
5118
+ end
5119
+ begin
5120
+ FileUtils.rm(file_path)
5121
+ rescue Exception
5122
+ # Removing a failed output must not mask the original failure.
5123
+ end
5124
+ end
4804
5125
  end
4805
5126
  end
4806
5127
 
@@ -4810,6 +5131,7 @@ module Pdfcrowd
4810
5131
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "pdf-to-text", "The file must exist and not be empty.", "convert_file"), 470);
4811
5132
  end
4812
5133
 
5134
+ @helper.reset_input(@fields, @files, @raw_data)
4813
5135
  @files['file'] = file
4814
5136
  @helper.post(@fields, @files, @raw_data)
4815
5137
  end
@@ -4820,6 +5142,7 @@ module Pdfcrowd
4820
5142
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "pdf-to-text", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
4821
5143
  end
4822
5144
 
5145
+ @helper.reset_input(@fields, @files, @raw_data)
4823
5146
  @files['file'] = file
4824
5147
  @helper.post(@fields, @files, @raw_data, out_stream)
4825
5148
  end
@@ -4831,24 +5154,38 @@ module Pdfcrowd
4831
5154
  end
4832
5155
 
4833
5156
  output_file = open(file_path, "wb")
5157
+ succeeded = false
4834
5158
  begin
4835
- convertFileToStream(file, output_file)
4836
- output_file.close()
4837
- rescue Error => why
4838
- output_file.close()
4839
- FileUtils.rm(file_path)
4840
- raise
5159
+ convertFileToStream(file,output_file)
5160
+ succeeded = true
5161
+ ensure
5162
+ if succeeded
5163
+ output_file.close()
5164
+ else
5165
+ begin
5166
+ output_file.close()
5167
+ rescue Exception
5168
+ # Preserve the conversion failure.
5169
+ end
5170
+ begin
5171
+ FileUtils.rm(file_path)
5172
+ rescue Exception
5173
+ # Removing a failed output must not mask the original failure.
5174
+ end
5175
+ end
4841
5176
  end
4842
5177
  end
4843
5178
 
4844
5179
  # @see https://pdfcrowd.com/api/pdf-to-text-ruby/ref/#convert_raw_data
4845
5180
  def convertRawData(data)
5181
+ @helper.reset_input(@fields, @files, @raw_data)
4846
5182
  @raw_data['file'] = data
4847
5183
  @helper.post(@fields, @files, @raw_data)
4848
5184
  end
4849
5185
 
4850
5186
  # @see https://pdfcrowd.com/api/pdf-to-text-ruby/ref/#convert_raw_data_to_stream
4851
5187
  def convertRawDataToStream(data, out_stream)
5188
+ @helper.reset_input(@fields, @files, @raw_data)
4852
5189
  @raw_data['file'] = data
4853
5190
  @helper.post(@fields, @files, @raw_data, out_stream)
4854
5191
  end
@@ -4860,24 +5197,38 @@ module Pdfcrowd
4860
5197
  end
4861
5198
 
4862
5199
  output_file = open(file_path, "wb")
5200
+ succeeded = false
4863
5201
  begin
4864
- convertRawDataToStream(data, output_file)
4865
- output_file.close()
4866
- rescue Error => why
4867
- output_file.close()
4868
- FileUtils.rm(file_path)
4869
- raise
5202
+ convertRawDataToStream(data,output_file)
5203
+ succeeded = true
5204
+ ensure
5205
+ if succeeded
5206
+ output_file.close()
5207
+ else
5208
+ begin
5209
+ output_file.close()
5210
+ rescue Exception
5211
+ # Preserve the conversion failure.
5212
+ end
5213
+ begin
5214
+ FileUtils.rm(file_path)
5215
+ rescue Exception
5216
+ # Removing a failed output must not mask the original failure.
5217
+ end
5218
+ end
4870
5219
  end
4871
5220
  end
4872
5221
 
4873
5222
  # @see https://pdfcrowd.com/api/pdf-to-text-ruby/ref/#convert_stream
4874
5223
  def convertStream(in_stream)
5224
+ @helper.reset_input(@fields, @files, @raw_data)
4875
5225
  @raw_data['stream'] = in_stream.read
4876
5226
  @helper.post(@fields, @files, @raw_data)
4877
5227
  end
4878
5228
 
4879
5229
  # @see https://pdfcrowd.com/api/pdf-to-text-ruby/ref/#convert_stream_to_stream
4880
5230
  def convertStreamToStream(in_stream, out_stream)
5231
+ @helper.reset_input(@fields, @files, @raw_data)
4881
5232
  @raw_data['stream'] = in_stream.read
4882
5233
  @helper.post(@fields, @files, @raw_data, out_stream)
4883
5234
  end
@@ -4889,13 +5240,25 @@ module Pdfcrowd
4889
5240
  end
4890
5241
 
4891
5242
  output_file = open(file_path, "wb")
5243
+ succeeded = false
4892
5244
  begin
4893
- convertStreamToStream(in_stream, output_file)
4894
- output_file.close()
4895
- rescue Error => why
4896
- output_file.close()
4897
- FileUtils.rm(file_path)
4898
- raise
5245
+ convertStreamToStream(in_stream,output_file)
5246
+ succeeded = true
5247
+ ensure
5248
+ if succeeded
5249
+ output_file.close()
5250
+ else
5251
+ begin
5252
+ output_file.close()
5253
+ rescue Exception
5254
+ # Preserve the conversion failure.
5255
+ end
5256
+ begin
5257
+ FileUtils.rm(file_path)
5258
+ rescue Exception
5259
+ # Removing a failed output must not mask the original failure.
5260
+ end
5261
+ end
4899
5262
  end
4900
5263
  end
4901
5264
 
@@ -5149,6 +5512,7 @@ module Pdfcrowd
5149
5512
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrl", "pdf-to-image", "Supported protocols are http:// and https://.", "convert_url"), 470);
5150
5513
  end
5151
5514
 
5515
+ @helper.reset_input(@fields, @files, @raw_data)
5152
5516
  @fields['url'] = url
5153
5517
  @helper.post(@fields, @files, @raw_data)
5154
5518
  end
@@ -5159,6 +5523,7 @@ module Pdfcrowd
5159
5523
  raise Error.new(Pdfcrowd.create_invalid_value_message(url, "convertUrlToStream::url", "pdf-to-image", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470);
5160
5524
  end
5161
5525
 
5526
+ @helper.reset_input(@fields, @files, @raw_data)
5162
5527
  @fields['url'] = url
5163
5528
  @helper.post(@fields, @files, @raw_data, out_stream)
5164
5529
  end
@@ -5170,13 +5535,25 @@ module Pdfcrowd
5170
5535
  end
5171
5536
 
5172
5537
  output_file = open(file_path, "wb")
5538
+ succeeded = false
5173
5539
  begin
5174
- convertUrlToStream(url, output_file)
5175
- output_file.close()
5176
- rescue Error => why
5177
- output_file.close()
5178
- FileUtils.rm(file_path)
5179
- raise
5540
+ convertUrlToStream(url,output_file)
5541
+ succeeded = true
5542
+ ensure
5543
+ if succeeded
5544
+ output_file.close()
5545
+ else
5546
+ begin
5547
+ output_file.close()
5548
+ rescue Exception
5549
+ # Preserve the conversion failure.
5550
+ end
5551
+ begin
5552
+ FileUtils.rm(file_path)
5553
+ rescue Exception
5554
+ # Removing a failed output must not mask the original failure.
5555
+ end
5556
+ end
5180
5557
  end
5181
5558
  end
5182
5559
 
@@ -5186,6 +5563,7 @@ module Pdfcrowd
5186
5563
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFile", "pdf-to-image", "The file must exist and not be empty.", "convert_file"), 470);
5187
5564
  end
5188
5565
 
5566
+ @helper.reset_input(@fields, @files, @raw_data)
5189
5567
  @files['file'] = file
5190
5568
  @helper.post(@fields, @files, @raw_data)
5191
5569
  end
@@ -5196,6 +5574,7 @@ module Pdfcrowd
5196
5574
  raise Error.new(Pdfcrowd.create_invalid_value_message(file, "convertFileToStream::file", "pdf-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470);
5197
5575
  end
5198
5576
 
5577
+ @helper.reset_input(@fields, @files, @raw_data)
5199
5578
  @files['file'] = file
5200
5579
  @helper.post(@fields, @files, @raw_data, out_stream)
5201
5580
  end
@@ -5207,24 +5586,38 @@ module Pdfcrowd
5207
5586
  end
5208
5587
 
5209
5588
  output_file = open(file_path, "wb")
5589
+ succeeded = false
5210
5590
  begin
5211
- convertFileToStream(file, output_file)
5212
- output_file.close()
5213
- rescue Error => why
5214
- output_file.close()
5215
- FileUtils.rm(file_path)
5216
- raise
5591
+ convertFileToStream(file,output_file)
5592
+ succeeded = true
5593
+ ensure
5594
+ if succeeded
5595
+ output_file.close()
5596
+ else
5597
+ begin
5598
+ output_file.close()
5599
+ rescue Exception
5600
+ # Preserve the conversion failure.
5601
+ end
5602
+ begin
5603
+ FileUtils.rm(file_path)
5604
+ rescue Exception
5605
+ # Removing a failed output must not mask the original failure.
5606
+ end
5607
+ end
5217
5608
  end
5218
5609
  end
5219
5610
 
5220
5611
  # @see https://pdfcrowd.com/api/pdf-to-image-ruby/ref/#convert_raw_data
5221
5612
  def convertRawData(data)
5613
+ @helper.reset_input(@fields, @files, @raw_data)
5222
5614
  @raw_data['file'] = data
5223
5615
  @helper.post(@fields, @files, @raw_data)
5224
5616
  end
5225
5617
 
5226
5618
  # @see https://pdfcrowd.com/api/pdf-to-image-ruby/ref/#convert_raw_data_to_stream
5227
5619
  def convertRawDataToStream(data, out_stream)
5620
+ @helper.reset_input(@fields, @files, @raw_data)
5228
5621
  @raw_data['file'] = data
5229
5622
  @helper.post(@fields, @files, @raw_data, out_stream)
5230
5623
  end
@@ -5236,24 +5629,38 @@ module Pdfcrowd
5236
5629
  end
5237
5630
 
5238
5631
  output_file = open(file_path, "wb")
5632
+ succeeded = false
5239
5633
  begin
5240
- convertRawDataToStream(data, output_file)
5241
- output_file.close()
5242
- rescue Error => why
5243
- output_file.close()
5244
- FileUtils.rm(file_path)
5245
- raise
5634
+ convertRawDataToStream(data,output_file)
5635
+ succeeded = true
5636
+ ensure
5637
+ if succeeded
5638
+ output_file.close()
5639
+ else
5640
+ begin
5641
+ output_file.close()
5642
+ rescue Exception
5643
+ # Preserve the conversion failure.
5644
+ end
5645
+ begin
5646
+ FileUtils.rm(file_path)
5647
+ rescue Exception
5648
+ # Removing a failed output must not mask the original failure.
5649
+ end
5650
+ end
5246
5651
  end
5247
5652
  end
5248
5653
 
5249
5654
  # @see https://pdfcrowd.com/api/pdf-to-image-ruby/ref/#convert_stream
5250
5655
  def convertStream(in_stream)
5656
+ @helper.reset_input(@fields, @files, @raw_data)
5251
5657
  @raw_data['stream'] = in_stream.read
5252
5658
  @helper.post(@fields, @files, @raw_data)
5253
5659
  end
5254
5660
 
5255
5661
  # @see https://pdfcrowd.com/api/pdf-to-image-ruby/ref/#convert_stream_to_stream
5256
5662
  def convertStreamToStream(in_stream, out_stream)
5663
+ @helper.reset_input(@fields, @files, @raw_data)
5257
5664
  @raw_data['stream'] = in_stream.read
5258
5665
  @helper.post(@fields, @files, @raw_data, out_stream)
5259
5666
  end
@@ -5265,13 +5672,25 @@ module Pdfcrowd
5265
5672
  end
5266
5673
 
5267
5674
  output_file = open(file_path, "wb")
5675
+ succeeded = false
5268
5676
  begin
5269
- convertStreamToStream(in_stream, output_file)
5270
- output_file.close()
5271
- rescue Error => why
5272
- output_file.close()
5273
- FileUtils.rm(file_path)
5274
- raise
5677
+ convertStreamToStream(in_stream,output_file)
5678
+ succeeded = true
5679
+ ensure
5680
+ if succeeded
5681
+ output_file.close()
5682
+ else
5683
+ begin
5684
+ output_file.close()
5685
+ rescue Exception
5686
+ # Preserve the conversion failure.
5687
+ end
5688
+ begin
5689
+ FileUtils.rm(file_path)
5690
+ rescue Exception
5691
+ # Removing a failed output must not mask the original failure.
5692
+ end
5693
+ end
5275
5694
  end
5276
5695
  end
5277
5696