Hi,
I'm stuck with this explanation :
// This should be a Uint8Array.
// In the browser, you could make a fetch() call and use res.arrayBuffer().
Can someone explain a bit more about this ?
Can this be done with ajax request ?
EDIT
Almost got it with
fetch('docs/example.pdf')
.then(function(response) {
response.arrayBuffer().then(function(buffer) {
const existingPdfDocBytes = buffer[""[[Uint8Array]]""]
But that opens the pdf in the window, don't know why...
Hello @mathiasleroy. You snippet looks close to what you want. Try the below code to convert the ArrayBuffer produced by response.arrayBuffer() into a Uint8Array:
response.arrayBuffer()
.then(function(buffer) {
const existingPdfDocBytes = new Uint8Array(buffer);
const pdfDoc = PDFLib.PDFDocumentFactory.load(
existingPdfDocBytes
);
Most helpful comment
Hello @mathiasleroy. You snippet looks close to what you want. Try the below code to convert the
ArrayBufferproduced byresponse.arrayBuffer()into aUint8Array: