Open Alain00 opened 4 years ago
@Alain00 I'm facing this same issue. Were you able to figure this out ?
Hey guys,
tldr: Blob is web-only
I had the same issue and it just occurred to me that Blob
does not exist on Node side (it's using buffers instead).
Basically, it is already a stream so you don't need to make a blob out of it.
In my case, I am creating a PDF from Express and I just had to pipe res
to the document instance:
router.get('/document.pdf', async (req, res) => {
const doc = new PDFDocument();
// vv The following line is the one you're looking for
doc.pipe(res);
doc
.text('And here is some wrapped text...', 100, 300)
.font('Times-Roman', 13);
doc.end();
res.writeHead(200, {
'Content-Type': 'application/pdf',
});
});
If this can be of any help :)
facing the same issue too, I wanted to create a pdf on backend and then use the blob and save it on firebase storage.
Hey guys,
tldr: Blob is web-only
I had the same issue and it just occurred to me that
Blob
does not exist on Node side (it's using buffers instead).Basically, it is already a stream so you don't need to make a blob out of it.
In my case, I am creating a PDF from Express and I just had to pipe
res
to the document instance:router.get('/document.pdf', async (req, res) => { const doc = new PDFDocument(); // vv The following line is the one you're looking for doc.pipe(res); doc .text('And here is some wrapped text...', 100, 300) .font('Times-Roman', 13); doc.end(); res.writeHead(200, { 'Content-Type': 'application/pdf', }); });
If this can be of any help :)
Many Thanks, this is help me more.
blobs are web only
use something like this incase you're in an express/nodejs server
import PDFDocument from "pdfkit";
import express from "express";
const router = express.Router();
router.get( '/', async ( req, res ) => {
const doc = new PDFDocument();
doc.pipe( res );
doc.text( 'And here is some wrapped text...', 100, 300 ).font( 'Times-Roman', 13 );
doc.end();
res.writeHead( 200, {
'Content-Type': 'application/pdf',
} );
} );
export default router;
Looks like Blob
was added to node in v14.18.0 https://nodejs.org/api/all.html#all_buffer_class-blob
I'm getting the following error
This is the code