document.dart
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import 'dart:io';
import 'dart:async';
import 'package:pdf/pdf.dart';
Future<PdfDocument> generateDocument(PdfPageFormat format) async {
final pdf = PdfDocument(deflate: zlib.encode);
final page = PdfPage(pdf,
pageFormat: format.applyMargin(
left: 2.0 * PdfPageFormat.cm,
top: 2.0 * PdfPageFormat.cm,
right: 2.0 * PdfPageFormat.cm,
bottom: 2.0 * PdfPageFormat.cm));
final g = page.getGraphics();
final font = PdfFont.helvetica(pdf);
final top = page.pageFormat.height - page.pageFormat.marginTop;
g.setColor(PdfColor.orange);
g.drawRect(
page.pageFormat.marginLeft,
page.pageFormat.marginBottom,
page.pageFormat.width -
page.pageFormat.marginRight -
page.pageFormat.marginLeft,
page.pageFormat.height -
page.pageFormat.marginTop -
page.pageFormat.marginBottom);
g.strokePath();
g.setColor(PdfColor(0.0, 1.0, 1.0));
g.drawRRect(
50.0 * PdfPageFormat.mm,
top - 80.0 * PdfPageFormat.mm,
100.0 * PdfPageFormat.mm,
50.0 * PdfPageFormat.mm,
20.0,
20.0,
);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(
font,
12.0,
"Hello World!",
page.pageFormat.marginLeft + 10.0 * PdfPageFormat.mm,
top - 10.0 * PdfPageFormat.mm);
{
final page = PdfPage(pdf,
pageFormat: format.applyMargin(
left: 2.0 * PdfPageFormat.cm,
top: 2.0 * PdfPageFormat.cm,
right: 2.0 * PdfPageFormat.cm,
bottom: 2.0 * PdfPageFormat.cm));
final g = page.getGraphics();
final font = PdfFont.helvetica(pdf);
final top = page.pageFormat.height - page.pageFormat.marginTop;
g.setColor(PdfColor.orange);
g.drawRect(
page.pageFormat.marginLeft,
page.pageFormat.marginBottom,
page.pageFormat.width -
page.pageFormat.marginRight -
page.pageFormat.marginLeft,
page.pageFormat.height -
page.pageFormat.marginTop -
page.pageFormat.marginBottom);
g.strokePath();
g.setColor(PdfColor(0.0, 1.0, 1.0));
g.drawRRect(
50.0 * PdfPageFormat.mm,
top - 80.0 * PdfPageFormat.mm,
100.0 * PdfPageFormat.mm,
50.0 * PdfPageFormat.mm,
20.0,
20.0,
);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(
font,
12.0,
"Hello World!",
page.pageFormat.marginLeft + 10.0 * PdfPageFormat.mm,
top - 10.0 * PdfPageFormat.mm);
}
return pdf;
}