pdf 1.0.5

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

Pdf creation library for dart / flutter

This is a low-level Pdf creation library. It can create a full multi-pages document with graphics, images and text using TrueType fonts.

Use printing package https://pub.dartlang.org/packages/printing for full flutter print and share operation.

The coordinate system is using the internal Pdf system:

  • (0.0, 0.0) is bottom-left
  • 1.0 is defined as 1 / 72.0 inch
  • you can use the constants for centimeters, milimeters and inch defined in PDFPageFormat

Example:

final pdf = new PDFDocument();
final page = new PDFPage(pdf, pageFormat: PDFPageFormat.LETTER);
final g = page.getGraphics();
final font = new PDFFont(pdf);

g.setColor(new PDFColor(0.0, 1.0, 1.0));
g.drawRect(50.0, 30.0, 100.0, 50.0);
g.fillPath();

g.setColor(new PDFColor(0.3, 0.3, 0.3));
g.drawString(font, 12.0, "Hello World!", 5.0 * PDFPageFormat.MM, 300.0);

var file = new File('file.pdf');
file.writeAsBytesSync(pdf.save());

To load an image it is possible to use the dart library image:

Image image = decodeImage(new Io.File('test.webp').readAsBytesSync());
PDFImage image = new PDFImage(
  pdf,
	image: img.data.buffer.asUint8List(),
	width: img.width,
	height: img.height);
g.drawImage(image, 100.0, 100.0, 80.0);

To use a TrueType font:

PDFTTFFont ttf = new PDFTTFFont(
  pdf,
  (new File("open-sans.ttf").readAsBytesSync() as Uint8List).buffer.asByteData());
g.setColor(new PDFColor(0.3, 0.3, 0.3));
g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0);

1.0.5

  • Remove dependency to dart:io
  • Add Contributing

1.0.4

  • Updated homepage
  • Update source formatting
  • Update README

1.0.3

  • Remove dependency to ttf_parser

1.0.2

  • Update sdk support for 2.0.0

1.0.1

  • Add example
  • Lower vector_math dependency version
  • Uses better page format object

example/main.dart

import 'dart:io';

import 'package:pdf/pdf.dart';

void main() {
  final pdf = new PDFDocument(deflate: zlib.encode);
  final page = new PDFPage(pdf, pageFormat: PDFPageFormat.LETTER);
  final g = page.getGraphics();
  final font = new PDFFont(pdf);
  final top = page.pageFormat.height;

  g.setColor(new PDFColor(0.0, 1.0, 1.0));
  g.drawRect(50.0 * PDFPageFormat.MM, top - 80.0 * PDFPageFormat.MM,
      100.0 * PDFPageFormat.MM, 50.0 * PDFPageFormat.MM);
  g.fillPath();

  g.setColor(new PDFColor(0.3, 0.3, 0.3));
  g.drawString(font, 12.0, "Hello World!", 10.0 * PDFPageFormat.MM,
      top - 10.0 * PDFPageFormat.MM);

  var file = new File('example.pdf');
  file.writeAsBytesSync(pdf.save());
}

Use this package as a library

1. Depend on it

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


dependencies:
  pdf: ^1.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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:pdf/pdf.dart';
  
Version Uploaded Documentation Archive
1.0.5 Aug 21, 2018 Go to the documentation of pdf 1.0.5 Download pdf 1.0.5 archive
1.0.4 Aug 15, 2018 Go to the documentation of pdf 1.0.4 Download pdf 1.0.4 archive
1.0.3 Aug 11, 2018 Go to the documentation of pdf 1.0.3 Download pdf 1.0.3 archive
1.0.2 Aug 8, 2018 Go to the documentation of pdf 1.0.2 Download pdf 1.0.2 archive
1.0.1 Jul 24, 2018 Go to the documentation of pdf 1.0.1 Download pdf 1.0.1 archive
1.0.0 Jul 16, 2018 Go to the documentation of pdf 1.0.0 Download pdf 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
74
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]
87
Learn more about scoring.

We analyzed this package on Aug 21, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:pdf/pdf.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
meta ^1.1.5 1.1.6
vector_math ^2.0.0 2.0.8
Dev dependencies
test any