layers property
PdfPageLayerCollection
get
layers
Gets the collection of the page's layers (Read only).
//Creates a new PDF document
PdfDocument document = PdfDocument();
//Creates a new page
PdfPage page = document.pages.add();
//Gets the layers from the page and Add the new layer.
PdfPageLayer layer = page.layers.add(name: 'Layer1');
//Get the layer graphics.
PdfGraphics graphics = layer.graphics;
graphics.translateTransform(100, 60);
//Draw an Arc.
graphics.drawArc(Rect.fromLTWH(0, 0, 50, 50), 360, 360,
pen: PdfPen(PdfColor(250, 0, 0), width: 50));
graphics.drawArc(Rect.fromLTWH(0, 0, 50, 50), 360, 360,
pen: PdfPen(PdfColor(0, 0, 250), width: 30));
graphics.drawArc(Rect.fromLTWH(0, 0, 50, 50), 360, 360,
pen: PdfPen(PdfColor(250, 250, 0), width: 20));
graphics.drawArc(Rect.fromLTWH(0, 0, 50, 50), 360, 360,
pen: PdfPen(PdfColor(0, 250, 0), width: 10));
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();
Implementation
PdfPageLayerCollection get layers {
if (!_helper.isTextExtraction && !_graphicStateUpdated) {
_layers = PdfPageLayerCollection(this);
_graphicStateUpdated = true;
} else {
_layers ??= PdfPageLayerCollection(this);
}
return _layers!;
}