pdf 1.3.4 copy "pdf: ^1.3.4" to clipboard
pdf: ^1.3.4 copied to clipboard

outdated

A pdf producer for Dart. It can create pdf files for both web or flutter.

Pdf creation library for dart / flutter #

This library is divided in two parts:

  • a low-level Pdf creation library that takes care of the pdf bits generation.
  • a Widgets system similar to Flutter's, for easy high-level Pdf creation.

It can create a full multi-pages document with graphics, images and text using TrueType fonts. With the ease of use you already know.

Example document

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

The coordinate system is using the internal Pdf unit:

  • 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 = Document()
  ..addPage(Page(
      pageFormat: PdfPageFormat.a4,
      build: (Context context) {
        return Center(
          child: Text("Hello World"),
        ); // Center
      })); // Page

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

Image image = decodeImage(Io.File('test.webp').readAsBytesSync());
PdfImage image = 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 = PdfTtfFont(
  pdf,
  (File("open-sans.ttf").readAsBytesSync() as Uint8List).buffer.asByteData());
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0);

To save the image on Flutter, use the path_provider library:

Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
var file = File("$tempPath/file.pdf");
await file.writeAsBytes(pdf.save());
2447
likes
0
pub points
99%
popularity

Publisher

verified publishernfet.net

A pdf producer for Dart. It can create pdf files for both web or flutter.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, utf, vector_math

More

Packages that depend on pdf