Free Support Forum - aspose.cloud

Ruby -- replace text on pdf:: undefined local variable or method `opts'


#1

I am getting this error and I am stuck:


“addtexttopdf.rb:16:in <main>': undefined local variable or methodopts’ for main:Object (NameError)“

The Ruby code is below:

require ‘aspose_pdf_cloud’
include AsposePDFCloud

#Get App key and App SID from https://cloud.aspose.com
AsposeStorageCloud::AsposeApp.app_key_and_sid(””, “”)

name = "samplepdf.pdf"
page_number = 1
text_replace = TextReplace.new
text_replace.old_value = "Avalere"
text_replace.new_value = “Inovalone”

# verify the required parameter ‘name’ is set
fail “Missing the required parameter ‘name’ when calling post_page_replace_text” if name.nil?

# verify the required parameter ‘page_number’ is set
fail “Missing the required parameter ‘page_number’ when calling post_page_replace_text” if page_number.nil?

# verify the required parameter ‘text_replace’ is set
fail “Missing the required parameter ‘text_replace’ when calling post_page_replace_text” if text_replace.nil?

# resource path
path = “/pdf/{name}/pages/{pageNumber}/replaceText”.sub(’{format}’,‘json’).sub(’{’ + ‘name’ + ‘}’, name.to_s).sub(’{’ + ‘pageNumber’ + ‘}’, page_number.to_s)

# query parameters
query_params = {}
query_params[:‘storage’] = opts[:‘storage’] if opts[:‘storage’]
query_params[:‘folder’] = opts[:‘folder’] if opts[:‘folder’]

# header parameters
header_params = {}

# HTTP header ‘Accept’ (if needed)
_header_accept = [‘application/json’, ‘text/json’, ‘application/xml’, ‘text/xml’, ‘text/javascript’]
_header_accept_result = @api_client.select_header_accept(_header_accept) and header_params[‘Accept’] = _header_accept_result

# HTTP header ‘Content-Type’
_header_content_type = [‘application/json’, ‘text/json’, ‘application/xml’, ‘text/xml’, ‘text/javascript’, ‘application/x-www-form-urlencoded’]
header_params[‘Content-Type’] = @api_client.select_header_content_type(_header_content_type)

# form parameters
form_params = {}

# http body (model)
post_body = @api_client.object_to_http_body(text_replace)

auth_names = []
result = @api_client.call_api(:POST, path,
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => ‘PageTextReplaceResponse’)

return result

#2

Hi there,


Thanks for your inquiry. We are looking into it and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,