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

pdfWriter.end() not closing? #257

Closed GoNode5 closed 6 years ago

GoNode5 commented 6 years ago

I have a problem that this (simplified) code seems not to close the created c.pdf. If I try to open the pdf while the server/nodejs is running, I get a an error with Foxit Reader: Encountered a sharing violation while accessing. As soon as I close the node.js, the problem is gone. node v8.7.0 / windows 10

const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;

var hummus = require('hummus');

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World!\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

let inStream1 = new hummus.PDFRStreamForFile('a.pdf');
let inStream2 = new hummus.PDFRStreamForFile('b.pdf');
let outStream = new hummus.PDFWStreamForFile("c.pdf");
let pdfWriter = hummus.createWriterToModify(inStream1, outStream);

   pdfWriter.appendPDFPagesFromPDF(inStream2);
   pdfWriter.end();
jaspersorrio commented 6 years ago

Hi @GoNode5, did you solve the problem?