aspose_pdf_cloud 1.0.2 → 18.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +42 -0
  3. data/.swagger-codegen-ignore +58 -0
  4. data/.swagger-codegen/VERSION +1 -0
  5. data/LICENSE +21 -22
  6. data/README.md +51 -43
  7. data/aspose_pdf_cloud.gemspec +32 -8
  8. data/lib/aspose_pdf_cloud.rb +93 -58
  9. data/lib/aspose_pdf_cloud/api/pdf_api.rb +2624 -1916
  10. data/lib/aspose_pdf_cloud/api_client.rb +280 -92
  11. data/lib/aspose_pdf_cloud/api_error.rb +29 -6
  12. data/lib/aspose_pdf_cloud/configuration.rb +86 -63
  13. data/lib/aspose_pdf_cloud/models/annotation.rb +218 -45
  14. data/lib/aspose_pdf_cloud/models/annotation_response.rb +195 -34
  15. data/lib/aspose_pdf_cloud/models/annotations.rb +187 -25
  16. data/lib/aspose_pdf_cloud/models/annotations_response.rb +195 -34
  17. data/lib/aspose_pdf_cloud/models/append_document.rb +198 -23
  18. data/lib/aspose_pdf_cloud/models/attachment.rb +224 -49
  19. data/lib/aspose_pdf_cloud/models/attachment_response.rb +195 -34
  20. data/lib/aspose_pdf_cloud/models/attachments.rb +187 -25
  21. data/lib/aspose_pdf_cloud/models/attachments_response.rb +195 -34
  22. data/lib/aspose_pdf_cloud/models/bookmarks.rb +187 -25
  23. data/lib/aspose_pdf_cloud/models/bookmarks_response.rb +195 -34
  24. data/lib/aspose_pdf_cloud/models/color.rb +214 -31
  25. data/lib/aspose_pdf_cloud/models/document.rb +194 -29
  26. data/lib/aspose_pdf_cloud/models/document_pages_response.rb +195 -34
  27. data/lib/aspose_pdf_cloud/models/document_properties.rb +187 -25
  28. data/lib/aspose_pdf_cloud/models/document_properties_response.rb +195 -34
  29. data/lib/aspose_pdf_cloud/models/document_property.rb +197 -33
  30. data/lib/aspose_pdf_cloud/models/document_property_response.rb +195 -34
  31. data/lib/aspose_pdf_cloud/models/document_response.rb +206 -34
  32. data/lib/aspose_pdf_cloud/models/document_text_replace_response.rb +203 -41
  33. data/lib/aspose_pdf_cloud/models/field.rb +213 -42
  34. data/lib/aspose_pdf_cloud/models/field_response.rb +195 -34
  35. data/lib/aspose_pdf_cloud/models/field_type.rb +44 -0
  36. data/lib/aspose_pdf_cloud/models/fields.rb +187 -25
  37. data/lib/aspose_pdf_cloud/models/fields_response.rb +195 -34
  38. data/lib/aspose_pdf_cloud/models/font_styles.rb +43 -0
  39. data/lib/aspose_pdf_cloud/models/horizontal_alignment.rb +44 -0
  40. data/lib/aspose_pdf_cloud/models/http_status_code.rb +87 -0
  41. data/lib/aspose_pdf_cloud/models/image.rb +194 -29
  42. data/lib/aspose_pdf_cloud/models/image_response.rb +195 -34
  43. data/lib/aspose_pdf_cloud/models/images.rb +187 -25
  44. data/lib/aspose_pdf_cloud/models/images_list_request.rb +205 -0
  45. data/lib/aspose_pdf_cloud/models/images_response.rb +195 -34
  46. data/lib/aspose_pdf_cloud/models/line_spacing.rb +43 -0
  47. data/lib/aspose_pdf_cloud/models/link.rb +194 -27
  48. data/lib/aspose_pdf_cloud/models/link_action_type.rb +46 -0
  49. data/lib/aspose_pdf_cloud/models/link_annotation.rb +204 -39
  50. data/lib/aspose_pdf_cloud/models/link_annotation_response.rb +195 -34
  51. data/lib/aspose_pdf_cloud/models/link_annotations.rb +187 -25
  52. data/lib/aspose_pdf_cloud/models/link_annotations_response.rb +195 -34
  53. data/lib/aspose_pdf_cloud/models/link_element.rb +175 -14
  54. data/lib/aspose_pdf_cloud/models/link_highlighting_mode.rb +45 -0
  55. data/lib/aspose_pdf_cloud/models/merge_documents.rb +175 -14
  56. data/lib/aspose_pdf_cloud/models/optimize_options.rb +293 -0
  57. data/lib/aspose_pdf_cloud/models/page.rb +198 -33
  58. data/lib/aspose_pdf_cloud/models/page_text_replace_response.rb +203 -41
  59. data/lib/aspose_pdf_cloud/models/page_word_count.rb +192 -19
  60. data/lib/aspose_pdf_cloud/models/pages.rb +187 -25
  61. data/lib/aspose_pdf_cloud/models/paragraph.rb +303 -0
  62. data/lib/aspose_pdf_cloud/models/rectangle.rb +210 -27
  63. data/lib/aspose_pdf_cloud/models/rotation.rb +44 -0
  64. data/lib/aspose_pdf_cloud/models/saa_spose_response.rb +213 -0
  65. data/lib/aspose_pdf_cloud/models/segment.rb +206 -0
  66. data/lib/aspose_pdf_cloud/models/signature.rb +278 -54
  67. data/lib/aspose_pdf_cloud/models/signature_type.rb +42 -0
  68. data/lib/aspose_pdf_cloud/models/split_result.rb +175 -14
  69. data/lib/aspose_pdf_cloud/models/split_result_document.rb +206 -37
  70. data/lib/aspose_pdf_cloud/models/split_result_response.rb +196 -34
  71. data/lib/aspose_pdf_cloud/models/stamp.rb +312 -104
  72. data/lib/aspose_pdf_cloud/models/stamp_type.rb +44 -0
  73. data/lib/aspose_pdf_cloud/models/text_format.rb +197 -33
  74. data/lib/aspose_pdf_cloud/models/text_format_response.rb +195 -34
  75. data/lib/aspose_pdf_cloud/models/text_horizontal_alignment.rb +47 -0
  76. data/lib/aspose_pdf_cloud/models/text_item.rb +192 -29
  77. data/lib/aspose_pdf_cloud/models/text_item_response.rb +195 -34
  78. data/lib/aspose_pdf_cloud/models/text_items.rb +187 -25
  79. data/lib/aspose_pdf_cloud/models/text_items_response.rb +195 -34
  80. data/lib/aspose_pdf_cloud/models/text_line.rb +210 -0
  81. data/lib/aspose_pdf_cloud/models/text_rect.rb +220 -0
  82. data/lib/aspose_pdf_cloud/models/text_rects.rb +199 -0
  83. data/lib/aspose_pdf_cloud/models/text_rects_response.rb +222 -0
  84. data/lib/aspose_pdf_cloud/models/text_replace.rb +225 -25
  85. data/lib/aspose_pdf_cloud/models/text_replace_list_request.rb +209 -16
  86. data/lib/aspose_pdf_cloud/models/text_replace_request.rb +262 -0
  87. data/lib/aspose_pdf_cloud/models/text_replace_response.rb +222 -0
  88. data/lib/aspose_pdf_cloud/models/text_state.rb +211 -32
  89. data/lib/aspose_pdf_cloud/models/tiff_export_options.rb +266 -75
  90. data/lib/aspose_pdf_cloud/models/vertical_alignment.rb +45 -0
  91. data/lib/aspose_pdf_cloud/models/word_count.rb +174 -14
  92. data/lib/aspose_pdf_cloud/models/word_count_response.rb +196 -34
  93. data/lib/aspose_pdf_cloud/models/wrap_mode.rb +44 -0
  94. data/lib/aspose_pdf_cloud/version.rb +23 -2
  95. data/test/pdf_tests.rb +1268 -623
  96. data/test_data/33539.jpg +0 -0
  97. data/test_data/44781.jpg +0 -0
  98. data/test_data/4pages.pdf +0 -0
  99. data/test_data/BlankWithSignature.pdf +0 -0
  100. data/test_data/Hello_world.pdf +0 -0
  101. data/test_data/HtmlExample1.html +27 -0
  102. data/test_data/Koala.jpg +0 -0
  103. data/test_data/PdfWithAcroForm.pdf +321 -0
  104. data/test_data/PdfWithAnnotations.pdf +720 -1
  105. data/test_data/PdfWithBookmarks.pdf +0 -0
  106. data/test_data/PdfWithEmbeddedFiles.pdf +0 -0
  107. data/test_data/PdfWithImages2.pdf +0 -0
  108. data/test_data/PdfWithLinks.pdf +0 -0
  109. data/test_data/Penguins.jpg +0 -0
  110. data/test_data/butterfly.jpg +0 -0
  111. data/test_data/marketing.pdf +0 -0
  112. data/test_data/rusdoc.pdf +0 -0
  113. data/test_data/test1234.pfx +0 -0
  114. metadata +54 -13
  115. data/lib/aspose_pdf_cloud/models/barcode_response_list.rb +0 -45
  116. data/lib/aspose_pdf_cloud/models/base_object.rb +0 -86
  117. data/lib/aspose_pdf_cloud/models/base_response.rb +0 -61
  118. data/lib/aspose_pdf_cloud/models/page_response.rb +0 -61
