drawRectangle method

void drawRectangle({
  1. PdfPen? pen,
  2. PdfBrush? brush,
  3. required Rect bounds,
})

Draws a rectangle specified by a pen, a brush and a Rect structure.

//Create a new PDF document.
PdfDocument doc = PdfDocument()
  ..pages
      .add()
      .graphics
      //Draw rectangle.
      .drawRectangle(
          pen: PdfPens.black, bounds: Rect.fromLTWH(0, 0, 200, 100));
// Save the document.
List<int> bytes = doc.save();
// Dispose the document.
doc.dispose();

Implementation

void drawRectangle({PdfPen? pen, PdfBrush? brush, required Rect bounds}) {
  _helper._beginMarkContent();
  _helper._stateControl(pen, brush, null, null);
  _helper.streamWriter!
      .appendRectangle(bounds.left, bounds.top, bounds.width, bounds.height);
  _drawPath(pen, brush, PdfFillMode.winding, false);
  _helper.endMarkContent();
  (_helper._getResources!() as PdfResources)
      .requireProcset(PdfDictionaryProperties.pdf);
}