Showing
1 changed file
with
46 additions
and
0 deletions
| @@ -67,6 +67,18 @@ pdf.addPage(pw.Page(build: (pw.Context context) { | @@ -67,6 +67,18 @@ pdf.addPage(pw.Page(build: (pw.Context context) { | ||
| 67 | })); // Page | 67 | })); // Page |
| 68 | ``` | 68 | ``` |
| 69 | 69 | ||
| 70 | +To load an image from the network using the `printing` package: | ||
| 71 | + | ||
| 72 | +```dart | ||
| 73 | +final image = await networkImage('https://www.nfet.net/nfet.jpg'); | ||
| 74 | + | ||
| 75 | +pdf.addPage(pw.Page(build: (pw.Context context) { | ||
| 76 | + return pw.Center( | ||
| 77 | + child: pw.Image(image), | ||
| 78 | + ); // Center | ||
| 79 | +})); // Page | ||
| 80 | +``` | ||
| 81 | + | ||
| 70 | To use a TrueType font: | 82 | To use a TrueType font: |
| 71 | 83 | ||
| 72 | ```dart | 84 | ```dart |
| @@ -82,6 +94,40 @@ pdf.addPage(pw.Page( | @@ -82,6 +94,40 @@ pdf.addPage(pw.Page( | ||
| 82 | })); // Page | 94 | })); // Page |
| 83 | ``` | 95 | ``` |
| 84 | 96 | ||
| 97 | +Or using the `printing` package's `PdfGoogleFonts`: | ||
| 98 | + | ||
| 99 | +```dart | ||
| 100 | +final font = await PdfGoogleFonts.nunitoExtraLight(); | ||
| 101 | + | ||
| 102 | +pdf.addPage(pw.Page( | ||
| 103 | + pageFormat: PdfPageFormat.a4, | ||
| 104 | + build: (pw.Context context) { | ||
| 105 | + return pw.Center( | ||
| 106 | + child: pw.Text('Hello World', style: pw.TextStyle(font: font, fontSize: 40)), | ||
| 107 | + ); // Center | ||
| 108 | + })); // Page | ||
| 109 | +``` | ||
| 110 | + | ||
| 111 | +To display emojis: | ||
| 112 | + | ||
| 113 | +```dart | ||
| 114 | +final emoji = await PdfGoogleFonts.notoColorEmoji(); | ||
| 115 | + | ||
| 116 | +pdf.addPage(pw.Page( | ||
| 117 | + pageFormat: PdfPageFormat.a4, | ||
| 118 | + build: (pw.Context context) { | ||
| 119 | + return pw.Center( | ||
| 120 | + child: pw.Text( | ||
| 121 | + 'Hello 🐒💁👌🎍😍🦊👨 world!', | ||
| 122 | + style: pw.TextStyle( | ||
| 123 | + fontFallback: [emoji], | ||
| 124 | + fontSize: 25, | ||
| 125 | + ), | ||
| 126 | + ), | ||
| 127 | + ); // Center | ||
| 128 | + })); // Page | ||
| 129 | +``` | ||
| 130 | + | ||
| 85 | To save the pdf file: | 131 | To save the pdf file: |
| 86 | 132 | ||
| 87 | ```dart | 133 | ```dart |
-
Please register or login to post a comment