@@ -0,0 +1,44 @@
1
+ =begin
2
+ --------------------------------------------------------------------------------------------------------------------
3
+ Copyright (c) 2018 Aspose.Pdf for Cloud
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ SOFTWARE.
19
+ --------------------------------------------------------------------------------------------------------------------
20
+ =end
21
+
22
+ require 'date'
23
+
24
+ module AsposePdfCloud
25
+ class WrapMode
26
+
27
+ NO_WRAP = "NoWrap".freeze
28
+ BY_WORDS = "ByWords".freeze
29
+ DISCRETIONARY_HYPHENATION = "DiscretionaryHyphenation".freeze
30
+
31
+ # Builds the enum from string
32
+ # @param [String] The enum value in the form of the string
33
+ # @return [String] The enum value
34
+ def build_from_hash(value)
35
+ # resolve issue with Concstant Name modification (ex: "FooName" to :FOO_NAME)
36
+ # consantValues = WrapMode.constants.select{|c| c.to_s == value}
37
+ constantValues = WrapMode.constants.select{ |const_name| WrapMode.const_get(const_name) == value}
38
+
39
+ raise "Invalid ENUM value #{value} for class #WrapMode" if constantValues.empty?
40
+ value
41
+ end
42
+ end
43
+
44
+ end
@@ -1,3 +1,24 @@
1
- module AsposePDFCloud
2
- VERSION = "1.0.2"
1
+ =begin
2
+ --------------------------------------------------------------------------------------------------------------------
3
+ Copyright (c) 2018 Aspose.Pdf for Cloud
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ SOFTWARE.
19
+ --------------------------------------------------------------------------------------------------------------------
20
+ =end
21
+
22
+ module AsposePdfCloud
23
+ VERSION = "18.2.0"
3
24
  end
