printing 2.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 93

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.dartlang.org/packages/pdf for pdf creation. Please refer to https://pub.dartlang.org/documentation/pdf/latest/ for documentation.

To load an image it is possible to use Image.toByteData:

var Image im;
var bytes = await im.toByteData(format: ui.ImageByteFormat.rawRgba);

PdfImage image = PdfImage(
    pdf,
    image: bytes.buffer.asUint8List(), 
    width: im.width, 
    height: im.height);
g.drawImage(image, 100.0, 100.0, 80.0);

To use a TrueType font from a flutter bundle:

var font = await rootBundle.load("assets/open-sans.ttf");
PdfTtfFont ttf = PdfTtfFont(pdf, font);
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0);

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
        ...
    }
    

2.0.0 #

  • Breaking change: Switch libraries to AndroidX
  • Add Page information to PdfDoc object

1.3.5 #

  • Restore compatibility with Flutter 1.0.0
  • Update code to Dart 2.1.0
  • Depends on pdf 1.3.3

1.3.4 #

  • Fix iOS build with Swift
  • Add installation instructions in the Readme
  • Follow Flutter debug painting settings

1.3.3 #

  • Fix dart lint warnings
  • Add documentation
  • Add a filename parameter for sharing
  • Convert Objective-C code to Swift
  • Update Readme

1.3.2 #

  • Fix iOS printing issues

1.3.1 #

  • Fix pana linting notices

1.3.0 #

  • Add a Flutter like widget system

1.2.0 #

  • Fix compileSdkVersion to match appcompat
  • Change license to Apache 2.0
  • Implement asynchronous printing driven by the OS

1.1.0 #

  • Rename classes to satisfy Dart conventions
  • Remove useless new and const keywords
  • Changed appcompat dependency to 26.1.0

1.0.6 #

  • Add screenshot example

1.0.5 #

  • Fix printing from pdf document

1.0.4 #

  • Update example for pdf 1.0.5
  • Add Contributing

1.0.3 #

  • Update source formatting
  • Update README

1.0.2 #

  • Add License file
  • Updated homepage

1.0.1 #

  • Fixed sdk version

1.0.0 #

  • Initial release.

example/README.md

Pdf Printing Example #

import 'dart:async';
import 'package:flutter/material.dart';

import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as Pdf;
import 'package:printing/printing.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Printing Demo'),
        ),
        body: Center(
          child: FlatButton(
            child: Text("Print Document"),
            onPressed: () {
              Printing.layoutPdf(onLayout: buildPdf);
            },
          ),
        ),
      ),
    );
  }

  List<int> buildPdf(PdfPageFormat format) {
    final PdfDoc pdf = PdfDoc()
      ..addPage(Pdf.Page(
          pageFormat: format,
          build: (Pdf.Context context) {
            return Pdf.ConstrainedBox(
              constraints: const Pdf.BoxConstraints.expand(),
              child: Pdf.FittedBox(
                  child: Pdf.Text(
                "Hello World",
              )),
            );
          }));
    return pdf.save();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  printing: ^2.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:printing/printing.dart';
  
Version Uploaded Documentation Archive
2.0.0 Mar 3, 2019 Go to the documentation of printing 2.0.0 Download printing 2.0.0 archive
1.3.5 Feb 27, 2019 Go to the documentation of printing 1.3.5 Download printing 1.3.5 archive
1.3.4 Feb 26, 2019 Go to the documentation of printing 1.3.4 Download printing 1.3.4 archive
1.3.3 Feb 24, 2019 Go to the documentation of printing 1.3.3 Download printing 1.3.3 archive
1.3.2 Feb 6, 2019 Go to the documentation of printing 1.3.2 Download printing 1.3.2 archive
1.3.1 Feb 6, 2019 Go to the documentation of printing 1.3.1 Download printing 1.3.1 archive
1.3.0 Feb 6, 2019 Go to the documentation of printing 1.3.0 Download printing 1.3.0 archive
1.2.0 Feb 3, 2019 Go to the documentation of printing 1.2.0 Download printing 1.2.0 archive
1.1.0 Jan 21, 2019 Go to the documentation of printing 1.1.0 Download printing 1.1.0 archive
1.0.6 Oct 28, 2018 Go to the documentation of printing 1.0.6 Download printing 1.0.6 archive

All 16 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Mar 6, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.3.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
pdf ^1.3.4 1.3.4
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
utf 0.9.0+5
vector_math 2.0.8
Dev dependencies
flutter_test