Save PDFs to a Remote Server Using JavaScript

PSPDFKit for Web makes it possible to upload a document to a remote server. This can be done programmatically by exporting the document and sending it to the destination server.

The following example shows how to use the Fetch Web API to send the ArrayBuffer resolved to by instance.exportPDF() to a remote server:

const arrayBuffer = await instance.exportPDF();
const blob = new Blob([arrayBuffer], { type: 'application/pdf' });
const formData = new FormData();
formData.append("file", blob);
await fetch("/upload", {
	method: "POST",
	body: formData
});

In the example above, the backend server expects to receive a POST request with a content type of multipart/form-data through an /upload endpoint it exposes. The payload of the request will depend upon your specific backend implementation.

When exporting a document, you have several options. Refer to our guides on flattening annotations and incremental saving for more details.

Auto saving can be configured for different scenarios and use cases. You can find more information in our auto save guide.