Class: Aspose::Cloud::Pdf::Document
- Inherits:
-
Object
- Object
- Aspose::Cloud::Pdf::Document
- Defined in:
- lib/Pdf/document.rb
Instance Method Summary collapse
-
#add_new_page ⇒ Object
Add new page to opend pdf file.
- #append_document(base_pdf, new_pdf, startpage = 0, endpage = 0, sourcefolder = '') ⇒ Object
-
#create_empty_pdf(pdf_filename) ⇒ Object
Creates an Empty Pdf document.
-
#create_from_html(pdf_filename, html_filename) ⇒ Object
Creates a PDF from HTML.
-
#create_from_xml(pdf_filename, xslt_filename, xml_filename) ⇒ Object
Creates a PDF from XML.
-
#delete_page(page_number) ⇒ Object
Deletes selected page from Pdf document.
-
#get_document_properties ⇒ Object
Get specified properity of the document.
-
#get_document_property(property_name) ⇒ Object
Get specified properity of the document.
-
#get_form_field(field_name) ⇒ Object
Gets a particular form field field_name.
-
#get_form_field_count ⇒ Object
Gets the FormField count of the specified PDF document.
-
#get_form_fields ⇒ Object
Gets the list of FormFields from the specified PDF document.
- #get_page_count ⇒ Object
-
#initialize(filename) ⇒ Document
constructor
A new instance of Document.
- #merge_documents(source_files) ⇒ Object
-
#move_page(page_number, new_location) ⇒ Object
Moves selected page in Pdf document to new location.
-
#remove_all_properties ⇒ Object
Remove All properties of a document.
-
#replace_image_file(page_number, image_index, image_filename) ⇒ Object
Replaces Image in PDF File using Local Image Stream.
-
#replace_image_stream(page_number, image_index, image_stream) ⇒ Object
Replaces Image in PDF File using Local Image Stream.
-
#set_document_property(property_name, property_value) ⇒ Object
Set specified properity of the document.
Constructor Details
#initialize(filename) ⇒ Document
Returns a new instance of Document.
9 10 11 |
# File 'lib/Pdf/document.rb', line 9 def initialize(filename) @filename = filename end |
Instance Method Details
#add_new_page ⇒ Object
Add new page to opend pdf file
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/Pdf/document.rb', line 297 def add_new_page begin if(@filename == '') raise('PDF file name not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/pages' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(@filename) output_path = $out_put_location + @filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#append_document(base_pdf, new_pdf, startpage = 0, endpage = 0, sourcefolder = '') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/Pdf/document.rb', line 34 def append_document(base_pdf, new_pdf, startpage = 0, endpage = 0, sourcefolder = '') begin if base_pdf == '' raise('Base file not specified') end if new_pdf == '' raise('File to merge is not specified') end if sourcefolder == '' struri = "#{$product_uri}/pdf/#{base_pdf}/appenddocument?appendfile=#{new_pdf}"+(startpage > 0 ? '&startPage=' + startpage : '' ) + (endpage > 0 ? '&endPage=' + endpage : '' ) else struri = "#{$product_uri}/pdf/#{base_pdf}/appenddocument?appendfile=#{sourcefolder}/#{new_pdf}"+ (startpage > 0 ? '&startPage=' + startpage : '' ) + (endpage > 0 ? '&endPage=' + endpage : '' ) end signeduri = Aspose::Cloud::Common::Utils.sign(struri) response_stream = RestClient.post signeduri,'', {:accept => 'application/json'} valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new if(sourcefolder == '') output_stream = folder.get_file(base_pdf) else output_stream = folder.get_file(sourcefolder + '/' + base_pdf) end output_path = $out_put_location + base_pdf; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#create_empty_pdf(pdf_filename) ⇒ Object
Creates an Empty Pdf document
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/Pdf/document.rb', line 263 def create_empty_pdf (pdf_filename) begin if(pdf_filename == '') raise('PDF file name not specified.') end str_uri = $product_uri + '/pdf/' + pdf_filename str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(pdf_filename) output_path = $out_put_location + pdf_filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#create_from_html(pdf_filename, html_filename) ⇒ Object
Creates a PDF from HTML
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/Pdf/document.rb', line 179 def create_from_html (pdf_filename, html_filename) begin if(pdf_filename == '') raise('PDF file name not specified.') end if(html_filename == '') raise('HTML file name not specified.') end str_uri = $product_uri + '/pdf/' + pdf_filename + '?templatefile=' + html_filename + '&templatetype=html' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(pdf_filename) output_path = $out_put_location + pdf_filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#create_from_xml(pdf_filename, xslt_filename, xml_filename) ⇒ Object
Creates a PDF from XML
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/Pdf/document.rb', line 220 def create_from_xml (pdf_filename, xslt_filename, xml_filename) begin if(pdf_filename == '') raise('PDF file name not specified.') end if(xslt_filename == '') raise('XSLT file name not specified.') end if(xml_filename == '') raise('XML file name not specified.') end str_uri = $product_uri + '/pdf/' + pdf_filename + '?templatefile=' + xslt_filename + '&datafile=' + xml_filename + '&templatetype=xml' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.put(str_signed_uri, '', {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(pdf_filename) output_path = $out_put_location + pdf_filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#delete_page(page_number) ⇒ Object
Deletes selected page from Pdf document
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/Pdf/document.rb', line 332 def delete_page (page_number) begin if(@filename == '') raise('PDF file name not specified.') end if(page_number == '') raise('page number not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.delete(str_signed_uri, {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(@filename) output_path = $out_put_location + @filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#get_document_properties ⇒ Object
Get specified properity of the document
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/Pdf/document.rb', line 548 def get_document_properties begin if(@filename == '') raise('PDF file name not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['DocumentProperties']['List'] rescue Exception=>e print e end end |
#get_document_property(property_name) ⇒ Object
Get specified properity of the document
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/Pdf/document.rb', line 519 def get_document_property property_name begin if(@filename == '') raise('PDF file name not specified.') end if(property_name == '') raise('property name not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties/' + property_name str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['DocumentProperty'] rescue Exception=>e print e end end |
#get_form_field(field_name) ⇒ Object
Gets a particular form field field_name
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/Pdf/document.rb', line 157 def get_form_field(field_name) begin str_uri = $product_uri + '/pdf/' + @filename + '/feilds/' + field_name str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['Field'] rescue Exception=>e print e end end |
#get_form_field_count ⇒ Object
Gets the FormField count of the specified PDF document
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/Pdf/document.rb', line 119 def get_form_field_count begin str_uri = $product_uri + '/pdf/' + @filename + '/feilds' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['Fields']['List'].count rescue Exception=>e print e end end |
#get_form_fields ⇒ Object
Gets the list of FormFields from the specified PDF document
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/Pdf/document.rb', line 137 def get_form_fields begin str_uri = $product_uri + '/pdf/' + @filename + '/feilds' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(str_signed_uri, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['Fields']['List'] rescue Exception=>e print e end end |
#get_page_count ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/Pdf/document.rb', line 13 def get_page_count begin if(@filename == '') raise('Filename cannot be empty.') end str_uri = $product_uri + '/pdf/' + @filename + '/pages' signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.get(signed_str_uri,{:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['Pages']['List'].count rescue Exception=>e print e end end |
#merge_documents(source_files) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/Pdf/document.rb', line 80 def merge_documents(source_files) begin _mergedfilename = @filename # Throw exception if output filename not specified if _mergedfilename == '' raise('Output file not specified') end # Throw exception if source files are not provided if source_files.empty? || source_files.length < 2 raise('File to merge are not specified') end # Build JSON to post json_data = JSON.generate('List'=>source_files) struri = "#{$product_uri}/pdf/#{_mergedfilename}/merge" signeduri = Aspose::Cloud::Common::Utils.sign(struri) responsexml = RestClient.put signeduri, json_data, {:content_type => :json} xmldoc = REXML::Document.new(responsexml) if xmldoc.elements.to_a('SaaSposeResponse/Status').first.text == 'OK' return true else return false end rescue Exception=>e print e end end |
#move_page(page_number, new_location) ⇒ Object
Moves selected page in Pdf document to new location
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/Pdf/document.rb', line 374 def move_page (page_number, new_location) begin if(@filename == '') raise('PDF file name not specified.') end if(page_number == '') raise('page number not specified.') end if(new_location == '') raise('new location not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/movepage?newindex=' + new_location.to_s str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.post(str_signed_uri, '', {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(@filename) output_path = $out_put_location + @filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#remove_all_properties ⇒ Object
Remove All properties of a document
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/Pdf/document.rb', line 612 def remove_all_properties begin if(@filename == '') raise('PDF file name not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties/' str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.delete(str_signed_uri, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) if stream_hash['Code'] == 200 return true; else return false; end rescue Exception=>e print e end end |
#replace_image_file(page_number, image_index, image_filename) ⇒ Object
Replaces Image in PDF File using Local Image Stream
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/Pdf/document.rb', line 471 def replace_image_file (page_number, image_index, image_filename) begin if(@filename == '') raise('PDF file name not specified.') end if(page_number == '') raise('page number not specified.') end if(image_index == '') raise('image index not specified.') end if(image_filename == '') raise('image filename not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/images/' + image_index.to_s + '/imagefile=' + image_filename str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.post(str_signed_uri, '', {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(@filename) output_path = $out_put_location + @filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#replace_image_stream(page_number, image_index, image_stream) ⇒ Object
Replaces Image in PDF File using Local Image Stream
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/Pdf/document.rb', line 421 def replace_image_stream (page_number, image_index, image_stream) begin if(@filename == '') raise('PDF file name not specified.') end if(page_number == '') raise('page number not specified.') end if(image_index == '') raise('image index not specified.') end if(image_stream == '') raise('image stream not specified.') end str_uri = $product_uri + '/pdf/' + @filename + '/pages/' + page_number.to_s + '/images/' + image_index.to_s str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.post(str_signed_uri, image_stream, {:accept=>'application/json'}) valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream) if valid_output == '' folder = Aspose::Cloud::AsposeStorage::Folder.new output_stream = folder.get_file(@filename) output_path = $out_put_location + @filename; Aspose::Cloud::Common::Utils.save_file(output_stream,output_path) return '' else return valid_output end rescue Exception=>e print e end end |
#set_document_property(property_name, property_value) ⇒ Object
Set specified properity of the document
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/Pdf/document.rb', line 576 def set_document_property property_name, property_value begin if(@filename == '') raise('PDF file name not specified.') end if(property_name == '') raise('property name not specified.') end if(property_value == '') raise('property value not specified.') end # Build JSON to post json_data = JSON.generate('Value'=>property_value) str_uri = $product_uri + '/pdf/' + @filename + '/documentProperties/' + property_name str_signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri) response_stream = RestClient.put(str_signed_uri, json_data, {:accept=>'application/json'}) stream_hash = JSON.parse(response_stream) return stream_hash['DocumentProperty'] rescue Exception=>e print e end end |