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/

Hi,

I am using web worker only, still there is performance issue.

And yes wasm file is loading once intially.

Kindly suggest, if any other way is there to enhance performance.

Thank you.

Greetings!
Our team is constantly working to improve the quality of our products.
Feedback from our customers is very important to us.
We are currently testing a new algorithm for replacing text in a PDF file.
On the test PDF we got more than 3 times speedup.
In the short term we will inform about the results and plans.

Hi,

Thank you for your reply.

As I mentioned before, we used temporary license for POC and it succeeds except the performance rate.

However, we have planned (under process) to buy license for this replace pdf text functionality. Only, we have concern about this performance issue which will have bad user experience.

Kindly assist on this.

Hello!

In the next version (24.11) the accelerated text replacement algorithm will be implemented.
Release this week (or next week).

PS We are grateful for your interest in our product.

1 Like

Glad to hear for new release :blush:.

Thank you for the heads up.

Greetings!

I’ll post here when the new 24.11 release is available.

PS. We recommend using Chrome and MS Edge browsers. The tests showed the best performance results in them.

Hello!

Aspose.PDF for JavaScript via C++ 24.11 has been published.

Install Aspose.PDF for JavaScript via C++

To install and use Aspose.PDF for JavaScript via C++ from a -*ZIP archive, follow the following instructions:

To install and use Aspose.PDF for JavaScript via C++ from NPMJS, follow the following instructions:

  • npm i aspose-pdf-js

To install and use Aspose.PDF for JavaScript via C++ from GITHUB, follow the following instructions:

  • npm install git+https://github.com/aspose-pdf/Aspose.PDF-for-JavaScript-via-CPP

Details

Hi,

We tried the new release. However, the pdf replace text functionality is still taking time to process.

In 24.10 release it was taking around 2mins, in 24.11 also same near about 2mins. Only 10-15seconds difference is there.

Would it be possible to have it less than 1min? Kindly assist.

Thank you.

Hi,

I’m very sorry to hear that you did not experience an improvement in the PDF text replacement processing time. The processing speed can vary significantly depending on the structure of the PDF file and the performance of your computer.

In the 24.11 release, achieved more than a twofold increase in speed with my test file.

If possible, please provide your file, and I will investigate the processing of it.

Thank you.

it is difficult to share the file. But I can tell which languages are being used.

we are using two languages ‘English’ and ‘Arabic’. The pdf pages are split into two parts where on the left side English is used and on right side Arabic language is used.

Kindly suggest if more than one language is causing delay in performance.

Thank you.

Hello!

Thank you for your response.

I regret that you are unable to provide your PDF file, as it would allow me to test and optimize the algorithm specifically for your case.
The languages used in the PDF and their number do not affect the performance.

If your PDF file is large and you only need to replace text on certain pages, we can improve the replacement process.
We can modify the Aspose.PDF for JavaScript via C++ to include an option for specifying the page number, which should enhance performance (will process only the specified page instead of the entire PDF).
Please let me know if this solution works for you.

Thank you.

Thank you for your suggestion. Could you please assist how page number can be passed.

it would be helpful to test again with specific page number.

Currently this functionality has not been implemented.
We can plan to include this option in the 25.1 release,
which is expected to be available in the second half of January 2025.

Thank you.

Sure, It would be much helpful.

Thank you so much.

We are happy that our product helps you!
We will answer any questions you may have while working with our product.

Thank you.