PdfDocument constructor

PdfDocument({
  1. List<int>? inputBytes,
  2. PdfConformanceLevel? conformanceLevel,
  3. String? password,
})

Initialize a new instance of the PdfDocument class from the PDF data as list of bytes

To initialize a new instance of the PdfDocument class for an exisitng PDF document, we can use the named parameters to load PDF data and password or add conformance level to the PDF

//Create a new PDF document.
PdfDocument document = PdfDocument();
//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 document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfDocument(
    {List<int>? inputBytes,
    PdfConformanceLevel? conformanceLevel,
    String? password}) {
  _helper = PdfDocumentHelper(this);
  _helper.isLoadedDocument = inputBytes != null;
  _helper.password = password;
  _initialize(inputBytes);
  if (!_helper.isLoadedDocument && conformanceLevel != null) {
    _initializeConformance(conformanceLevel);
  }
}