printPdf method

Future<void> printPdf({
  1. required String fileName,
  2. PdfPageMode pageMode = PdfPageMode.thumbs,
  3. bool compress = false,
  4. PdfVersion pdfVersion = PdfVersion.pdf_1_5,
  5. PdfPageFormat pageFormat = PdfPageFormat.undefined,
  6. PageOrientation? pageOrientation,
  7. String? title,
  8. String? author,
  9. String? creator,
  10. String? subject,
  11. String? keywords,
  12. String? producer,
})

This method takes the binary data obtained from a widget rendering task and renders it into a printing layout.

If there is no Widget attached or if an error occurs during the convertion, this method throws an Exception.

Implementation

Future<void> printPdf({
  required String fileName,
  PdfPageMode pageMode = PdfPageMode.thumbs,
  bool compress = false,
  PdfVersion pdfVersion = PdfVersion.pdf_1_5,
  PdfPageFormat pageFormat = PdfPageFormat.undefined,
  pdf_widgets.PageOrientation? pageOrientation,
  String? title,
  String? author,
  String? creator,
  String? subject,
  String? keywords,
  String? producer,
}) async {
  if(!(await Printing.layoutPdf(
    onLayout: (PdfPageFormat format) async => await getPdf(
      pageMode: pageMode,
      compress: compress,
      pdfVersion: pdfVersion,
      pageFormat: format,
      pageOrientation: pageOrientation,
      title: title,
      author: author,
      creator: creator,
      subject: subject,
      keywords: keywords,
      producer: producer
    ) ?? Uint8List(0),
    name: fileName,
    format: pageFormat
  ))) {
    throw Exception(
      "An error occurred while gererating the PDF printing layout."
    );
  }
}