Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition in document generation. #762

Open
Sako73 opened this issue Dec 21, 2017 · 6 comments
Open

Race condition in document generation. #762

Sako73 opened this issue Dec 21, 2017 · 6 comments

Comments

@Sako73
Copy link

Sako73 commented Dec 21, 2017

I just started using the PDFKit. The following works after calling "doc.end()":

// ... doc.end()
setTimeout(() => {
        res.download(`www/${fileName}`);
    }, 3000);

but this returns an empty file:

// ... doc.end()
res.download(`www/${fileName}`);

It appears that doc.end() is a synchronous function. Am I missing an async call, or is it a race condition on the disk?

If I try to read the file from disk immediately after calling doc.end() using fs, I get an empty file then also.

Thanks.

@alafr
Copy link
Collaborator

alafr commented Dec 26, 2017

It is asynchronous:

var doc = new PDFDocument();
var stream = fs.createWriteStream('file.pdf');
stream.on('finish', function() {
  // The file is ready
});
doc.pipe(stream);
doc.end();

See also issues #642, #633, #525 and #265

@fabltd
Copy link

fabltd commented Mar 1, 2022

Hi

I think I have the same issue: Only differnce

First time I call the function the PDF is created and writen to disk.

Next time I call the function the file is writen with zero bytes.

Wait and then retry after a couple of minutes same thing.

Any ideas?

@liborm85
Copy link
Collaborator

liborm85 commented Mar 1, 2022

you can use same pipe method as described above.

@liborm85 liborm85 closed this as completed Mar 1, 2022
@fabltd
Copy link

fabltd commented Mar 1, 2022

This does not fix the issue ! Thats why I reported it

@blikblum
Copy link
Member

blikblum commented Mar 1, 2022

Your pdf has png images?

@blikblum blikblum reopened this Mar 1, 2022
@fabltd
Copy link

fabltd commented Mar 2, 2022

Yes it has PNG images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants