Showing
1 changed file
with
23 additions
and
1 deletions
| @@ -134,6 +134,28 @@ final pdf = await rootBundle.load('document.pdf'); | @@ -134,6 +134,28 @@ final pdf = await rootBundle.load('document.pdf'); | ||
| 134 | await Printing.layoutPdf(onLayout: (_) => pdf.buffer.asUint8List()); | 134 | await Printing.layoutPdf(onLayout: (_) => pdf.buffer.asUint8List()); |
| 135 | ``` | 135 | ``` |
| 136 | 136 | ||
| 137 | +## Display your PDF document | ||
| 138 | + | ||
| 139 | +This package also comes with a PdfPreview widget to display a pdf document. | ||
| 140 | + | ||
| 141 | +```dart | ||
| 142 | +PdfPreview( | ||
| 143 | + build: (format) => doc.save(), | ||
| 144 | +); | ||
| 145 | +``` | ||
| 146 | + | ||
| 147 | +This widget is compatible with Android, iOS, macOS and web. | ||
| 148 | + | ||
| 149 | +For the web, a javascript library and a small script has to be added to | ||
| 150 | +your `web/index.html` file: | ||
| 151 | + | ||
| 152 | +```html | ||
| 153 | +<script src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.min.js"></script> | ||
| 154 | +<script type="text/javascript"> | ||
| 155 | + pdfjsLib.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.worker.min.js"; | ||
| 156 | +</script> | ||
| 157 | +``` | ||
| 158 | + | ||
| 137 | ## Designing your PDF document | 159 | ## Designing your PDF document |
| 138 | 160 | ||
| 139 | A good starting point is to use PdfPreview which features hot-reload pdf build | 161 | A good starting point is to use PdfPreview which features hot-reload pdf build |
| @@ -161,7 +183,7 @@ Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async { | @@ -161,7 +183,7 @@ Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async { | ||
| 161 | This widget also features a debug switch at the bottom right to display the | 183 | This widget also features a debug switch at the bottom right to display the |
| 162 | drawing constraints used. This switch is available only on debug builds. | 184 | drawing constraints used. This switch is available only on debug builds. |
| 163 | 185 | ||
| 164 | -Moving on to your production application, you can keep only the `_generatePdf` | 186 | +Moving on to your production application, you can keep the `_generatePdf` |
| 165 | function and print the document using: | 187 | function and print the document using: |
| 166 | 188 | ||
| 167 | ```dart | 189 | ```dart |
-
Please register or login to post a comment