PDFkit output is unreadable
See original GitHub issueQuestion
I’m trying to generate a pdf in the backend and send it to the mobile app but the result is unreadable data.
Description
My question is what doc.pipe (res) stores in res as an answer, whether it’s a blob or something. If you need to do an application-side decoding or because of this unreadable data
Code sample
` try {
let doc = new PDFDocument();
doc.info['Title'] = 'test Document';
doc.text('Hello Bruno Sousa PDF');
doc.pipe(res);
doc.end();
res.status(200).send();
} catch (error) {
console.log("error: ", error);
res.status(500).send({
status: "error",
}
);
}
`
response in the application the data arrives in this format: ` %PDF-1.3 %ÿÿÿÿ 7 0 obj << /Type /Page /Parent 1 0 R /MediaBox [0 0 612 792] /Contents 5 0 R /Resources 6 0 R
endobj 6 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 8 0 R
endobj 5 0 obj << /Length 220 /Filter /FlateDecode
stream xœµQ1N�1ìó �€`;öx#�¶@‚‚�)�¢8�¶»‚ÿ7x�$ÄmÃ�$ÒX±¬ñÌDˆóÞHBt¥Ó¹|�ÙôîÆwS(˜0µÚ&£q.·�B¢4–ò|ð†† ��Ç ®l� ƒ·ãLÎtPVnÚ¸Iëú–¨�”™ø…Æc¹�åé/ûÑ«¯[�ïWÞËã^±±a«‰%8��º—Ò¤�¦kδÜÛ1‘×�œÑÑfÒŒ�¯á‘=è×;Y/ ±á=g2Ɯ֬�¶W‰F�:6J2ô�%f¡«W,Èó�Äë&㫯ú�=]‚ú endstream endobj 10 0 obj (PDFKit) endobj 11 0 obj (PDFKit) endobj 12 0 obj (D:20191210115354Z) endobj 9 0 obj << /Producer 10 0 R /Creator 11 0 R /CreationDate 12 0 R
endobj 8 0 obj << /Type /Font /BaseFont /Helvetica /Subtype /Type1 /Encoding /WinAnsiEncoding
endobj 4 0 obj <<
endobj 3 0 obj << /Type /Catalog /Pages 1 0 R /Names 2 0 R
endobj 1 0 obj << /Type /Pages /Count 1 /Kids [7 0 R]
endobj 2 0 obj << /Dests << /Names [ ]
endobj xref 0 13 0000000000 65535 f 0000000841 00000 n 0000000898 00000 n 0000000779 00000 n 0000000758 00000 n 0000000208 00000 n 0000000119 00000 n 0000000015 00000 n 0000000661 00000 n 0000000586 00000 n 0000000500 00000 n 0000000525 00000 n 0000000550 00000 n trailer << /Size 13 /Root 3 0 R /Info 9 0 R /ID [ ]
startxref 945 %%EOF `
Your environment
- pdfkit version: “^0.11.0”
- Node version: v10.16.3
- Browser version (if applicable): react-native “0.59.8”
- Operating System: Linux
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top GitHub Comments
It won’t save the document on the server using this code as you are not accessing the servers file system, however it should be displaying the page in your web browser?
You’ll need to show more code to be honest and give more context for what you are trying to do, however this is not a bug in PDFKit, but your code, so I’d suggest moving to StackOverflow.
After using
doc.pipie(res)
don’t useres.status(200).send();
doc.pipe(res)
already send your response to server. You’re trying to send it twice.