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

doc.text() and doc.image() fail #753

Open
MasonP57 opened this issue Dec 5, 2017 · 2 comments
Open

doc.text() and doc.image() fail #753

MasonP57 opened this issue Dec 5, 2017 · 2 comments

Comments

@MasonP57
Copy link

MasonP57 commented Dec 5, 2017

I'm doing something very simple, just adding a QR code and some text to a pdf page. It fails.

I'm using it on Firebase Cloud Functions which uses Node v6.x

Here is the code that works and generates a pdf file that can be opened in a browser/google drive:

doc = new pdf()
pdfpath = path.join(os.tmpdir(), 'test.pdf')
doc.pipe(fs.createWriteStream(pdfpath))
doc.end()

This does not work:

doc = new pdf()
pdfpath = path.join(os.tmpdir(), 'test.pdf')
doc.pipe(fs.createWriteStream(pdfpath))
doc.text('hello world')
doc.end()

No idea how to fix this, every example I can find shows the same thing; that this should work just fine.

@MasonP57
Copy link
Author

MasonP57 commented Dec 5, 2017

If I create a blank pdf file and it works, this is what I get from opening the file in Notepad:

%PDF-1.3
%ÿÿÿÿ
5 0 obj
<<
/Type /Page
/Parent 1 0 R
/MediaBox [0 0 612 792]
/Contents 3 0 R
/Resources 4 0 R
>>
endobj
4 0 obj
<<
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
endobj
6 0 obj
<<
/Producer (PDFKit)
/Creator (PDFKit)
/CreationDate (D:20171205214225Z)
>>
endobj
2 0 obj
<<
/Type /Catalog
/Pages 1 0 R
>>
endobj
1 0 obj
<<
/Type /Pages
/Count 1
/Kids [5 0 R]
>>
endobj
3 0 obj
<<
/Length 23
/Filter /FlateDecode
>>
stream
xœ3T0 B]C ani¤�œË� �I�\
endstream
endobj
xref
0 7
0000000000 65535 f 
0000000327 00000 n 
0000000278 00000 n 
0000000384 00000 n 
0000000119 00000 n 
0000000015 00000 n 
0000000186 00000 n 
trailer
<<
/Size 7
/Root 2 0 R
/Info 6 0 R
>>
startxref
478
%%EOF

Here is the broken pdf created by having the line doc.text('hello world') in the code:

%PDF-1.3
%ÿÿÿÿ
5 0 obj
<<
/Type /Page
/Parent 1 0 R
/MediaBox [0 0 612 792]
/Contents 3 0 R
/Resources 4 0 R
>>
endobj
4 0 obj
<<
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/XObject <<
/I1 6 0 R
>>
>>
endobj
7 0 obj
<<
/Producer (PDFKit)
/Creator (PDFKit)
/CreationDate (D:20171205205103Z)
>>
endobj
2 0 obj
<<
/Type /Catalog
/Pages 1 0 R
>>
endobj
1 0 obj
<<
/Type /Pages
/Count 1
/Kids [5 0 R]
>>
endobj

@alafr
Copy link
Collaborator

alafr commented Dec 29, 2017

You can try to use the finish callback. It could be the server that timeouts before the document is finished. Maybe there is an option to wait longer?

var stream = fs.createWriteStream(pdfpath);
doc.pipe(stream);
stream.on('finish', function() {
  console.log('The file is ready');
});

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

2 participants