How to Replace Text and Images in PDF document in Ruby using Aspose.PDF REST API

Hello trying to use: GitHub - aspose-pdf-cloud/aspose-pdf-cloud-ruby: Ruby library for communicating with the Aspose.PDF Cloud API


I’ve been able to upload a pdf and to see its page count, event get the text. But when it comes to editing a pdf I just get 400 bad requests.

looking at my activity log I see:
Object reference not set to an instance of an object.


It could be looking at the library code, that it’s not updated to take storage parameters.

Anyway i’m interested in replacing text and images, both do not work.


Hi Matthew,


We are sorry for the inconvenience caused. We are looking into the issue and will get back to you soon.

Best Regards,

Hi Mathew,

Thanks for your patience. Your reported issue has been fixed. Please download the latest Ruby SDK of Aspose.PDF Cloud. Hopefully, now it will help you to accomplish your requirements.

Please feel free to contact us for any further assistance.

Best Regards,

@matt8

As an update, please note we have released a new API Version V3.0 of Aspose.PDF Cloud API. It is more simplified and better in memory management than older versions. Please find the sample code for replacing text in a PDF document for reference. Kindly also check updated Ruby SDK of Aspose.PDF Cloud and feel free to contact us for any assistance in this regard.

def test_post_document_text_replace
    file_name = 'marketing.pdf'
    rect = Rectangle.new
    rect.llx = 100
    rect.lly = 100
    rect.urx = 300
    rect.ury = 300

    text_replace = TextReplace.new
    text_replace.old_value = 'market'
    text_replace.new_value = 'm_a_r_k_e_t'
    text_replace.regex = false
    text_replace.rect = rect

    text_replace_list = TextReplaceListRequest.new
    text_replace_list.text_replaces = [text_replace]
    text_replace_list.start_index = 0
    text_replace_list.count_replace = 0


    opts = {
        :folder => @temp_folder
    }

    response  = @pdf_api.post_document_text_replace(file_name, text_replace_list, opts)

  end