drawString method
void
drawString(})
Draws the specified text string at the specified location.
//Creates a new PDF document.
PdfDocument doc = PdfDocument()
..pages
.add()
.graphics
//Draw string to PDF page graphics.
.drawString(
'Hello world!',
PdfStandardFont(PdfFontFamily.helvetica, 12,
style: PdfFontStyle.bold),
bounds: Rect.fromLTWH(0, 0, 200, 50),
brush: PdfBrushes.red,
pen: PdfPens.blue,
format: PdfStringFormat(alignment: PdfTextAlignment.left));
//Saves the document.
List<int> bytes = doc.save();
//Dispose the document.
doc.dispose();
Implementation
void drawString(String s, PdfFont font,
{PdfPen? pen, PdfBrush? brush, Rect? bounds, PdfStringFormat? format}) {
PdfRectangle layoutRectangle;
if (bounds != null) {
layoutRectangle = PdfRectangle.fromRect(bounds);
} else {
layoutRectangle = PdfRectangle.empty;
}
if (pen == null && brush == null) {
brush = PdfSolidBrush(PdfColor(0, 0, 0));
}
s = _normalizeText(font, s);
_helper.layoutString(s, font,
pen: pen,
brush: brush,
layoutRectangle: layoutRectangle,
format: format);
}