Find and Replace PDF text in NodeJS SDK delay issue

Hello,

I am trying to find a good solution for my company in order to achieve the ability to replace a font through out the entirety of any PDF that is generated from within another system.

I have a few concerns which I’d like to find an answer to before I advise my company on whether to move forward with this product or not. Therefore, I was wondering as an open question if any of you have faced these following issues:

  • During our limited trial, we managed to create a suitable POC for what we are trying to achieve using Aspose.PDF NodeJS CloudSDK, but there were some delays while waiting for the response to come back, at times it never gave back a response, ultimately having to re run the same process in order to get a response from the API. Is that something that was happening on my end or is it a side-effect of running the limited trial?

  • The PDFs generated will take multiple roles, that being said, some parts of the PDFs are hidden. While using the Cloud SDK for NodeJs postDocumentTextReplace method, we noticed the hidden parts of the PDF were suddenly made visible as part of the manipulation. Is there any chance we can check for those hidden parts and ignore them as the intended goal is to only change the font of the visible elements?

  • We are going to require a large amount of PDFs to be processed in a fairly short amount of time on a daily basis. Is the API capable of meeting such requirements as well as a significant reliability as we can’t afford the systems to be down often?

Thank you very much for your time.

@CristianToporascu

Thanks for your interest in Aspose.PDF Cloud API. About the free trial plan, there are no restrictions on it except monthly 150 API calls limits. So there is no link to delayed response with the free trial plan. We will appreciate it if you please share some sample input documents along with the code to replicate the issue at our end. We will investigate it and share our findings with you.

I am afraid currently there is no option available to check and ignore the hidden parts in the test replacement. We try to mimic Adobe Acrobat, can you achieve this using Adobe Acrobat. We will appreciate it if you please share a sample input PDF document to test the scenario along with the text values to replace. We will look into it and will create a feature request accordingly.

There are very rare chances of our service interruption but we have placed workflow to overcome it as soon as possible. And we can claim the service reliable and stable as we already have a number of satisfied customers.

The goal we are trying to achieve is to get all future generated PDFs from the new system we are integrating to use our company’s signature font in all of the customer facing documents.

The system we are integrating does not support any Non Microsoft standard fonts hence why we were using Aspose as an attempt to create a POC for the business to decide whether it should be the solution we would move forward with.

We have tested both the On Premise .NET SDK as well as the Cloud SDK to investigate thoroughly which is the better option in this case. The .NET SDK has worked although functional we would prefer a cloud based solution.

I will provide the code, as well as attach the main PDF, and the final outcome after replacing the font throughout the PDF. While replacing with the Cloud solution, under Invoice you can see there is an extra E that shows up, which is an artefact from the aforementioned d hidden element suddenly being visible. Although now visible, it has not assumed the new font, our assumption being that the getText method does not see the text hence why is not replacing the font, but the generation of the PDF following the postReplace call enables it.

const fs = require('fs');

const { PdfApi } = require("asposepdfcloud");

var configProps = require('./config');

var datatoload = require('./datatoload');

// Instantiate Aspose.Pdf API SDK

var pdfApi = new PdfApi(configProps.app_sid, configProps.api_key);

const name = "Infor.pdf";

const x = 0;

const y = 0;

const width = 0;

const height = 0;

let trr = {}

trr.textReplaces = []; // datatoload.data;

trr.startIndex = 0;

trr.countReplace = 1;

trr.defaultFont = 'Arial';
pdfApi.getText(name, x, y, width, height, null, null, null, null)
  .then(
    (result) => {
      let textJSON = JSON.parse(result.response.text);
      textJSON.TextOccurrences.List.map( element => { 
        if (element.Text && element.Text != " ") {
          // console.log(element);
          let replacer = {}
          replacer.oldValue = element.Text;
          replacer.newValue = element.Text;
          replacer.regex = false;

          replacer.rect = {};
          replacer.rect.lLX = element.Rect.LLX;
          replacer.rect.lLY = element.Rect.LLY;
          replacer.rect.uRX = element.Rect.URX;
          replacer.rect.uRY = element.Rect.URY;

          replacer.textState = {}
          replacer.textState.foregroundColor = {
            "r": 0,
            "g": 0,
            "b": 0,
            "a": 255
          }
          if (element.TextState.Font === 'Arial,Bold') {
            replacer.textState.fontFile = 'UniversLTStd-Bold.ttf';
            replacer.textState.font = 'UniversLTStd-Bold';
          } else {
            replacer.textState.fontFile = 'UniversLTStd-Light.ttf';
            replacer.textState.font = 'UniversLTStd-Light';
          }
          
          trr.textReplaces.push(replacer);
        }
       
        pdfApi.postDocumentTextReplace(name, trr, null, null)
        .then((result) => {
          console.log(result.response);
        });
      });
    }
  );

AfterAspose.pdf (90.7 KB)
BeforeAspose.pdf (69.6 KB)

I am pleased to hear that the Cloud service is reliable and stable and I’ll feed that back to the business. Our concern was raised out of the POC we made using the limited trial.

@CristianToporascu

We have tested the scenario and noticed an extra e under the Invoice text at the top right corner of the PDF document. We have logged a ticket PDFCLOUD-2359 for further investigation and rectification. We will notify you as soon as it is resolved.