yjy_printing 5.10.4 copy "yjy_printing: ^5.10.4" to clipboard
yjy_printing: ^5.10.4 copied to clipboard

Plugin that allows Flutter apps to generate and print documents to compatible printers on Android, iOS, macOS, Windows, and Linux, as well as web print.

example/lib/main.dart

// 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';

Future<void> main() async {
  runApp(const MyApp('Printing Demo'));
}

class MyApp extends StatelessWidget {
  const MyApp(this.title, {Key? key}) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(title: Text(title)),
          // body: PdfPreview.builder(
          //   build: (format) => _generatePdf(format, title),
          //   pagesBuilder: (context, pages) =>
          //       SingleChildScrollView(
          //         child: Wrap(
          //           spacing: 8,
          //           runSpacing: 8,
          //           children: [
          //             for (final page in pages)
          //               Container(
          //                 color: Colors.white,
          //                 child: Image(
          //                   image: page.image,
          //                   width: 300,
          //                 ),
          //               )
          //           ],
          //         ),
          //       ),
          // )
          body: PdfPreview(
            actions: [],
            allowPrinting: false,
            allowSharing: false,
            build: (format) => _generatePdf(format, title),
          ),
    )
    ,
    );
  }

  Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async {
    final pdf = pw.Document(version: PdfVersion.pdf_1_5, compress: true);
    final font = await PdfGoogleFonts.nunitoExtraLight();

    pdf.addPage(
      pw.Page(
        pageFormat: format,
        build: (context) {
          return pw.Column(
            children: [
              pw.SizedBox(
                width: double.infinity,
                child: pw.FittedBox(
                  child: pw.Text(title, style: pw.TextStyle(font: font)),
                ),
              ),
              pw.SizedBox(height: 20),
              pw.Flexible(child: pw.FlutterLogo())
            ],
          );
        },
      ),
    );

    return pdf.save();
  }
}
0
likes
70
points
43
downloads
screenshot

Publisher

unverified uploader

Weekly Downloads

Plugin that allows Flutter apps to generate and print documents to compatible printers on Android, iOS, macOS, Windows, and Linux, as well as web print.

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

ffi, flutter, flutter_web_plugins, http, image, js, meta, pdf, plugin_platform_interface

More

Packages that depend on yjy_printing