galkahana / HummusJS

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

How can I delete the pdf? it does not let me do it I think it's protected against writing #255

Open MedinaGitHub opened 6 years ago

MedinaGitHub commented 6 years ago
          const fs = require('fs');
          let inStream1 = new hummus.PDFRStreamForFile('hola.pdf');
          let inStream2 = new hummus.PDFRStreamForFile('chao.pdf');
          let outStream = new hummus.PDFWStreamForFile( 'result.pdf');
          let pdfWriter = hummus.createWriterToModify(inStream1, outStream);
          pdfWriter.appendPDFPagesFromPDF(inStream2);
          pdfWriter.end();

fs.unlinkSync('result.pdf');
fs.unlinkSync('hola.pdf');
chunyenHuang commented 6 years ago

https://github.com/galkahana/HummusJS/blob/48066498a51cd25074ecce3a70db9b9775cb9fa6/PDFRStreamForFile.js#L51 How about to try with .close?

let inStream1 = new hummus.PDFRStreamForFile('hola.pdf');
...
inStream1.close(()=>{
    fs.unlinkSync('hola.pdf');
});