Core.PDFNet. ContentReplacer doesn't replace content with custom delimiters

Product: @pdftron/pdfnet-node

Product Version: 9.4.2

Product key: Trial key

Core.PDFNet. ContentReplacer doesn’t replace content with custom delimiters. Only with singular square brackets works even custom delimiters are provided.

There is an office document (.docx) with specially marked strings with custom delimiters ({{FIELD}}).

After loading the document and converting it using PDFNet.Convert to the PDFDoc instance and then applying replacer that has custom delimiters, the content does’t change. When custom delimiters has singular delimiter, for example, { and } or < and >, the replacer does not replace required string and replace strings with square brackets instead.

The Test.docx (6.1 KB) test file.

The index file:

import path from 'path';
import fs from 'fs';
import { PDFNet } from '@pdftron/pdfnet-node';

function readDoc(): Buffer {
  const p = path.resolve(process.cwd(), 'Test.docx');
  const b = fs.readFileSync(p);

  return b;

const main = async () => {
  const doc = await PDFNet

  const page = await doc.getPage(1);
  const replacer = await PDFNet

  await replacer.addString('FIELD_01', 'Field 01');
  await replacer.addString('FIELD_02', 'Field 02');
  await replacer.addString('FIELD_03', 'Field 03');
  await replacer.addString('FIELD_04', 'Field 04');
  await replacer.addString('FIELD_05', 'Field 05');

  await replacer.setMatchStrings('{{', '}}'); // #1 - changes nothing
  // await replacer.setMatchStrings('{', '}'); // #2 - change only singular rectangle braces
  // await replacer.setMatchStrings('[', ']'); // #3 - change only singular rectangle braces
  // await replacer.setMatchStrings('<', '>'); // #4 - change only singular rectangle braces
  // await replacer.setMatchStrings('<<', '>>'); // #5 - changes nothing

  await replacer.process(page);

  await`${}.pdf`, PDFNet.SDFDoc.SaveOptions.e_remove_unused);


  .runWithCleanup(main, process.env.PDFTRON_KEY)
  .then(function () { PDFNet.shutdown(); })
  .catch(function (error) {
    console.log('Error: ' + error);



I had no such issues. My hunch is that something went wrong with the DOCX to PDF conversion.

Can you please send me the PDF that your call office2PDF returned?

document.pdf (9.3 KB) created immediate after conversion using extra code (before manipulations):

await`converted-${}.pdf`, PDFNet.SDFDoc.SaveOptions.e_linearized);

The team believes they have identified the issue and are already working on a solution, though I do not have any time estimate yet.

The team has patched our developer preview builds.

Can you please try the latest versions of PDFNet, and see if that corrects the issue.

Developer channel:
Developer channel Apple M1:

Latest official builds, and Release channel, are ready for production usage, however the developer channel builds do not get the same amount of testing and can be in a state of change.

The fix is now available in our latest 9.5 SDK Release builds.

Release channel: PDFTron Systems Inc. | Nightly

Latest official builds, and Release channel, are ready for production usage, however the developer channel builds do not get the same amount of testing and can be in a state of change.

Thanks a lot for your efforts.

I loaded the latest version of @pdftron/pdfnet-node. Then I created a simple script using pure JS and ran the script. In the result file, there were pattern strings (the strings were not replaced as was expected).
Then I commented out the 31-st line and tried another template where squared brackets instead of curly ones. Also, the template document (where string patterns with the squared bracers) was loaded for the test, and the string patterns were replaced.

On my local machine, it still doesn’t work.
It still replaces only patterns with the squared bracers.

The index.js and template files are attached.

index.js (1.7 KB)
template-curly-brackets.docx (11.8 KB)
template-square-brackets.docx (11.8 KB)

Can you please call and log the output of PDFNet.GetVersionString() and send me the output, so I can confirm what code you are running.