attachments property

Gets the attachment collection of the document.

Implementation

PdfAttachmentCollection get attachments {
  if (_attachments == null) {
    if (!_helper.isLoadedDocument) {
      _attachments = PdfAttachmentCollection();
      if (_helper.conformanceLevel == PdfConformanceLevel.a1b ||
          _helper.conformanceLevel == PdfConformanceLevel.a2b) {
        PdfAttachmentCollectionHelper.getHelper(_attachments!).conformance =
            true;
      }
      _helper.catalog.names!.embeddedFiles = _attachments!;
    } else {
      if (onPdfPassword != null && _helper.password == '') {
        final PdfPasswordArgs args = PdfPasswordArgs._();
        onPdfPassword!(this, args);
        _helper.password = args.attachmentOpenPassword;
      }
      if (_helper._isAttachOnlyEncryption!) {
        _helper.checkEncryption(_helper._isAttachOnlyEncryption);
      }
      final IPdfPrimitive? attachmentDictionary = PdfCrossTable.dereference(
          _helper.catalog[PdfDictionaryProperties.names]);
      if (attachmentDictionary != null &&
          attachmentDictionary is PdfDictionary &&
          attachmentDictionary
              .containsKey(PdfDictionaryProperties.embeddedFiles)) {
        _attachments = PdfAttachmentCollectionHelper.load(
            attachmentDictionary, _helper.crossTable);
      } else {
        _attachments = PdfAttachmentCollection();
        _helper.catalog.names!.embeddedFiles = _attachments!;
      }
    }
  }
  return _attachments!;
}