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.
Use the exportLayers function to extract PDF layers or OCG (optional content group) from a document.
Incoming parameters:
The return value is the data of a new PDF file, which can be downloaded as a Blob.
const doc = documentViewer.getDocument();
// Get layers.
const layers = await doc.getLayersArray();
// Export the first layer.
const result = await doc.exportLayers([layers[0].obj]); // The return value is a new PDF file data
// Export the first two layers and download them.
const data = await doc.exportLayers([layers[0].obj, layers[1].obj]);
const link = document.createElement('a');
link.href = URL.createObjectURL(new Blob([data], { type: 'application/pdf' }));
link.download = 'layers.pdf';
link.click();