galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.15k stars 169 forks source link

TypeError: Unable to end PDF (Random: out of 10, 5 times I got an error.) #321

Closed hrdk108 closed 6 years ago

hrdk108 commented 6 years ago

My Image is in png format. The issue is random. Out of 10, 5 times it gives an error.

try{
      var pdfWriter = hummus.createWriterToModify(termCondFilePath, {modifiedFilePath: signedDocFilePath});
      var pageModifier = new hummus.PDFPageModifier(pdfWriter,4,true);
      var ctx = pageModifier.startContext().getContext();
    ctx.drawImage(70,180, imageFilePath, {transformation:{width:150,height:100, proportional:true}});
    pageModifier.endContext().writePage();
    pdfWriter.end();
    if(fs.existsSync(signedDocFilePath)){
      callback(null, "successfully created PDF");
    } else {
      callback("Error while creating document.");
    }
  } catch(e){
    console.log("try....catch.....e.....", e);
    callback(e);
  }

Log error:

try....catch.....e..... TypeError: Unable to end PDF
    at generateSignedDoc (/Users/hardik.shah/git/BE/fileStream/service/fileStream.js:38:15)
    at Promise.apply (/Users/hardik.shah/git/BE/node_modules/q/q.js:1185:26)
    at Promise.promise.promiseDispatch (/Users/hardik.shah/git/BE/node_modules/q/q.js:808:41)
    at /Users/hardik.shah/git/BE/node_modules/q/q.js:1411:14
    at runSingle (/Users/hardik.shah/git/BE/node_modules/q/q.js:137:13)
    at flush (/Users/hardik.shah/git/BE/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
hrdk108 commented 6 years ago

The issue was, hummus is processing before fileStream for png image get closed. So, I need to take care of fstream close event first and then serve an image to hummus. That was not an issue from hummus library.