@@ -1,623 +1,1268 @@
1
- require "minitest/autorun"
2
- require "minitest/unit"
3
-
4
- require_relative '../lib/aspose_pdf_cloud'
5
-
6
- class PDFTests < Minitest::Test
7
- include MiniTest::Assertions
8
- include AsposePDFCloud
9
- include AsposeStorageCloud
10
-
11
- def setup
12
- #Get App key and App SID from https://cloud.aspose.com
13
- AsposeApp.app_key_and_sid("", "")
14
- @pdf_api = PdfApi.new
15
- end
16
-
17
- def teardown
18
- end
19
-
20
- def upload_file(file_name)
21
- @storage_api = StorageApi.new
22
- response = @storage_api.put_create(file_name, File.open("../../../data/" << file_name,"r") { |io| io.read } )
23
- assert(response, message="Failed to upload {file_name} file.")
24
- end
25
-
26
- def test_put_convert_document
27
- file_name = "Sample.pdf"
28
-
29
- response = @pdf_api.put_convert_document(File.open("../../../data/" << file_name,"r") { |io| io.read }, {format: "doc"})
30
- assert(response, message="Failed to convert document from request content to format specified")
31
- end
32
-
33
- def test_get_document_with_format
34
- file_name = "Sample.pdf"
35
- upload_file(file_name)
36
-
37
- format = "html"
38
- response = @pdf_api.get_document_with_format(file_name, format)
39
- assert(response, message="Failed to convert document to specified format")
40
- end
41
-
42
- def test_put_create_document
43
- file_name = "newPDFFile.pdf"
44
- response = @pdf_api.put_create_document(file_name)
45
- assert(response, message="Failed to create new document")
46
- end
47
-
48
- def test_put_document_save_as_tiff
49
- file_name = "Sample.pdf"
50
- upload_file(file_name)
51
- result_file = "sample.tiff"
52
- upload_file(result_file)
53
-
54
- tiff_export_options = TiffExportOptions.new
55
- tiff_export_options.result_file = result_file;
56
-
57
- response = @pdf_api.put_document_save_as_tiff(file_name, tiff_export_options)
58
- assert(response, message="Failed to save document as Tiff image")
59
- end
60
-
61
- def test_post_append_document
62
- file_name = "Sample.pdf"
63
- upload_file(file_name)
64
- append_file_name = "sample-input.pdf"
65
- upload_file(append_file_name)
66
-
67
- append_document = AppendDocument.new
68
- append_document.document = append_file_name;
69
- append_document.start_page = 2
70
- append_document.end_page = 3
71
-
72
- response = @pdf_api.post_append_document(file_name, append_document)
73
- assert(response, message="Failed to append document to existing one.")
74
- end
75
-
76
- def test_get_document_attachments
77
- file_name = "SampleAttachment.pdf"
78
- upload_file(file_name)
79
-
80
- response = @pdf_api.get_document_attachments(file_name)
81
- assert(response, message="Failed to read document attachments info.")
82
- end
83
-
84
- def test_get_document_attachment_by_index
85
- file_name = "SampleAttachment.pdf"
86
- upload_file(file_name)
87
-
88
- attachment_index = 1
89
- response = @pdf_api.get_document_attachment_by_index(file_name, attachment_index)
90
- assert(response, message="Failed to read document attachment info by its index")
91
- end
92
-
93
- def test_get_download_document_attachment_by_index
94
- file_name = "SampleAttachment.pdf"
95
- upload_file(file_name)
96
-
97
- attachment_index = 1
98
- response = @pdf_api.get_download_document_attachment_by_index(file_name, attachment_index)
99
- assert(response, message="Failed to download document attachment content by its index")
100
- end
101
-
102
- def test_get_document_bookmarks
103
- file_name = "Sample-Bookmark.pdf"
104
- upload_file(file_name)
105
-
106
- response = @pdf_api.get_document_bookmarks(file_name)
107
- assert(response, message="Failed to read document bookmarks")
108
- end
109
-
110
- def test_get_document_bookmarks_children
111
- file_name = "Sample-Bookmark.pdf"
112
- upload_file(file_name)
113
-
114
- bookmark_path = "1"
115
- response = @pdf_api.get_document_bookmarks_children(file_name, bookmark_path)
116
- assert(response, message="Failed to read document bookmark/bookmarks (including children).")
117
- end
118
-
119
- def test_get_document_properties
120
- file_name = "Sample-Annotation.pdf"
121
- upload_file(file_name)
122
-
123
- response = @pdf_api.get_document_properties(file_name)
124
- assert(response, message="Failed to read document properties")
125
- end
126
-
127
- def test_delete_properties
128
- file_name = "Sample-Annotation.pdf"
129
- upload_file(file_name)
130
-
131
- response = @pdf_api.delete_properties(file_name)
132
- assert(response, message="Failed to delete document properties.")
133
- end
134
-
135
- def test_get_document_property
136
- file_name = "Sample-Annotation.pdf"
137
- upload_file(file_name)
138
-
139
- property_name = "author"
140
- response = @pdf_api.get_document_property(file_name, property_name)
141
- assert(response, message="Failed to read document property by name.")
142
- end
143
-
144
- def test_put_set_property
145
- file_name = "Sample-Annotation.pdf"
146
- upload_file(file_name)
147
-
148
- property_name = "AsposeDev"
149
- document_property = DocumentProperty.new
150
- document_property.name = property_name
151
- document_property.value = "Elon"
152
- document_property.built_in = false
153
-
154
- response = @pdf_api.put_set_property(file_name, property_name, document_property)
155
- assert(response, message="Failed to add/update document property.")
156
- end
157
-
158
- def test_delete_property
159
- file_name = "Sample-Annotation-Property.pdf"
160
- upload_file(file_name)
161
-
162
- property_name = "AsposeDev"
163
- response = @pdf_api.delete_property(file_name, property_name)
164
- assert(response, message="Failed to delete document property.")
165
- end
166
-
167
- def test_get_fields
168
- file_name = "sample-field.pdf"
169
- upload_file(file_name)
170
-
171
- response = @pdf_api.get_fields(file_name)
172
- assert(response, message="Failed to get document fields.")
173
- end
174
-
175
- def test_put_update_fields
176
- file_name = "sample-field.pdf"
177
- upload_file(file_name)
178
-
179
- field = Field.new
180
- field.name = "textbox1";
181
- field.values = ["Aspose"]
182
-
183
- fields = Fields.new
184
- fields.list = [field]
185
-
186
- response = @pdf_api.put_update_fields(file_name, fields)
187
- assert(response, message="Failed to update fields.")
188
- end
189
-
190
- def test_post_create_field
191
- file_name = "sample-field.pdf"
192
- upload_file(file_name)
193
-
194
- field = Field.new
195
- field.name = "checkBoxField2"
196
- field.values = ["1"]
197
- field.type = "Boolean"
198
-
199
- rect = Rectangle.new
200
- rect.x = 100
201
- rect.y = 100
202
- rect.height = 100
203
- rect.width = 200
204
-
205
- field.rect = rect
206
-
207
- page = 1
208
- response = @pdf_api.post_create_field(file_name, page, field)
209
- assert(response, message="Failed to create field.")
210
- end
211
-
212
- def test_get_field
213
- file_name = "sample-field.pdf"
214
- upload_file(file_name)
215
-
216
- field_name = "textbox1"
217
- response = @pdf_api.get_field(file_name, field_name)
218
- assert(response, message="Failed to get document field by name.")
219
- end
220
-
221
- def test_put_update_field
222
- file_name = "sample-field.pdf"
223
- upload_file(file_name)
224
-
225
- field_name = "textbox1"
226
-
227
- field = Field.new
228
- field.name = field_name
229
- field.values = ["Aspose"]
230
-
231
- response = @pdf_api.put_update_field(file_name, field, field_name)
232
- assert(response, message="Failed to update field.")
233
- end
234
-
235
- def test_put_merge_documents
236
- upload_file("Sample.pdf")
237
- upload_file("sample-input.pdf")
238
-
239
- merge_documents = MergeDocuments.new
240
- merge_documents.list = ["Sample.pdf", "sample-input.pdf"]
241
-
242
- response = @pdf_api.put_merge_documents("sample-merged.pdf", merge_documents)
243
- assert(response, message="Failed to merge a list of documents")
244
- end
245
-
246
- def test_get_pages
247
- file_name = "Sample-Annotation.pdf"
248
- upload_file(file_name)
249
-
250
- response = @pdf_api.get_pages(file_name)
251
- assert(response, message="Failed to read document pages info")
252
- end
253
-
254
- def test_put_add_new_page
255
- file_name = "sample-input.pdf"
256
- upload_file(file_name)
257
-
258
- response = @pdf_api.put_add_new_page(file_name)
259
- assert(response, message="Failed to add new page to end of the document")
260
- end
261
-
262
- def test_get_words_per_page
263
- file_name = "Sample-Annotation.pdf"
264
- upload_file(file_name)
265
-
266
- response = @pdf_api.get_words_per_page(file_name)
267
- assert(response, message="Failed to get number of words per document page.")
268
- end
269
-
270
- def test_get_page_with_format
271
- file_name = "Sample-Annotation.pdf"
272
- upload_file(file_name)
273
-
274
- page_number = 1
275
- format = "png"
276
- response = @pdf_api.get_page_with_format(file_name, page_number, format)
277
- assert(response, message="Failed to get page in specified format.")
278
- end
279
-
280
- def test_delete_page
281
- file_name = "sample-input.pdf"
282
- upload_file(file_name)
283
-
284
- page_number = 1
285
- response = @pdf_api.delete_page(file_name, page_number)
286
- assert(response, message="Failed to delete document page by its number.")
287
- end
288
-
289
- def test_get_page_annotations
290
- file_name = "Sample-Annotation.pdf"
291
- upload_file(file_name)
292
-
293
- page_number = 1
294
- response = @pdf_api.get_page_annotations(file_name, page_number)
295
- assert(response, message="Failed to read document page annotations.")
296
- end
297
-
298
- def test_get_page_annotation
299
- file_name = "Sample-Annotation.pdf"
300
- upload_file(file_name)
301
-
302
- page_number = 1
303
- annotation_number = 1
304
- response = @pdf_api.get_page_annotation(file_name, page_number, annotation_number)
305
- assert(response, message="Failed to read document page annotation by its number.")
306
- end
307
-
308
- def test_get_fragments
309
- file_name = "sample-input.pdf"
310
- upload_file(file_name)
311
-
312
- page_number = 1
313
- response = @pdf_api.get_fragments(file_name, page_number)
314
- assert(response, message="Failed to read page fragments.")
315
- end
316
-
317
- def test_get_fragment
318
- file_name = "sample-input.pdf"
319
- upload_file(file_name)
320
-
321
- page_number = 1
322
- fragment_number = 1
323
- response = @pdf_api.get_fragment(file_name, page_number, fragment_number)
324
- assert(response, message="Failed to read page fragment.")
325
- end
326
-
327
- def test_get_segments
328
- file_name = "sample-input.pdf"
329
- upload_file(file_name)
330
-
331
- page_number = 1
332
- fragment_number = 1
333
- response = @pdf_api.get_segments(file_name, page_number, fragment_number)
334
- assert(response, message="Failed to read fragment segments.")
335
- end
336
-
337
- def test_get_segment
338
- file_name = "sample-input.pdf"
339
- upload_file(file_name)
340
-
341
- page_number = 1
342
- fragment_number = 1
343
- segment_number = 1
344
- response = @pdf_api.get_segment(file_name, page_number, fragment_number, segment_number)
345
- assert(response, message="Failed to read segment.")
346
- end
347
-
348
- def test_get_segment_text_format
349
- file_name = "sample-input.pdf"
350
- upload_file(file_name)
351
-
352
- page_number = 1
353
- fragment_number = 1
354
- segment_number = 1
355
- response = @pdf_api.get_segment_text_format(file_name, page_number, fragment_number, segment_number)
356
- assert(response, message="Failed to read segment text format.")
357
- end
358
-
359
- def test_get_fragment_text_format
360
- file_name = "sample-input.pdf"
361
- upload_file(file_name)
362
-
363
- page_number = 1
364
- fragment_number = 1
365
- response = @pdf_api.get_fragment_text_format(file_name, page_number, fragment_number)
366
- assert(response, message="Failed to read page fragment text format.")
367
- end
368
-
369
- def test_get_images
370
- file_name = "SampleImage.pdf"
371
- upload_file(file_name)
372
-
373
- page_number = 1
374
- response = @pdf_api.get_images(file_name, page_number)
375
- assert(response, message="Failed to read document images.")
376
- end
377
-
378
- def test_get_image_with_format
379
- file_name = "SampleImage.pdf"
380
- upload_file(file_name)
381
-
382
- page_number = 1
383
- image_number = 1
384
- format = "jpeg"
385
- response = @pdf_api.get_image_with_format(file_name, page_number, image_number, format)
386
- assert(response, message="Failed to get image in specified format.")
387
- end
388
-
389
- def test_post_replace_image
390
- file_name = "SampleImage.pdf"
391
- upload_file(file_name)
392
- image_file_name = "aspose-cloud.png"
393
- upload_file(image_file_name)
394
-
395
- page_number = 1
396
- image_number = 1
397
- response = @pdf_api.post_replace_image(file_name, page_number, image_number, {image_file: image_file_name})
398
- assert(response, message="Failed to replace document image.")
399
- end
400
-
401
- def test_get_extract_barcodes
402
- file_name = "SampleBarCodeImage.pdf"
403
- upload_file(file_name)
404
-
405
- page_number = 1
406
- image_number = 1
407
- response = @pdf_api.get_extract_barcodes(file_name, page_number, image_number)
408
- assert(response, message="Failed to recognize barcodes.")
409
- end
410
-
411
- def test_get_page_link_annotations
412
- file_name = "Sample-Bookmark.pdf"
413
- upload_file(file_name)
414
-
415
- page_number = 1
416
- response = @pdf_api.get_page_link_annotations(file_name, page_number)
417
- assert(response, message="Failed to read document page link annotations.")
418
- end
419
-
420
- def test_get_page_link_annotation_by_index
421
- file_name = "Sample-Bookmark.pdf"
422
- upload_file(file_name)
423
-
424
- page_number = 1
425
- link_index = 1
426
- response = @pdf_api.get_page_link_annotation_by_index(file_name, page_number, link_index)
427
- assert(response, message="Failed to read document page link annotation by its index.")
428
- end
429
-
430
- def test_post_move_page
431
- file_name = "sample-merged.pdf"
432
- upload_file(file_name)
433
-
434
- page_number = 1
435
- new_index = 1
436
- response = @pdf_api.post_move_page(file_name, page_number, new_index)
437
- assert(response, message="Failed to move page to new position.")
438
- end
439
-
440
- def test_post_page_replace_text
441
- file_name = "sample-input.pdf"
442
- upload_file(file_name)
443
-
444
- page_number = 1
445
- text_replace = TextReplace.new
446
- text_replace.old_value = "Sample PDF"
447
- text_replace.new_value = "Sample Aspose PDF"
448
- response = @pdf_api.post_page_replace_text(file_name, page_number, text_replace)
449
- assert(response, message="Failed to replace text")
450
- end
451
-
452
- def test_post_page_replace_text_list
453
- file_name = "sample-input.pdf"
454
- upload_file(file_name)
455
-
456
- page_number = 1
457
- text_replace_list_request = TextReplaceListRequest.new
458
- text_request_1 = TextReplace.new
459
- text_request_1.old_value = "Sample"
460
- text_request_1.new_value = "Sample Aspose"
461
- text_request_2 = TextReplace.new
462
- text_request_2.old_value = "PDF"
463
- text_request_2.new_value = "PDF Document"
464
- text_replace_list_request.text_replaces = [text_request_1, text_request_2]
465
-
466
- response = @pdf_api.post_page_replace_text_list(file_name, page_number, text_replace_list_request)
467
- assert(response, message="Failed to replace text")
468
- end
469
-
470
- def test_post_sign_page
471
- file_name = "sample-input.pdf"
472
- upload_file(file_name)
473
-
474
- signature_file_name = "pkc7-sample.pfx"
475
- upload_file(signature_file_name)
476
-
477
- page_number = 1
478
- signature = Signature.new
479
- signature.authority = "Alexey"
480
- signature.location = "London"
481
- signature.contact = "alexey@aspose.com"
482
- signature.date = "10/25/2015 2:46:00.000 PM"
483
- signature.form_field_name = "Signature1"
484
- signature.password = "aspose"
485
- rectangle = Rectangle.new
486
- rectangle.x = 100
487
- rectangle.y = 100
488
- rectangle.height = 100
489
- rectangle.width = 200
490
- signature.rectangle = rectangle
491
- signature.signature_path = signature_file_name
492
- signature.signature_type = "PKCS7"
493
- signature.visible = true
494
-
495
- response = @pdf_api.post_sign_page(file_name, page_number, signature)
496
- assert(response, message="Failed to sign page.")
497
- end
498
-
499
- def test_put_page_add_stamp
500
- file_name = "sample-input.pdf"
501
- upload_file(file_name)
502
-
503
- page_number = 1
504
- stamp = Stamp.new
505
- stamp.value = "Aspose"
506
- stamp.background = true
507
- stamp.type = "Text"
508
-
509
- response = @pdf_api.put_page_add_stamp(file_name, page_number, stamp)
510
- assert(response, message="Failed to add page stamp.")
511
- end
512
-
513
- def test_get_page_text_items
514
- file_name = "Sample-Annotation.pdf"
515
- upload_file(file_name)
516
-
517
- page_number = 1
518
- response = @pdf_api.get_page_text_items(file_name, page_number)
519
- assert(response, message="Failed to read page text items.")
520
- end
521
-
522
- def test_post_document_replace_text
523
- file_name = "sample-input.pdf"
524
- upload_file(file_name)
525
-
526
- text_replace = TextReplace.new
527
- text_replace.old_value = "Sample PDF"
528
- text_replace.new_value = "Sample Aspose PDF"
529
-
530
- response = @pdf_api.post_document_replace_text(file_name, text_replace)
531
- assert(response, message="Failed to replace document's text.")
532
- end
533
-
534
- def test_post_document_replace_text_list
535
- file_name = "Sample-Annotation.pdf"
536
- upload_file(file_name)
537
-
538
- text_replace_list_request = TextReplaceListRequest.new
539
- text_replace_1 = TextReplace.new
540
- text_replace_1.old_value = "Sample"
541
- text_replace_1.new_value = "Sample Aspose"
542
- text_replace_1.regex = false
543
- text_replace_2 = TextReplace.new
544
- text_replace_2.old_value = "PDF"
545
- text_replace_2.new_value = "PDF Document"
546
- text_replace_2.regex = false
547
- text_replace_list_request.text_replaces = [text_replace_1, text_replace_2]
548
-
549
- response = @pdf_api.post_document_replace_text_list(file_name, text_replace_list_request)
550
- assert(response, message="Failed to replace document's text")
551
- end
552
-
553
- def test_post_sign_document
554
- file_name = "sample-input-2.pdf"
555
- upload_file(file_name)
556
- signature_file_name = "pkc7-sample.pfx"
557
- upload_file(signature_file_name)
558
-
559
- signature = Signature.new
560
- signature.authority = "Alexey"
561
- signature.location = "London"
562
- signature.contact = "alexey@aspose.com"
563
- signature.date = "10/25/2015 2:46:00.000 PM"
564
- signature.form_field_name = "Signature1"
565
- signature.password = "aspose"
566
- rectangle = Rectangle.new
567
- rectangle.x = 100
568
- rectangle.y = 100
569
- rectangle.height = 100
570
- rectangle.width = 200
571
- signature.rectangle = rectangle
572
- signature.signature_path = signature_file_name
573
- signature.signature_type = "PKCS7"
574
- signature.visible = true
575
-
576
- response = @pdf_api.post_sign_document(file_name, signature)
577
- assert(response, message="Failed to sign document.")
578
- end
579
-
580
- def test_post_split_document
581
- file_name = "sample-input.pdf"
582
- upload_file(file_name)
583
-
584
- response = @pdf_api.post_split_document(file_name, {format: "pdf", from: 1, to: 2})
585
- assert(response, message="Failed to split document to parts.")
586
- end
587
-
588
- def test_get_text_items
589
- file_name = "Sample-Annotation.pdf"
590
- upload_file(file_name)
591
-
592
- response = @pdf_api.get_text_items(file_name)
593
- assert(response, message="Failed to read document text items.")
594
- end
595
-
596
- def test_get_page
597
- file_name = "sample-input.pdf"
598
- upload_file(file_name)
599
-
600
- page_number = 1
601
- response = @pdf_api.get_page(file_name, page_number)
602
- assert(response, message="Failed to read document page info.")
603
- end
604
-
605
- def test_get_document
606
- file_name = "Sample.pdf"
607
- upload_file(file_name)
608
-
609
- response = @pdf_api.get_document(file_name)
610
- assert(response, message="Failed to read common document info.")
611
- end
612
-
613
- def test_get_image
614
- file_name = "SampleImage.pdf"
615
- upload_file(file_name)
616
-
617
- page_number = 1
618
- image_number = 1
619
- response = @pdf_api.get_image(file_name, page_number, image_number)
620
- assert(response, message="Failed to read document image by number.")
621
- end
622
-
623
- end
1
+ =begin
2
+ --------------------------------------------------------------------------------------------------------------------
3
+ Copyright (c) 2018 Aspose.Pdf for Cloud
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ SOFTWARE.
19
+ --------------------------------------------------------------------------------------------------------------------
20
+ =end
21
+
22
+ require 'minitest/autorun'
23
+ require 'minitest/unit'
24
+ require 'aspose_storage_cloud'
25
+
26
+ require_relative '../lib/aspose_pdf_cloud'
27
+
28
+ class PdfTests < Minitest::Test
29
+ include MiniTest::Assertions
30
+ include AsposePdfCloud
31
+ include AsposeStorageCloud
32
+
33
+
34
+ def setup
35
+ # Get App key and App SID from https://cloud.aspose.com
36
+ AsposeApp.app_key_and_sid('', '')
37
+
38
+ @pdf_api = PdfApi.new
39
+ @storage_api = StorageApi.new
40
+ @storage_api.api_client.host = 'http://api-dev.aspose.cloud/v1.1'
41
+
42
+ @temp_folder = 'TempPdf'
43
+ @test_data_folder = '../test_data/'
44
+
45
+ config = @pdf_api.api_client.config
46
+ config.host = 'api-dev.aspose.cloud'
47
+ config.scheme = 'http'
48
+ end
49
+
50
+
51
+ def teardown
52
+ end
53
+
54
+
55
+ def upload_file(file_name)
56
+ response = @storage_api.put_create(@temp_folder + '/' + file_name, File.open(@test_data_folder + file_name, 'r') { |io| io.read(io.size) } )
57
+ assert(response, "Failed to upload #{file_name} file.")
58
+ end
59
+
60
+
61
+ # Annotations Tests
62
+
63
+ def test_get_page_annotations
64
+ file_name = 'PdfWithAnnotations.pdf'
65
+ upload_file(file_name)
66
+
67
+ page_number = 2
68
+ opts = {
69
+ :folder => @temp_folder
70
+ }
71
+
72
+ response = @pdf_api.get_page_annotations(file_name, page_number, opts)
73
+ assert(response, 'Failed to read document page annotations.')
74
+ end
75
+
76
+
77
+ # Append Tests
78
+
79
+ def test_post_append_document_using_query_params
80
+ file_name = 'PdfWithImages2.pdf'
81
+ append_file_name = '4pages.pdf'
82
+
83
+ upload_file(file_name)
84
+ upload_file(append_file_name)
85
+
86
+ opts = {
87
+ :append_file => append_file_name,
88
+ :startPage => 2,
89
+ :endPage => 4,
90
+ :folder => @temp_folder
91
+ }
92
+
93
+ response = @pdf_api.post_append_document(file_name, opts)
94
+ assert(response, 'Failed to append document to existing one.')
95
+ end
96
+
97
+
98
+ def test_post_append_document_using_body_params
99
+ file_name = 'PdfWithImages2.pdf'
100
+ append_file_name = '4pages.pdf'
101
+
102
+ upload_file(file_name)
103
+ upload_file(append_file_name)
104
+
105
+ append_document = AppendDocument.new
106
+ append_document.document = append_file_name
107
+ append_document.start_page = 2
108
+ append_document.end_page = 4
109
+
110
+ opts = {
111
+ :append_document => append_document,
112
+ :folder => @temp_folder
113
+ }
114
+
115
+ response = @pdf_api.post_append_document(file_name, opts)
116
+ assert(response, 'Failed to append document to existing one.')
117
+ end
118
+
119
+
120
+ # Attachments Tests
121
+
122
+ def test_get_document_attachment_by_index
123
+ file_name = 'PdfWithEmbeddedFiles.pdf'
124
+ upload_file(file_name)
125
+
126
+ attachment_index = 1
127
+ opts = {
128
+ :folder => @temp_folder
129
+ }
130
+
131
+ response = @pdf_api.get_document_attachment_by_index(file_name, attachment_index, opts)
132
+ assert(response, 'Failed to read document attachment info by its index')
133
+ end
134
+
135
+
136
+ def test_get_document_attachments
137
+ file_name = 'PdfWithEmbeddedFiles.pdf'
138
+ upload_file(file_name)
139
+
140
+ opts = {
141
+ :folder => @temp_folder
142
+ }
143
+
144
+ response = @pdf_api.get_document_attachments(file_name, opts)
145
+ assert(response, 'Failed to read document attachments info.')
146
+ end
147
+
148
+
149
+ def test_get_download_document_attachment_by_index
150
+ file_name = 'PdfWithEmbeddedFiles.pdf'
151
+ upload_file(file_name)
152
+
153
+ attachment_index = 1
154
+ opts = {
155
+ :folder => @temp_folder
156
+ }
157
+
158
+ response = @pdf_api.get_download_document_attachment_by_index(file_name, attachment_index, opts)
159
+ assert(response, 'Failed to download document attachment content by its index.')
160
+ end
161
+
162
+
163
+ # Bookmarks Tests
164
+
165
+ def test_get_document_bookmarks
166
+ file_name = 'PdfWithBookmarks.pdf'
167
+ upload_file(file_name)
168
+
169
+ opts = {
170
+ :folder => @temp_folder
171
+ }
172
+
173
+ response = @pdf_api.get_document_bookmarks(file_name, opts)
174
+ assert(response, 'Failed to read document bookmarks.')
175
+ end
176
+
177
+
178
+ # Document Save As Tiff Tests
179
+
180
+ def test_put_document_save_as_tiff_using_query_params
181
+ file_name = '4pages.pdf'
182
+ upload_file(file_name)
183
+
184
+ opts = {
185
+ :result_file => '4pages.tiff',
186
+ :brightness => 0.6,
187
+ :compression => 'Ccitt4',
188
+ :color_depth => 'format1bpp',
189
+ :left_margin => 0,
190
+ :right_margin => 0,
191
+ :top_margin => 0,
192
+ :bottom_margin => 0,
193
+ :orientation => 'portait', # Yes, we know 'portrait'. It will be fixed in the next version.
194
+ :skip_blank_pages => true,
195
+ :width => 1200,
196
+ :height => 1600,
197
+ :x_resolution => 200,
198
+ :y_resolution => 200,
199
+ :page_index => 2,
200
+ :page_count=> 2,
201
+ :folder => @temp_folder
202
+ }
203
+
204
+ response = @pdf_api.put_document_save_as_tiff(file_name, opts)
205
+ assert(response, 'Failed to save document as Tiff image')
206
+ end
207
+
208
+
209
+ def test_put_document_save_as_tiff_using_body_params
210
+ file_name = '4pages.pdf'
211
+ upload_file(file_name)
212
+
213
+ export_options = TiffExportOptions.new
214
+ export_options.result_file = '4pages.tiff'
215
+ export_options.brightness = 0.6
216
+ export_options.compression = 'Ccitt4'
217
+ export_options.color_depth = 'format1bpp'
218
+ export_options.left_margin = 0
219
+ export_options.right_margin = 0
220
+ export_options.top_margin = 0
221
+ export_options.bottom_margin = 0
222
+ export_options.orientation = 'portait' # Yes, we know 'portrait'. It will be fixed in the next version.
223
+ export_options.skip_blank_pages = true
224
+ export_options.width = 1200
225
+ export_options.height = 1600
226
+ export_options.x_resolution = 200
227
+ export_options.y_resolution = 200
228
+ export_options.page_index = 2
229
+ export_options.page_count = 2
230
+
231
+ opts = {
232
+ :export_options => export_options,
233
+ :folder => @temp_folder
234
+ }
235
+
236
+ response = @pdf_api.put_document_save_as_tiff(file_name, opts)
237
+ assert(response, 'Failed to save document as Tiff image')
238
+ end
239
+
240
+
241
+ # Document Tests
242
+
243
+ def test_get_document
244
+ file_name = '4pages.pdf'
245
+ upload_file(file_name)
246
+
247
+ opts = {
248
+ :folder => @temp_folder
249
+ }
250
+
251
+ response = @pdf_api.get_document(file_name, opts)
252
+ assert(response, 'Failed to read common document info.')
253
+ end
254
+
255
+
256
+ def test_post_optimize_document
257
+ file_name = '4pages.pdf'
258
+ upload_file(file_name)
259
+
260
+ optimize_options = OptimizeOptions.new
261
+ optimize_options.allow_reuse_page_content = false
262
+ optimize_options.compress_images = true
263
+ optimize_options.image_quality = 100
264
+ optimize_options.link_duplcate_streams = true
265
+ optimize_options.remove_unused_objects = true
266
+ optimize_options.remove_unused_streams = true
267
+ optimize_options.unembed_fonts = true
268
+
269
+ opts = {
270
+ :options => optimize_options,
271
+ :folder => @temp_folder
272
+ }
273
+
274
+ response = @pdf_api.post_optimize_document(file_name, opts)
275
+ assert(response, 'Failed to optimize document.')
276
+ end
277
+
278
+
279
+ def test_post_split_document
280
+ file_name = '4pages.pdf'
281
+ upload_file(file_name)
282
+
283
+ opts = {
284
+ :folder => @temp_folder
285
+ }
286
+ response = @pdf_api.post_split_document(file_name, opts)
287
+ assert(response, 'Failed to split document to parts.')
288
+ end
289
+
290
+
291
+ def test_put_convert_document
292
+ url = 'http://pdf995.com/samples/pdf.pdf'
293
+ format = 'tiff'
294
+
295
+ opts = {
296
+ :format => format,
297
+ :url => url
298
+ }
299
+
300
+ response = @pdf_api.put_convert_document(opts)
301
+ assert(response, 'Failed to convert document from request content to format specified')
302
+ end
303
+
304
+
305
+ def test_put_create_empty_document
306
+ file_name = 'empty.pdf'
307
+
308
+ opts = {
309
+ :folder => @temp_folder
310
+ }
311
+
312
+ response = @pdf_api.put_create_document(file_name, opts)
313
+ assert(response, 'Failed to create new document')
314
+ end
315
+
316
+
317
+ def test_put_create_document
318
+ file_name = 'HtmlExample1.pdf'
319
+ template_name = 'HtmlExample1.html'
320
+
321
+ upload_file(template_name)
322
+
323
+ opts = {
324
+ :template_file => @temp_folder + '/' + template_name,
325
+ :template_type => 'html',
326
+ :folder => @temp_folder
327
+ }
328
+
329
+ response = @pdf_api.put_create_document(file_name, opts)
330
+ assert(response, 'Failed to create document from HTML template.')
331
+ end
332
+
333
+
334
+ def test_put_create_document_from_images
335
+ image_1 = '33539.jpg'
336
+ upload_file(image_1)
337
+
338
+ image_2 = '44781.jpg'
339
+ upload_file(image_2)
340
+
341
+ result_doc_name = 'pdffromimagesinquery.pdf'
342
+
343
+ images = ImagesListRequest.new
344
+ images.images_list = [ @temp_folder + '/' + image_1, @temp_folder + '/' + image_2]
345
+
346
+ opts = {
347
+ :images => images,
348
+ :ocr => false,
349
+ :folder => @temp_folder
350
+ }
351
+
352
+ response = @pdf_api.put_create_document_from_images(result_doc_name, opts)
353
+ assert(response, 'Failed to create document from Images.')
354
+ end
355
+
356
+ # Fields Tests
357
+
358
+ def test_get_field
359
+ file_name = 'PdfWithAcroForm.pdf'
360
+ upload_file(file_name)
361
+
362
+ opts = {
363
+ :folder => @temp_folder
364
+ }
365
+ field_name = 'textField'
366
+
367
+ response = @pdf_api.get_field(file_name, field_name, opts)
368
+ assert(response, 'Failed to get document field by name.')
369
+ end
370
+
371
+
372
+ def test_get_fields
373
+ file_name = 'PdfWithAcroForm.pdf'
374
+ upload_file(file_name)
375
+
376
+ opts = {
377
+ :folder => @temp_folder
378
+ }
379
+
380
+ response = @pdf_api.get_fields(file_name, opts)
381
+ assert(response, 'Failed to get document fields.')
382
+ end
383
+
384
+
385
+ def test_post_create_field
386
+ file_name = 'Hello_world.pdf'
387
+ upload_file(file_name)
388
+
389
+ rect = Rectangle.new
390
+ rect.x = 50
391
+ rect.y = 200
392
+ rect.width = 150
393
+ rect.height = 200
394
+
395
+ field = Field.new
396
+ field.name = 'checkboxfield'
397
+ field.values = ['1']
398
+ field.type = 'Boolean'
399
+ field.rect = rect
400
+
401
+ page_number = 1
402
+
403
+ opts = {
404
+ :field => field,
405
+ :folder => @temp_folder
406
+ }
407
+
408
+ response = @pdf_api.post_create_field(file_name, page_number, opts)
409
+ assert(response, 'Failed to create field.')
410
+ end
411
+
412
+
413
+ def test_put_update_field
414
+ file_name = 'PdfWithAcroForm.pdf'
415
+ upload_file(file_name)
416
+
417
+ field_name = 'textField'
418
+
419
+ field = Field.new
420
+ field.name = field_name
421
+ field.values = ['Text field updated value.']
422
+ field.type = FieldType::TEXT
423
+
424
+ opts = {
425
+ :field => field,
426
+ :folder => @temp_folder
427
+ }
428
+
429
+ response = @pdf_api.put_update_field(file_name, field_name, opts)
430
+ assert(response, 'Failed to update fields.')
431
+ end
432
+
433
+
434
+ # Fragments And Segments Tests
435
+
436
+ def test_get_fragment
437
+ file_name = '4pages.pdf'
438
+ upload_file(file_name)
439
+
440
+ page_number = 1
441
+ fragment_number = 1
442
+
443
+ opts = {
444
+ :folder => @temp_folder
445
+ }
446
+
447
+ response = @pdf_api.get_fragment(file_name, page_number, fragment_number, opts)
448
+ assert(response, 'Failed to read page fragment.')
449
+ end
450
+
451
+ def test_get_fragment_text_format
452
+ file_name = '4pages.pdf'
453
+ upload_file(file_name)
454
+
455
+ page_number = 1
456
+ fragment_number = 1
457
+
458
+ opts = {
459
+ :folder => @temp_folder
460
+ }
461
+
462
+ response = @pdf_api.get_fragment_text_format(file_name, page_number, fragment_number, opts)
463
+ assert(response, 'Failed to read page fragment text format.')
464
+ end
465
+
466
+
467
+ def test_get_fragments
468
+ file_name = '4pages.pdf'
469
+ upload_file(file_name)
470
+
471
+ page_number = 1
472
+
473
+ opts = {
474
+ :folder => @temp_folder
475
+ }
476
+ response = @pdf_api.get_fragments(file_name, page_number, opts)
477
+ assert(response, 'Failed to read page fragments.')
478
+ end
479
+
480
+
481
+ def test_get_segment
482
+ file_name = '4pages.pdf'
483
+ upload_file(file_name)
484
+
485
+ page_number = 1
486
+ fragment_number = 1
487
+ segment_number = 1
488
+
489
+ opts = {
490
+ :folder => @temp_folder
491
+ }
492
+
493
+ response = @pdf_api.get_segment(file_name, page_number, fragment_number, segment_number, opts)
494
+ assert(response, 'Failed to read segment.')
495
+ end
496
+
497
+
498
+ def test_get_segment_text_format
499
+ file_name = '4pages.pdf'
500
+ upload_file(file_name)
501
+
502
+ page_number = 1
503
+ fragment_number = 1
504
+ segment_number = 1
505
+
506
+ opts = {
507
+ :folder => @temp_folder
508
+ }
509
+
510
+ response = @pdf_api.get_segment_text_format(file_name, page_number, fragment_number, segment_number, opts)
511
+ assert(response, 'Failed to read segment text format.')
512
+ end
513
+
514
+
515
+ def test_get_segments
516
+ file_name = '4pages.pdf'
517
+ upload_file(file_name)
518
+
519
+ page_number = 1
520
+ fragment_number = 1
521
+
522
+ opts = {
523
+ :folder => @temp_folder
524
+ }
525
+
526
+ response = @pdf_api.get_segments(file_name, page_number, fragment_number, opts)
527
+ assert(response, 'Failed to read fragment segments.')
528
+ end
529
+
530
+
531
+ # Images Tests
532
+
533
+ def test_get_image
534
+ file_name = 'PdfWithImages2.pdf'
535
+ upload_file(file_name)
536
+
537
+ page_number = 1
538
+ image_number = 1
539
+ opts = {
540
+ :folder => @temp_folder
541
+ }
542
+
543
+ response = @pdf_api.get_image(file_name, page_number, image_number, opts)
544
+ assert(response, 'Failed to read document image by number.')
545
+ end
546
+
547
+
548
+ def test_get_images
549
+ file_name = 'PdfWithImages2.pdf'
550
+ upload_file(file_name)
551
+
552
+ page_number = 1
553
+ opts = {
554
+ :folder => @temp_folder
555
+ }
556
+
557
+ response = @pdf_api.get_images(file_name, page_number, opts)
558
+ assert(response, 'Failed to read document images.')
559
+ end
560
+
561
+
562
+ def test_post_replace_image
563
+ file_name = 'PdfWithImages2.pdf'
564
+ upload_file(file_name)
565
+
566
+ image_file_name = 'Koala.jpg'
567
+ upload_file(image_file_name)
568
+
569
+ page_number = 1
570
+ image_number = 1
571
+ opts = {
572
+ :image_file => @temp_folder + '/' + image_file_name,
573
+ :folder => @temp_folder
574
+ }
575
+
576
+ response = @pdf_api.post_replace_image(file_name, page_number, image_number, opts)
577
+ assert(response, 'Failed to replace document image.')
578
+ end
579
+
580
+
581
+ # Links Tests
582
+
583
+ def test_get_page_link_annotation_by_index
584
+ file_name = 'PdfWithLinks.pdf'
585
+ upload_file(file_name)
586
+
587
+ page_number = 1
588
+ link_index = 1
589
+ opts = {
590
+ :folder => @temp_folder
591
+ }
592
+
593
+ response = @pdf_api.get_page_link_annotation_by_index(file_name, page_number, link_index, opts)
594
+ assert(response, 'Failed to read document page link annotation by its index.')
595
+ end
596
+
597
+ def test_get_page_link_annotations
598
+ file_name = 'PdfWithLinks.pdf'
599
+ upload_file(file_name)
600
+
601
+ page_number = 1
602
+ opts = {
603
+ :folder => @temp_folder
604
+ }
605
+
606
+ response = @pdf_api.get_page_link_annotations(file_name, page_number, opts)
607
+ assert(response, 'Failed to read document page link annotations.')
608
+ end
609
+
610
+
611
+ # Merge Tests
612
+
613
+ def test_put_merge_documents
614
+ file_name_list = ['4pages.pdf', 'PdfWithImages2.pdf', 'marketing.pdf']
615
+ file_name_list.each { |file_name| upload_file(file_name)}
616
+
617
+ result_name = 'MergingResult.pdf'
618
+
619
+ merge_documents = MergeDocuments.new
620
+ merge_documents.list = file_name_list
621
+
622
+ opts = {
623
+ :merge_documents => merge_documents,
624
+ :folder => @temp_folder
625
+ }
626
+
627
+ response = @pdf_api.put_merge_documents(result_name, opts)
628
+ assert(response, 'Failed to merge a list of documents')
629
+ end
630
+
631
+
632
+ # Pages Tests
633
+
634
+ def test_delete_page
635
+ file_name = '4pages.pdf'
636
+ upload_file(file_name)
637
+
638
+ page_number = 1
639
+ opts = {
640
+ :folder => @temp_folder
641
+ }
642
+
643
+ response = @pdf_api.delete_page(file_name, page_number, opts)
644
+ assert(response, 'Failed to delete document page by its number.')
645
+ end
646
+
647
+
648
+ def test_get_page
649
+ file_name = '4pages.pdf'
650
+ upload_file(file_name)
651
+
652
+ page_number = 3
653
+ opts = {
654
+ :folder => @temp_folder
655
+ }
656
+
657
+ response = @pdf_api.get_page(file_name, page_number, opts)
658
+ assert(response, 'Failed to get document page by its number.')
659
+ end
660
+
661
+
662
+ def test_get_pages
663
+ file_name = '4pages.pdf'
664
+ upload_file(file_name)
665
+
666
+ opts = {
667
+ :folder => @temp_folder
668
+ }
669
+
670
+ response = @pdf_api.get_pages(file_name, opts)
671
+ assert(response, 'Failed to read document pages info.')
672
+ end
673
+
674
+
675
+ def test_get_words_per_page
676
+ file_name = '4pages.pdf'
677
+ upload_file(file_name)
678
+
679
+ opts = {
680
+ :folder => @temp_folder
681
+ }
682
+
683
+ response = @pdf_api.get_words_per_page(file_name, opts)
684
+ assert(response, 'Failed to get number of words per document page.')
685
+ end
686
+
687
+
688
+ def test_post_move_page
689
+ file_name = '4pages.pdf'
690
+ upload_file(file_name)
691
+
692
+ opts = {
693
+ :folder => @temp_folder
694
+ }
695
+ page_number = 1
696
+ new_index = 1
697
+
698
+ response = @pdf_api.post_move_page(file_name, page_number, new_index, opts)
699
+ assert(response, 'Failed to move page to new position.')
700
+ end
701
+
702
+
703
+ def test_put_add_new_page
704
+ file_name = '4pages.pdf'
705
+ upload_file(file_name)
706
+
707
+ opts = {
708
+ :folder => @temp_folder
709
+ }
710
+
711
+ response = @pdf_api.put_add_new_page(file_name, opts)
712
+ assert(response, 'Failed to add new page to end of the document.')
713
+ end
714
+
715
+ def test_put_page_add_stamp
716
+ file_name = '4pages.pdf'
717
+ upload_file(file_name)
718
+
719
+ stamp_file_name = 'Penguins.jpg'
720
+ upload_file(stamp_file_name)
721
+
722
+ page_number = 1
723
+
724
+ stamp = Stamp.new
725
+ stamp.type = StampType::IMAGE
726
+ stamp.file_name = @temp_folder + '/' + stamp_file_name
727
+ stamp.background = true
728
+ stamp.width = 200
729
+ stamp.height = 200
730
+ stamp.x_indent = 100
731
+ stamp.y_indent = 100
732
+
733
+ opts = {
734
+ :folder => @temp_folder
735
+ }
736
+
737
+ response = @pdf_api.put_page_add_stamp(file_name, page_number, stamp, opts)
738
+ assert(response, 'Failed to add page stamp.')
739
+ end
740
+
741
+
742
+ # Paragraphs Tests
743
+
744
+ def test_put_add_text
745
+ file_name = '4pages.pdf'
746
+ upload_file(file_name)
747
+
748
+ page_number = 1
749
+
750
+ rectangle = Rectangle.new
751
+ rectangle.x = 100
752
+ rectangle.y = 100
753
+ rectangle.width = 200
754
+ rectangle.height = 200
755
+
756
+ foreground_color = Color.new
757
+ foreground_color.a = 0x00
758
+ foreground_color.r = 0x00
759
+ foreground_color.g = 0xFF
760
+ foreground_color.b = 0x00
761
+
762
+ background_color = Color.new
763
+ background_color.a = 0x00
764
+ background_color.r = 0xFF
765
+ background_color.g = 0x00
766
+ background_color.b = 0x00
767
+
768
+ text_state = TextState.new
769
+ text_state.font = 'Arial'
770
+ text_state.font_size = 10
771
+ text_state.foreground_color = foreground_color
772
+ text_state.background_color = background_color
773
+ text_state.font_style = FontStyles::BOLD
774
+
775
+ segment = Segment.new
776
+ segment.value = 'segment 1'
777
+ segment.text_state = text_state
778
+
779
+ text_line = TextLine.new
780
+ text_line.horizontal_alignment = TextHorizontalAlignment::RIGHT
781
+ text_line.segments = [segment]
782
+
783
+ paragraph = Paragraph.new
784
+ paragraph.rectangle = rectangle
785
+ paragraph.left_margin = 10
786
+ paragraph.right_margin = 10
787
+ paragraph.top_margin = 20
788
+ paragraph.bottom_margin = 20
789
+ paragraph.horizontal_alignment = TextHorizontalAlignment::FULL_JUSTIFY
790
+ paragraph.line_spacing = LineSpacing::FONT_SIZE
791
+ paragraph.rotation = 10
792
+ paragraph.subsequent_lines_indent = 20
793
+ paragraph.vertical_alignment = VerticalAlignment::CENTER
794
+ paragraph.wrap_mode = WrapMode::BY_WORDS
795
+ paragraph.lines = [text_line]
796
+
797
+ opts = {
798
+ :paragraph => paragraph,
799
+ :folder => @temp_folder
800
+ }
801
+
802
+ response = @pdf_api.put_add_text(file_name, page_number, opts)
803
+ assert(response, 'Failed to add text to the page.')
804
+ end
805
+
806
+
807
+ # Properties Tests
808
+
809
+ def test_delete_properties
810
+ file_name = 'PdfWithAcroForm.pdf'
811
+ upload_file(file_name)
812
+
813
+ property_1 = DocumentProperty.new
814
+ property_1.name = 'prop1'
815
+ property_1.value = 'val1'
816
+
817
+ opts_1 = {
818
+ :property => property_1,
819
+ :folder => @temp_folder
820
+ }
821
+
822
+ property_2 = DocumentProperty.new
823
+ property_2.name = 'prop2'
824
+ property_2.value = 'val2'
825
+
826
+ opts_2 = {
827
+ :property => property_2,
828
+ :folder => @temp_folder
829
+ }
830
+
831
+ @pdf_api.put_set_property(file_name, property_1.name, opts_1)
832
+ @pdf_api.put_set_property(file_name, property_2.name, opts_2)
833
+
834
+ opts = {
835
+ :folder => @temp_folder
836
+ }
837
+
838
+ response = @pdf_api.delete_properties(file_name, opts)
839
+ assert(response, 'Failed to delete document properties.')
840
+ end
841
+
842
+
843
+ def test_delete_property
844
+ file_name = 'PdfWithAcroForm.pdf'
845
+ upload_file(file_name)
846
+
847
+ property_1 = DocumentProperty.new
848
+ property_1.name = 'prop1'
849
+ property_1.value = 'val1'
850
+
851
+ opts_1 = {
852
+ :property => property_1,
853
+ :folder => @temp_folder
854
+ }
855
+
856
+ @pdf_api.put_set_property(file_name, property_1.name, opts_1)
857
+
858
+ opts = {
859
+ :folder => @temp_folder
860
+ }
861
+
862
+ response = @pdf_api.delete_property(file_name, property_1.name, opts)
863
+ assert(response, 'Failed to delete document property.')
864
+ end
865
+
866
+
867
+ def test_get_document_properties
868
+ file_name = 'PdfWithAcroForm.pdf'
869
+ upload_file(file_name)
870
+
871
+ property_1 = DocumentProperty.new
872
+ property_1.name = 'prop1'
873
+ property_1.value = 'val1'
874
+
875
+ opts_1 = {
876
+ :property => property_1,
877
+ :folder => @temp_folder
878
+ }
879
+
880
+ property_2 = DocumentProperty.new
881
+ property_2.name = 'prop2'
882
+ property_2.value = 'val2'
883
+
884
+ opts_2 = {
885
+ :property => property_2,
886
+ :folder => @temp_folder
887
+ }
888
+
889
+ @pdf_api.put_set_property(file_name, property_1.name, opts_1)
890
+ @pdf_api.put_set_property(file_name, property_2.name, opts_2)
891
+
892
+ opts = {
893
+ :folder => @temp_folder
894
+ }
895
+
896
+ response = @pdf_api.get_document_properties(file_name, opts)
897
+ assert(response, 'Failed to read document properties')
898
+ end
899
+
900
+
901
+ def test_get_document_property
902
+ file_name = 'PdfWithAcroForm.pdf'
903
+ upload_file(file_name)
904
+
905
+ property_1 = DocumentProperty.new
906
+ property_1.name = 'prop1'
907
+ property_1.value = 'val1'
908
+
909
+ opts_1 = {
910
+ :property => property_1,
911
+ :folder => @temp_folder
912
+ }
913
+
914
+ @pdf_api.put_set_property(file_name, property_1.name, opts_1)
915
+
916
+ opts = {
917
+ :folder => @temp_folder
918
+ }
919
+
920
+ response = @pdf_api.get_document_property(file_name, property_1.name, opts)
921
+ assert(response, 'Failed to read document property by name.')
922
+ end
923
+
924
+
925
+ def test_put_set_property
926
+ file_name = 'PdfWithAcroForm.pdf'
927
+ upload_file(file_name)
928
+
929
+ property_1 = DocumentProperty.new
930
+ property_1.name = 'prop1'
931
+ property_1.value = 'val1'
932
+
933
+ opts_1 = {
934
+ :property => property_1,
935
+ :folder => @temp_folder
936
+ }
937
+
938
+ response = @pdf_api.put_set_property(file_name, property_1.name, opts_1)
939
+ assert(response, 'Failed to add/update document property.')
940
+ end
941
+
942
+
943
+ # Sign Tests
944
+
945
+ def test_post_sign_document
946
+ file_name = 'BlankWithSignature.pdf'
947
+ upload_file(file_name)
948
+
949
+ signature_file_name = 'test1234.pfx'
950
+ upload_file(signature_file_name)
951
+
952
+ rectangle = Rectangle.new
953
+ rectangle.x = 100
954
+ rectangle.y = 100
955
+ rectangle.width = 400
956
+ rectangle.height = 100
957
+
958
+ signature = Signature.new
959
+ signature.authority = 'Sergey Smal'
960
+ signature.contact = 'test@mail.ru'
961
+ signature.date = '08/01/2012 12:15:00.000 PM'
962
+ signature.form_field_name = 'Signature1'
963
+ signature.location = 'Ukraine'
964
+ signature.password = 'test1234'
965
+ signature.rectangle = rectangle
966
+ signature.signature_path = @temp_folder + '/' + signature_file_name
967
+ signature.signature_type = SignatureType::PKCS_7
968
+ signature.visible = true
969
+
970
+ opts = {
971
+ :signature => signature,
972
+ :folder => @temp_folder
973
+ }
974
+
975
+ response = @pdf_api.post_sign_document(file_name, opts)
976
+ assert(response, 'Failed to sign document.')
977
+ end
978
+
979
+ def test_post_sign_page
980
+ file_name = 'BlankWithSignature.pdf'
981
+ upload_file(file_name)
982
+
983
+ signature_file_name = 'test1234.pfx'
984
+ upload_file(signature_file_name)
985
+
986
+ page_number = 1
987
+
988
+ rectangle = Rectangle.new
989
+ rectangle.x = 100
990
+ rectangle.y = 100
991
+ rectangle.width = 400
992
+ rectangle.height = 100
993
+
994
+ signature = Signature.new
995
+ signature.authority = 'Sergey Smal'
996
+ signature.contact = 'test@mail.ru'
997
+ signature.date = '08/01/2012 12:15:00.000 PM'
998
+ signature.form_field_name = 'Signature1'
999
+ signature.location = 'Ukraine'
1000
+ signature.password = 'test1234'
1001
+ signature.rectangle = rectangle
1002
+ signature.signature_path = @temp_folder + '/' + signature_file_name
1003
+ signature.signature_type = 'PKCS7'
1004
+ signature.visible = true
1005
+
1006
+ opts = {
1007
+ :signature => signature,
1008
+ :folder => @temp_folder
1009
+ }
1010
+
1011
+ response = @pdf_api.post_sign_page(file_name, page_number, opts)
1012
+ assert(response, 'Failed to sign page.')
1013
+ end
1014
+
1015
+
1016
+ # Text Items Tests
1017
+
1018
+ def test_get_page_text_items
1019
+ file_name = '4pages.pdf'
1020
+ upload_file(file_name)
1021
+
1022
+ page_number = 1
1023
+ opts = {
1024
+ :folder => @temp_folder
1025
+ }
1026
+
1027
+ response = @pdf_api.get_page_text_items(file_name, page_number, opts)
1028
+ assert(response, 'Failed to read page text items.')
1029
+ end
1030
+
1031
+
1032
+ def test_get_text_items
1033
+ file_name = '4pages.pdf'
1034
+ upload_file(file_name)
1035
+
1036
+ opts = {
1037
+ :folder => @temp_folder
1038
+ }
1039
+
1040
+ response = @pdf_api.get_text_items(file_name, opts)
1041
+ assert(response, 'Failed to read document text items.')
1042
+ end
1043
+
1044
+
1045
+ # Text Replace Tests
1046
+
1047
+ def test_post_document_replace_text
1048
+ file_name = '4pages.pdf'
1049
+ upload_file(file_name)
1050
+
1051
+ text_replace_request = TextReplaceRequest.new
1052
+ text_replace_request.old_value = 'Page'
1053
+ text_replace_request.new_value = 'p_a_g_e'
1054
+ text_replace_request.regex = false
1055
+
1056
+ opts = {
1057
+ :folder => @temp_folder
1058
+ }
1059
+
1060
+ response = @pdf_api.post_document_replace_text(file_name, text_replace_request, opts)
1061
+ assert(response, "Failed to replace document's text.")
1062
+ end
1063
+
1064
+
1065
+ def test_post_document_replace_text_list
1066
+ file_name = '4pages.pdf'
1067
+ upload_file(file_name)
1068
+
1069
+ text_replace_request_1 = TextReplaceRequest.new
1070
+ text_replace_request_1.old_value = 'First'
1071
+ text_replace_request_1.new_value = '1'
1072
+ text_replace_request_1.regex = false
1073
+
1074
+ text_replace_request_2 = TextReplaceRequest.new
1075
+ text_replace_request_2.old_value = 'Page'
1076
+ text_replace_request_2.new_value = 'p_a_g_e'
1077
+ text_replace_request_2.regex = false
1078
+
1079
+ text_replace_list_request = TextReplaceListRequest.new
1080
+ text_replace_list_request.text_replaces = [text_replace_request_1, text_replace_request_2]
1081
+
1082
+ opts = {
1083
+ :folder => @temp_folder
1084
+ }
1085
+
1086
+ response = @pdf_api.post_document_replace_text_list(file_name, text_replace_list_request, opts)
1087
+ assert(response, "Failed to replace document's text")
1088
+ end
1089
+
1090
+
1091
+ def test_post_page_replace_text
1092
+ file_name = '4pages.pdf'
1093
+ upload_file(file_name)
1094
+
1095
+ page_number = 1
1096
+
1097
+ text_replace_request = TextReplaceRequest.new
1098
+ text_replace_request.old_value = 'Page'
1099
+ text_replace_request.new_value = 'p_a_g_e'
1100
+ text_replace_request.regex = false
1101
+
1102
+ opts = {
1103
+ :folder => @temp_folder
1104
+ }
1105
+
1106
+ response = @pdf_api.post_page_replace_text(file_name, page_number, text_replace_request, opts)
1107
+ assert(response, 'Failed to replace text')
1108
+ end
1109
+
1110
+
1111
+ def test_post_page_replace_text_list
1112
+ file_name = '4pages.pdf'
1113
+ upload_file(file_name)
1114
+
1115
+ page_number = 1
1116
+
1117
+ text_replace_request_1 = TextReplaceRequest.new
1118
+ text_replace_request_1.old_value = 'First'
1119
+ text_replace_request_1.new_value = '1'
1120
+ text_replace_request_1.regex = false
1121
+
1122
+ text_replace_request_2 = TextReplaceRequest.new
1123
+ text_replace_request_2.old_value = 'Page'
1124
+ text_replace_request_2.new_value = 'p_a_g_e'
1125
+ text_replace_request_2.regex = false
1126
+
1127
+ text_replace_list_request = TextReplaceListRequest.new
1128
+ text_replace_list_request.text_replaces = [text_replace_request_1, text_replace_request_2]
1129
+
1130
+ opts = {
1131
+ :folder => @temp_folder
1132
+ }
1133
+
1134
+ response = @pdf_api.post_page_replace_text_list(file_name, page_number, text_replace_list_request, opts)
1135
+ assert(response, 'Failed to replace text')
1136
+ end
1137
+
1138
+
1139
+ # OCR Tests
1140
+
1141
+ def test_put_searchable_document
1142
+ file_name = 'rusdoc.pdf'
1143
+ upload_file(file_name)
1144
+
1145
+ opts = {
1146
+ :lang => 'rus,eng',
1147
+ :folder => @temp_folder
1148
+ }
1149
+
1150
+ response = @pdf_api.put_searchable_document(file_name, opts)
1151
+ assert(response, 'Filed to make document searchable')
1152
+ end
1153
+
1154
+
1155
+ def test_put_searchable_document_with_default_lang
1156
+ file_name = 'rusdoc.pdf'
1157
+ upload_file(file_name)
1158
+
1159
+ opts = {
1160
+ :folder => @temp_folder
1161
+ }
1162
+
1163
+ response = @pdf_api.put_searchable_document(file_name, opts)
1164
+ assert(response, 'Filed to make document searchable.')
1165
+ end
1166
+
1167
+
1168
+ # Text Tests
1169
+
1170
+ def test_get_text
1171
+ file_name = '4pages.pdf'
1172
+ upload_file(file_name)
1173
+
1174
+ x = 0
1175
+ y = 0
1176
+ width = 0
1177
+ height = 0
1178
+ opts = {
1179
+ :folder => @temp_folder
1180
+ }
1181
+
1182
+ response = @pdf_api.get_text(file_name, x, y, width, height, opts)
1183
+ assert(response, 'Filed to get document text.')
1184
+ end
1185
+
1186
+ def test_get_page_text_by_two_text_on_page
1187
+ file_name = '4pages.pdf'
1188
+ upload_file(file_name)
1189
+
1190
+ page_number = 1
1191
+ x = 0
1192
+ y = 0
1193
+ width = 0
1194
+ height = 0
1195
+ opts = {
1196
+ :format => ['First Page', 'Second Page'],
1197
+ # :format => 'First Page',
1198
+ :folder => @temp_folder
1199
+ }
1200
+
1201
+ response = @pdf_api.get_page_text(file_name, page_number, x, y, width, height, opts)
1202
+ assert(response, 'Filed to get document text.')
1203
+ end
1204
+
1205
+
1206
+ # Text Replace Tests
1207
+
1208
+ def test_post_document_text_replace_whole_doc_by_rect
1209
+ file_name = '4pages.pdf'
1210
+ upload_file(file_name)
1211
+
1212
+ rect = Rectangle.new
1213
+ rect.x = 100
1214
+ rect.y = 700
1215
+ rect.width = 300
1216
+ rect.height = 300
1217
+
1218
+ text_replace = TextReplace.new
1219
+ text_replace.old_value = 'Page'
1220
+ text_replace.new_value = 'p_a_g_e'
1221
+ text_replace.rect = rect
1222
+
1223
+ text_replace_list = TextReplaceListRequest.new
1224
+ text_replace_list.text_replaces = [text_replace]
1225
+ text_replace_list.start_index = 0
1226
+ text_replace_list.count_replace = 0
1227
+
1228
+
1229
+ opts = {
1230
+ :folder => @temp_folder
1231
+ }
1232
+
1233
+ response = @pdf_api.post_document_text_replace(file_name, text_replace_list, opts)
1234
+ assert(response, 'Filed to replace document text by rect.')
1235
+ end
1236
+
1237
+
1238
+ def test_post_page_text_replace_by_rect
1239
+ file_name = '4pages.pdf'
1240
+ upload_file(file_name)
1241
+ page_number = 1
1242
+
1243
+ rect = Rectangle.new
1244
+ rect.x = 100
1245
+ rect.y = 700
1246
+ rect.width = 300
1247
+ rect.height = 300
1248
+
1249
+ text_replace = TextReplace.new
1250
+ text_replace.old_value = 'Page'
1251
+ text_replace.new_value = 'p_a_g_e'
1252
+ text_replace.rect = rect
1253
+
1254
+ text_replace_list = TextReplaceListRequest.new
1255
+ text_replace_list.text_replaces = [text_replace]
1256
+ text_replace_list.start_index = 0
1257
+ text_replace_list.count_replace = 0
1258
+
1259
+ opts = {
1260
+ :folder => @temp_folder
1261
+ }
1262
+
1263
+ response = @pdf_api.post_page_text_replace(file_name, page_number, text_replace_list, opts)
1264
+ assert(response, 'Filed to replace page text by rect.')
1265
+ end
1266
+
1267
+ end
1268
+