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.init({
pdf: '/',
pdfUrl: 'Your PDF Url',
license: 'Input your license here'
}, viewer)
.then((core) => {
const docViewer = core.docViewer;
docViewer.addEvent('documentloaded',async () => {
console.log('Document Loaded');
})
});Export the PDF Data
const bufferData = await docViewer.exportPDF(saveAs);
const blobData = new Blob([bufferData], { type: 'application/pdf' });| Name | Required | Type | Description | Default Value |
|---|---|---|---|---|
| saveAs | no | boolean | Whether to save as a new file | false |
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,
});