loadDocumentFromBytes method

PdfiumWrap loadDocumentFromBytes(
  1. Uint8List bytes, {
  2. String? password,
})

Loads a document from bytes, and if necessary, a password can be specified.

Throws an PdfiumException if the document is null. Returns a instance of PdfiumWrap

Implementation

PdfiumWrap loadDocumentFromBytes(Uint8List bytes, {String? password}) {
  // Allocate a pointer large enough.
  final frameData = allocator<Uint8>(bytes.length);
  // Create a list that uses our pointer and copy in the image data.
  final pointerList = frameData.asTypedList(bytes.length);
  pointerList.setAll(0, bytes);

  _document = pdfium.FPDF_LoadMemDocument64(
      frameData.cast<Void>(),
      bytes.length,
      password != null ? stringToNativeInt8(password) : nullptr,);

  if (_document == nullptr) {
    final err = pdfium.FPDF_GetLastError();
    throw PdfiumException.fromErrorCode(err);
  }
  return this;
}