Load a PDF as an ArrayBuffer in Standalone mode
Q: How can I load a PDF as an ArrayBuffer in Standalone mode?
A: Instead of passing the document URL directly in the configuration object, you can retrieve it using the required credentials options (PSPDFKit for Web uses credentials: same-origin
) with fetch()
, and then pass it to PSPDFKit.load()
as an ArrayBuffer
, like this:
Copy
1 2 3 4 5 6 7 8 | fetch(url, { credentials: "include" }) .then(res => res.arrayBuffer()) .then(arrayBuffer => { PSPDFKit.load({ container: targetSelector, document: arrayBuffer }); }); |
You’ll find more details about the PSPDFKit.Configuration#document
property in our API docs.
This has been tested with PSPDFKit for Web 2020.2.3