我正在创建一个生成 PDF 的应用程序。但我需要缩小标题和内容之间的差距。我使用一个名为 pdf 的包来创建 PDF。 https://pub.dev/packages/pdf 这是包的链接。
我想缩小的空间用红色箭头表示。
这是我用来创建 PDF 的代码。
Future<Uint8List> _generatePdf() async {
String name = controllerName.text;
String age;
String complain = controllerComplain.text;
String systolicPressure = controllerSystolicPressure.text;
String diastolicPressure = controllerDiastolicPressure.text;
String fullPressure = systolicPressure + "/" + diastolicPressure + " mmHg";
if (controllerAgeYears.text == '') {
} else {
age = controllerAgeYears.text + " years ";
}
if (controllerAgeMonths.text == '') {
} else {
age += controllerAgeMonths.text + ' Months';
}
String mOF = '';
if (_isSelected[0] == true) {
mOF = 'Male';
} else {
mOF = 'Female';
}
pdf.addPage(pw.MultiPage(
pageFormat: PdfPageFormat.a5,
margin: pw.EdgeInsets.all(32),
build: (pw.Context context) {
return <pw.Widget>[
pw.Text("Methsuwa Family Clinic",
style: pw.TextStyle(fontSize: 22)),
pw.Header(
level: 0,
child: pw.Text("No: 607, Medamandiya, Panagoda, Homagame.",
style: pw.TextStyle(fontSize: 10)),
),
pw.Text('Name: ' + name, style: pw.TextStyle(fontSize: 10)),
pw.SizedBox(height: 3),
pw.Text('Age: ' + age, style: pw.TextStyle(fontSize: 10)),
pw.SizedBox(height: 3),
pw.Text('Gender: ' + mOF, style: pw.TextStyle(fontSize: 10)),
pw.SizedBox(height: 3),
pw.Text('Complains: ' + complain,
style: pw.TextStyle(fontSize: 10)),
pw.SizedBox(height: 3),
pw.Text('Blood Pressure: ' + fullPressure,
style: pw.TextStyle(fontSize: 10)),
pw.SizedBox(height: 6),
pw.Table.fromTextArray(
context: context,
headerStyle: pw.TextStyle(fontSize: 10),
cellStyle: pw.TextStyle(fontSize: 10),
data: <List<String>>[
<String>['Drug', 'Amount', 'Days', 'When', 'Total'],
..._data.map((msg) => [
msg["drug"],
msg["amount"],
msg["days"],
msg["when"],
msg["total"]
])
]),
pw.SizedBox(height: 6),
pw.Table.fromTextArray(
context: context,
headerStyle: pw.TextStyle(fontSize: 10),
cellStyle: pw.TextStyle(fontSize: 10),
data: <List<String>>[
<String>['Investigations'],
...selectedInvestigations.map((msg) => [msg["investigation"]])
]),
//pw.Text(
// 'Daily:එදිනෙදා, BID:දිනකට දෙවරක්, TID:දිනකට තෙවරක්, QID:දිනකට සතරවරක්, QHS:නින්දට පෙර Q4h:සෑම පැය සතරකට වරක් Q4-6h:සෑම පැය සතරත් සයත් තුල QWK:සෑම සතියකට වරක්',
// ),
];
}));
pdfPrint = pdf;
pdf = null;
pdf = pw.Document();
return pdfPrint.save();
}
Future savePdf() async {
pdf = null;
pdf = pw.Document();
}