I am generating PDF dynamically on the server in response to params received from ajax request. I need to handle the response in ajax and pass the PDF to PDF.js as a data object.
I do not want to write these PDF to the server - I rather have a clean process that returns the PDF stream instead
I have done something similar successfully using filereader - loading local PDF into PDF.js in the browser as ArrayBuffer.
The responseType is 'application/pdf' and the raw PDF is being returned but I cannot seem to convert it to an ArrayBuffer for PDF.js
var responseText = src
var len = responseText.length
console.log(len);
var buf = new ArrayBuffer(len);
console.log(buf);
var bufView = new Uint8Array(buf);
console.log(bufView);
for (var i=0; i < len; i++) {
bufView[i] = responseText.charCodeAt(i);
}
console.log(bufView);
var docInitParams = { data: bufView};
PDFJS.getDocument(docInitParams).then(function(pdf) {......
Here is the output of the above code