setMargins method
Sets the margins.
//Create a PDF document.
PdfDocument document = PdfDocument();
//Set margins.
document.pageSettings.setMargins(50);
//Create page and draw text.
document.pages.add().graphics.drawString(
'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(0, 0, 0, 0));
//Save and dispose document.
List<int> bytes = await document.save();
document.dispose();
Implementation
void setMargins(double all, [double? top, double? right, double? bottom]) {
if (!_helper.isPageAdded) {
if (top != null && right != null && bottom != null) {
PdfMarginsHelper.getHelper(margins)
.setMarginsAll(all, top, right, bottom);
} else if (top != null && right == null) {
PdfMarginsHelper.getHelper(margins).setMarginsLT(all, top);
} else if (top == null && bottom != null) {
PdfMarginsHelper.getHelper(margins).setMarginsLT(all, bottom);
} else {
PdfMarginsHelper.getHelper(margins).setMargins(all);
}
}
}