class Aspose::Cloud::Pdf::Document

Public Class Methods

new(filename) click to toggle source
# File lib/Pdf/document.rb, line 9
def initialize(filename)
  @filename = filename
end

Public Instance Methods

add_new_page() click to toggle source

Add new page to opend pdf file

# 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 = '') click to toggle source
# 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) click to toggle source

Creates an Empty Pdf document @param string $pdfFileName (name of the PDF file to create)

# 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) click to toggle source

Creates a PDF from HTML @param string $pdfFileName (name of the PDF file to create) @param string $htmlFileName (name of the HTML template file)

# 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) click to toggle source

Creates a PDF from XML @param string $pdfFileName (name of the PDF file to create) @param string $xsltFileName (name of the XSLT template file) @param string $xmlFileName (name of the XML file)

# 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) click to toggle source

Deletes selected page from Pdf document @param page_number

# 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() click to toggle source

Get specified properity of the document

# 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) click to toggle source

Get specified properity of the document @param string propertyName

# 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) click to toggle source

Gets a particular form field field_name

# 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() click to toggle source

Gets the FormField count of the specified PDF document

# 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() click to toggle source

Gets the list of FormFields from the specified PDF document

# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Moves selected page in Pdf document to new location @param page_number @param new_location

# 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() click to toggle source

Remove All properties of a document

# 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) click to toggle source

Replaces Image in PDF File using Local Image Stream @param page_number @param image_index @param image_filename

# 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) click to toggle source

Replaces Image in PDF File using Local Image Stream @param page_number @param image_index @param image_stream

# 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) click to toggle source

Set specified properity of the document @param string propertyName @param string propertyValue

# 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