savePdf method

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

This method saves into a PDF file the binary data obtained from a widget rendering task, based on the directive passed to saveMode.

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

Implementation

Future<void> savePdf({
  required String fileName,
  SaveMode saveMode = SaveMode.filePicker,
  String filePickerTitle = "",
  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 {
  Uint8List? pdfByteList = await getPdf(
    pageMode: pageMode,
    compress: compress,
    pdfVersion: pdfVersion,
    pageFormat: pageFormat,
    pageOrientation: pageOrientation,
    title: title,
    author: author,
    creator: creator,
    subject: subject,
    keywords: keywords,
    producer: producer
  );

  if(pdfByteList != null) {
    saveBytes(
      byteList: pdfByteList,
      fileName: fileName,
      fileExtension: "pdf",
      saveMode: saveMode,
      filePickerTitle: filePickerTitle
    );

    return;
  }

  throw Exception("An error occurred during the Widget conversion to PDF.");
}