Performance issue in PDF replace text

Hi,

I was trying PDF replace text via javascript using CPP which is working as expected. However, I noticed, it almost taking 2mins time to replace 7 texts in the PDF having 2 pages.

I am using a temporary incense currently for POC. Kindly suggest on the performance issue.

Thank you.

@rakasaha7

It seems you are experiencing performance issues when replacing text in a PDF document using JavaScript with Aspose.PDF. Here are some suggestions that may help improve the performance of your text replacement process:

  1. Use Page-Level TextFragmentAbsorber: Instead of applying the TextFragmentAbsorber to all pages at once, consider processing each page individually. This approach can significantly reduce resource consumption and improve performance. Here’s a code snippet to illustrate this:

    for (Page page : document.getPages()) {
        TextFragmentAbsorber absorber = new TextFragmentAbsorber();
        page.accept(absorber);
        
        for (TextFragment textFragment : absorber.getTextFragments()) {
            // Perform your text replacement logic here
        }
    }
    
  2. Check API Version: Ensure you are using the latest version of the Aspose.PDF API, as performance improvements and bug fixes are regularly included in updates. It is recommended to try this with at least version 22.8 of the API.

  3. Environment Details: If the performance issue persists, consider sharing details about your environment, such as the operating system, installed RAM, and Java Development Kit (JDK) version. This information can help in diagnosing the issue further.

  4. Investigate Specific Text Values: If you notice that the performance issue occurs with specific text values, identifying these can help in replicating and addressing the problem more effectively.

If you continue to experience slow performance after trying these suggestions, please provide additional details about your specific use case, and we can assist you further.

Sources:
[1]: Performance too slow

this is not working as I am using javascript via C++ . So i need any javascript code to enhance performance.

Kindly assist.

@rakasaha7

We are checking it and will get back to you shortly.

Hello
Processing a PDF-file consists of two stages:

  1. loading and initializing wasm
  2. processing the PDF

and depends on the performance of the computer.
The first stage is performed only once.

It is also worth trying the option using a web worker.
An example of use can be found in AsposePdfReplaceText_worker.html from the archive on the site https://releases.aspose.com/pdf/javascriptcpp/