David PHAM-VAN

Update the example to use PdfPreview

# Changelog
## 3.6.1
- Update the example to use PdfPreview
## 3.6.0
- Added pdfFileName prop to PdfPreview Widget [Marcos Rodriguez]
... ...
... ... @@ -134,6 +134,23 @@ final pdf = await rootBundle.load('document.pdf');
await Printing.layoutPdf(onLayout: (_) => pdf.buffer.asUint8List());
```
## Designing your PDF document
A good starting point is to use PdfPreview which features hot-reload pdf build
and refresh.
Take a look at the [example tab](example) for a sample project.
This widget also features a debug switch at the bottom right to display the
drawing constraints used. This switch is available only on debug builds.
Moving on to your production application, you can keep only the `_generatePdf`
function and print the document using:
```dart
await Printing.layoutPdf(onLayout: (format) => _generatePdf(format, title));
```
## Encryption and Digital Signature
Encryption using RC4-40, RC4-128, AES-128, and AES-256 is fully supported using a separate library.
... ...
// ignore_for_file: always_specify_types
// ignore_for_file: public_member_api_docs
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
void main() => runApp(MyApp());
void main() => runApp(const MyApp('Printing Demo'));
class MyApp extends StatelessWidget {
const MyApp(this.title);
final String title;
@override
Widget build(BuildContext context) {
const title = 'Printing Demo';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: Center(
child: IconButton(
icon: const Icon(Icons.print),
onPressed: _printDocument,
),
appBar: AppBar(title: Text(title)),
body: PdfPreview(
build: (format) => _generatePdf(format, title),
),
),
);
}
void _printDocument() {
Printing.layoutPdf(
onLayout: (pageFormat) {
final doc = pw.Document();
doc.addPage(
pw.Page(
build: (pw.Context context) => pw.Center(
child: pw.Text('Hello World!'),
),
),
);
return doc.save();
},
Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async {
final pdf = pw.Document();
pdf.addPage(
pw.Page(
pageFormat: format,
build: (context) {
return pw.Center(
child: pw.Text(title),
);
},
),
);
return pdf.save();
}
}
... ...
... ... @@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to
homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 3.6.0
version: 3.6.1
environment:
sdk: ">=2.3.0 <3.0.0"
... ...