Open sarathsaleem opened 9 years ago
You can use toFile(function(err, file))
and fs.readFile(file.path, 'utf8', callback)
Sorry, I didn't read you issue title :wink: Here's the answer:
chunks = []
stream.on('data', function addToChunks (chunk) { chunks.push(chunk) })
stream.on('end', function onEnd () { res.send(Buffer.concat(chunks).toString()) })
I guess res.send(buffer)
should work. so you can just use Buffer.concat(chunks)
without toString.
By this method I am able to get the response as PDF. But the file is corrupted. I this the pdf jheader and body part has to be handled in different way.
by analyzing the corrupted file.
Analysis terminated; corruptions found.
Page ObjNo Description
0 0 The 'xref' keyword was not found or the xref table is malformed.
0 10 The "Length" key of the stream object is wrong.
0 10 Error in Flate stream: data error.
1 0 The file is corrupt and cannot be repaired. Some of the contents can possibly be recovered.
1 10 Error in Flate stream: data error.
.toString('utf8') also didn't work.
Same issue here. The string produced via stream.on('data' and stream.on('end' method is not valid. A simple test can be where you read the file produced by toFile method into bas64 and compare it with the aforementioned method's buffer.toString('base64'). Content is not the same. Any resolution to this?
I have the same problem, is there someone who succeded in generating the PDF in base64 format string?
solved this way `pdf.create(htmlTemplate.body, options).toStream(function(err, stream) {
var chunks = [];
stream.on('data', function(chunk) {
chunks.push(chunk);
console.log('chunk:', chunk.length);
});
stream.on('end', function() {
var result = Buffer.concat(chunks);
logger.debug(util.format('Received request: %s', result.toString('base64')));
console.log('final result:', result.toString('base64'));
});
});`
@sblantipodi i was able to convert it to base64 encoding. But when i decoded using atob(result.toString('base64')), data seem to be corrupt. Any reason why?
I cannot use the pipe method of a stream, instead I want o convert this stream as a valid pdf string.
So how to convert the stream data into a string.