Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Web Guides Export layers

Export Layers ​

Use the exportLayers function to extract PDF layers or OCG (optional content group) from a document.

Incoming parameters:

  • An array composed of obj properties of the layers that need to be exported. If omitted, all layers visible by default are exported.

The return value is the data of a new PDF file, which can be downloaded as a Blob.

javascript
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();