PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
ComPDF supports getting document data to save to the local file system or save to the server.
This example shows how to save a document:
// Import the JS file of ComPDFKit Web Demo.
import ComPDFKitViewer from "@compdfkit_pdf_sdk/webviewer";
const viewer = document.getElementById('webviewer');
ComPDFKitViewer({
path: '/',
initialDoc: 'Your PDF Url',
licenseKey: 'Input your license here'
}, viewer)
.then((instance) => {
const { documentViewer, SaveOptions } = instance.Core;
documentViewer.addEventListener('documentLoaded', async () => {
console.log('Document Loaded');
})
});Export the PDF Data
const bufferData = await documentViewer.getDocument().getFileData({ flags: SaveOptions.INCREMENTAL });
const blobData = new Blob([bufferData], { type: 'application/pdf' });| Name | Required | Type | Description | Default Value |
|---|---|---|---|---|
| flags | no | SaveOptions | Save flags. SaveOptions.INCREMENTAL appends the changes to the original file; omit it to save as a new file | — |
const fileName = "document.pdf";
const url = URL.createObjectURL(blobData);
const a = document.createElement("a");
a.href = url;
a.style = "display: none";
a.download = fileName;
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
document.body.removeChild(a);const fileName = 'document.pdf';
const data = new FormData();
data.append('file', blobData, fileName);
const res = await fetch('https://example.com/api/test', {
method: 'POST',
body: data,
});