Skip to Content
NexPDF

Platform notes

The UI isolate and background isolates, memory, app size on iOS, Android and desktop, and deployment notes for NexPDF for Flutter.

English

Threading and isolates

The Dart API calls the engine through dart:ffi, synchronously: a call blocks the isolate that makes it until the engine returns. On the UI isolate, a quick call (pageCount, a search, a render at screen size) is fine; a long one (a 300 dpi render, OCR, Office conversion, signing with LTV) freezes the app and drops frames while it runs.

Run long work in a background isolate. Create a NexPdfFlutter and open the document inside the isolate, pass bytes in and results out:

import 'dart:isolate';
import 'dart:typed_data';
import 'package:nexpdf_flutter/nexpdf_flutter.dart';

Future<Uint8List> renderForPrint(Uint8List pdf, int page) {
  return Isolate.run(() {
    final sdk = NexPdfFlutter();          // loads the engine in this isolate
    final doc = sdk.open(pdf);
    try {
      return doc.renderPagePng(page, dpi: 300);
    } finally {
      doc.dispose();
    }
  });
}
  • A document is not thread-safe, and isolates can run at the same time on different threads. Use each NexPdfDocument only in the isolate that opened it.
  • Different documents can be used in different isolates at the same time, so isolates scale across cores for independent files. The state shared between documents (the license and the renderer's caches) is thread-safe.
  • The license is process-wide: one activateLicense call on the main isolate covers background isolates and the native reader.
  • Errors are tracked per thread. The SDK reads the error straight after each failed call, on the same isolate, so an error on one isolate never shows up in another.
  • NexPdfViewerWidget renders its pages synchronously on the UI isolate, at 144 dpi for pages and 36 dpi for the pages grid, and keeps the last 24 renders. For very large pages, render in an isolate and show the PNGs in your own widget.
  • NexPdfReader is a native screen: its engine work runs natively and does not block your Dart isolates. Its events arrive on NexPdfReader.events.

Memory

  • A document is read fully into memory when it is opened. open copies your bytes into native memory for the call and the engine keeps its own copy, so drop your Uint8List if you no longer need it.
  • Results (renderPagePng, save, buffers from C calls through takeBytes) are copied into a Dart Uint8List and the native buffer is freed at once.
  • Call dispose() when you are done with a document. A finalizer frees forgotten documents, but only when the garbage collector runs, which is not predictable.
  • A rendered A4 page at 144 dpi is about 1190 x 1684 pixels before PNG compression, and Image.memory decodes it again. Render at the size you display.
  • The renderer keeps process-wide caches of parsed fonts, glyphs and decoded images, shared by every document. Each cache is bounded by size and drops its least recently used entries first; together they can hold up to about 1.3 GB on a process that renders many large, image-heavy files. On a phone the system can stop a background app long before that, so render at display size and dispose what you no longer show.
  • nexpdf_memory_usage_bytes and nexpdf_trim_memory, through dart:ffi, let long-lived documents give memory back; see Compare and optimise.

Packaging and app size

The Dart package is small. The engine comes from the native SDKs the plugin depends on, or from the library you ship on desktop:

PlatformEngineAlso included
iOSNexPdfCore.xcframework through the NexPdf pod, linked statically into the appThe NexPdfUI reader, which the plugin depends on
Androidlibnexpdf_ffi.so from the com.nexdevit:nexpdf-android AAR, for arm64-v8a, armeabi-v7a and x86_64The JNI bridge and the reader activity
macOS, Windows, Linuxlibnexpdf_ffi.dylib, nexpdf_ffi.dll or libnexpdf_ffi.so that you ship with the appNo native reader
  • On Android the engine library is about 20 MB per ABI, uncompressed. With an Android App Bundle (flutter build appbundle), Google Play delivers only the device's ABI. If you distribute APKs, flutter build apk --split-per-abi makes one APK per ABI instead of one with all three.
  • On iOS the engine is linked statically, and a device build links only the ios-arm64 slice of the xcframework. The .a files in the xcframework are much larger than what ends up in the app, because they hold everything the linker may need. Measure the real size with Xcode's App Thinning Size Report.
  • On desktop the library is about 20 MB per architecture; the macOS library is universal and holds two. The Linux release library needs glibc 2.35 or later (Ubuntu 22.04); there is no musl build.
  • The default engine compiles in the Liberation fonts (about 4 MB) used for non-embedded standard fonts and PDF/A. nexpdf_has_bundled_fonts tells you which build you have.

Requirements

Dart3.3 or later
Flutter3.19 or later
iOS15.0 or later, Swift 5.9
AndroidminSdk 24, compileSdk 35, Java 17
DesktopThe engine library for the platform; no native reader

Deployment

  • Keys are bound to a platform and an app id. NexPdfFlutter.platform is ios, android, macos, windows or linux; the key must list the platforms you ship on. Pass the bundle id on iOS and the package name on Android.
  • Ship the license as an asset and activate it at every launch; activation is offline. See License.
  • On Android, NexPdfReader.open writes the document you pass to the app's cache folder (nexpdf-reader/) before the reader opens it. On iOS the reader opens it from memory.

Network

The engine makes no network calls of its own: license keys are verified offline and documents never leave the device. Only signing options you set (tsa_url for a timestamp, ltv for OCSP and CRL lookups) and nexpdf_add_ltv contact the servers named in the certificates. If you use them:

  • on Android, declare <uses-permission android:name="android.permission.INTERNET"/> in android/app/src/main/AndroidManifest.xml. Flutter's templates add it only to the debug and profile manifests, and the NexPDF libraries do not declare it;
  • on macOS, give the app the com.apple.security.network.client entitlement, since Flutter macOS apps are sandboxed.

On this page