PDFWorkerError Message: Error opening file

Hi while looping through a list of documents some documents get processd correctly but most of them at the end of the loop I receive the following error. Below is the code that I’am using and the error message

Error Message

  type: 'PDFWorkerError',
  message: 'Exception: \n' +
    '\t Message: Error opening file: E:\\10_k_expired_example\\OMB-MC1002000590\\OMB-MC1002000590-drawings.pdf\n' +
    'Exception: \n' +
    '\t Message: file seek failed\n' +
    '\t Conditional expression: seek_result == 0\n' +
    '\t Version      : 9.3.0-88327614b9\n' +
    '\t Platform     : Windows\n' +
    '\t Architecture : AMD64\n' +
    '\t Filename     : MappingManager.cpp\n' +
    '\t Function     : trn::Filters::MappingManager::CreateMapping\n' +
    '\t Linenumber   : 476\n' +
    '\n' +
    '\t Conditional expression: false\n' +
    '\t Version      : 9.3.0-88327614b9\n' +
    '\t Platform     : Windows\n' +
    '\t Architecture : AMD64\n' +
    '\t Filename     : MappingManager.cpp\n' +
    '\t Function     : trn::Filters::MappingManager::Init\n' +
    '\t Linenumber   : 177\n'

Code :
i’m using node.js with pdftron sdk

import path from "path";
import fs from "fs";
import file from "file";
import pkg from "@pdftron/pdfnet-node";
const { PDFNet } = pkg;

const main = async() => {
    let count = 0;
    let folderPath = "E:\\10_k_expired_example";
    const pdfList = walkDirectories(folderPath);

    for(let idx = 0; idx < pdfList.length; idx++) {
    try {
            let doc = await PDFNet.PDFDoc.createFromFilePath(pdfList[idx]);
            let formObject = await doc.getAcroForm();
            if(null != formObject) {
                console.log(`${pdfList[idx]} contains forms count is ${count}`);
            } else {
                console.log(`${pdfList[idx]} NOT forms count is ${count}`);
            await doc.save(pdfList[idx], 0);
    } catch (error) {
PDFNet.runWithCleanup(main, "KEY").catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});

Is this the correct way to batch process many PDF documents. The above code works for around the first 100 to 200 files

When I try to check the filw individually it works as expected just does not work in a loop.

Is this the right way to batch process documents ???

Product Version:

Please give a brief summary of your issue:
(Think of this as an email subject)

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

Please provide a link to a minimal sample where the issue is reproducible:

The issue is that the Javascript GC is not aware of how much memory the PDFDoc instance actually has allocated (since most allocation is unmanaged memory). Instead you want to make the destruction of the PDFDoc instances determinstic by using PDFNet.startDeallocateStack and PDFNet.endDeallocateStack. See this sample.

1 Like

Thank You solved the problem.