windows_printing 0.0.3 copy "windows_printing: ^0.0.3" to clipboard
windows_printing: ^0.0.3 copied to clipboard

Windows PDF file Printing plugin using PDFium https://pdfium.googlesource.com/pdfium.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:windows_printing/windows_printing.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> _printerList = [];

  @override
  void initState() {
    super.initState();
    getPrinterList();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getPrinterList() async {
    List<String> printerList;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      printerList = await WindowsPrinting.printersList;
    } on PlatformException {
      printerList = [];
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _printerList = printerList;
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> printPdfFile(String filePath, String printerName) async {
    // Platform messages may fail, so we use a try/catch.
    try {
      String result = await WindowsPrinting.printPdf(filePath, printerName,
          pageNumber: 1, landscape: false);
      debugPrint("printPdfFile: " + result);
    } catch (err) {
      debugPrint("printPdfFile Error: " + err.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.all(16),
                margin: EdgeInsets.all(16),
                color: Colors.black,
                child: Text(
                  'Printer List',
                  style: TextStyle(
                      color: Colors.white, fontWeight: FontWeight.bold),
                ),
              ),
              for (String printerName in _printerList)
                FlatButton(
                  onPressed: () {
                    printPdfFile("sample.pdf", printerName);
                  },
                  child: Text('$printerName'),
                )
            ],
          ),
        ),
      ),
    );
  }
}
12
likes
40
pub points
0%
popularity

Publisher

verified publisherkahloun.online

Windows PDF file Printing plugin using PDFium https://pdfium.googlesource.com/pdfium.

Homepage

License

BSD-2-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on windows_printing