printing 2.1.9 copy "printing: ^2.1.9" to clipboard
printing: ^2.1.9 copied to clipboard

outdated

Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers

Printing #

Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers

See the example on how to use the plugin.

Example document

This plugin uses the pdf package https://pub-web.flutter-io.cn/packages/pdf for pdf creation. Please refer to https://pub-web.flutter-io.cn/documentation/pdf/latest/ for documentation.

Buy Me A Coffee

Example:

final pdf = Document();

pdf.addPage(Page(
      pageFormat: PdfPageFormat.a4,
      build: (Context context) {
        return Center(
          child: Text("Hello World"),
        ); // Center
      })); // Page

To load an image from an ImageProvider:

const imageProvider = const AssetImage('assets/image.png');
final PdfImage image = await pdfImageFromImageProvider(pdf: pdf.document, image: imageProvider);

pdf.addPage(Page(
    build: (Context context) {
      return Center(
        child: Image(image),
      ); // Center
    })); // Page

To use a TrueType font from a flutter bundle:

final font = await rootBundle.load("assets/open-sans.ttf");
final ttf = Font.ttf(font);

pdf.addPage(Page(
    build: (Context context) {
      return Center(
        child: Text('Dart is awesome', style: TextStyle(font: ttf, fontSize: 40)),
      ); // Center
    })); // Page

To save the pdf file using the path_provider library:

final output = await getTemporaryDirectory();
final file = File("${output.path}/example.pdf");
await file.writeAsBytes(pdf.save());

You can also print the document using the iOS or Android print service:

await Printing.layoutPdf(
      onLayout: (PdfPageFormat format) async => pdf.save());

Or share the document to other applications:

await Printing.sharePdf(bytes: pdf.save(), filename: 'my-document.pdf');

To print an HTML document, simply do:

await Printing.layoutPdf(
    onLayout: (PdfPageFormat format) async => await Printing.convertHtml(
          format: format,
          html: '<html><body><p>Hello!</p></body></html>',
        ));

Installing #

  1. Add this to your package's pubspec.yaml file:

    dependencies:
      printing: any       # <-- Add this line
    
  2. Enable Swift on the iOS project, in ios/Podfile:

    target 'Runner' do
       use_frameworks!    # <-- Add this line
    
  3. Set minimum Android version in android/app/build.gradle:

    defaultConfig {
        ...
        minSdkVersion 19  // <-- Change this line to 19 or more
        ...
    }
    
1454
likes
40
pub points
99%
popularity

Publisher

verified publishernfet.net

Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers

Homepage
Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (LICENSE)

Dependencies

flutter, pdf

More

Packages that depend on printing