PdfDocument.fromBase64String constructor

PdfDocument.fromBase64String(
  1. String base64String, {
  2. String? password,
})

Initialize a new instance of the PdfDocument class from the PDF data as base64 string

If the document is encrypted, then we have to provide open or permission passwords to load PDF document

//Load an exisiting PDF document.
PdfDocument document = PdfDocument.fromBase64String(pdfData);
//Add a PDF page and draw text.
document.pages.add().graphics.drawString(
    'Hello World!',
    PdfStandardFont(PdfFontFamily.helvetica, 12),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)),
    bounds: Rect.fromLTWH(0, 0, 150, 20));
//Save the updated PDF document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfDocument.fromBase64String(String base64String, {String? password}) {
  _helper = PdfDocumentHelper(this);
  if (base64String.isEmpty) {
    ArgumentError.value(base64String, 'PDF data', 'PDF data cannot be null');
  }
  _helper.password = password;
  _helper.isLoadedDocument = true;
  _initialize(base64.decode(base64String));
}