graphics property

PdfGraphics? get graphics

Gets graphics context of the template.

//Create a new PDF document.
PdfDocument document = PdfDocument();
//Create a PDF Template.
PdfTemplate template = PdfTemplate(100, 50);
//Draw a rectangle on the template graphics
template.graphics!.drawRectangle(
    brush: PdfBrushes.burlyWood, bounds: Rect.fromLTWH(0, 0, 100, 50));
//Draw a string using the graphics of the template.
template.graphics!.drawString(
    'Hello World', PdfStandardFont(PdfFontFamily.helvetica, 14),
    brush: PdfBrushes.black, bounds: Rect.fromLTWH(5, 5, 0, 0));
//Add a new page and draw the template on the page graphics of the document.
document.pages.add().graphics.drawPdfTemplate(template, Offset(0, 0));
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfGraphics? get graphics {
  if (_helper.isReadonly) {
    _graphics = null;
  } else if (_graphics == null) {
    _graphics = PdfGraphicsHelper.load(size, _getResources, _helper.content);
    _helper.writeTransformation ??= true;
    if (_helper.writeTransformation!) {
      PdfGraphicsHelper.getHelper(_graphics!).initializeCoordinates();
    }
  }
  return _graphics;
}