Platform notes
The UI isolate and background isolates, memory, app size on iOS, Android and desktop, and deployment notes for NexPDF for Flutter.
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
NexPdfDocumentonly 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
activateLicensecall 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.
NexPdfViewerWidgetrenders 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.NexPdfReaderis a native screen: its engine work runs natively and does not block your Dart isolates. Its events arrive onNexPdfReader.events.
Memory
- A document is read fully into memory when it is opened.
opencopies your bytes into native memory for the call and the engine keeps its own copy, so drop yourUint8Listif you no longer need it. - Results (
renderPagePng,save, buffers from C calls throughtakeBytes) are copied into a DartUint8Listand 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.memorydecodes 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_bytesandnexpdf_trim_memory, throughdart: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:
| Platform | Engine | Also included |
|---|---|---|
| iOS | NexPdfCore.xcframework through the NexPdf pod, linked statically into the app | The NexPdfUI reader, which the plugin depends on |
| Android | libnexpdf_ffi.so from the com.nexdevit:nexpdf-android AAR, for arm64-v8a, armeabi-v7a and x86_64 | The JNI bridge and the reader activity |
| macOS, Windows, Linux | libnexpdf_ffi.dylib, nexpdf_ffi.dll or libnexpdf_ffi.so that you ship with the app | No 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-abimakes 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-arm64slice of the xcframework. The.afiles 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_fontstells you which build you have.
Requirements
| Dart | 3.3 or later |
| Flutter | 3.19 or later |
| iOS | 15.0 or later, Swift 5.9 |
| Android | minSdk 24, compileSdk 35, Java 17 |
| Desktop | The engine library for the platform; no native reader |
Deployment
- Keys are bound to a platform and an app id.
NexPdfFlutter.platformisios,android,macos,windowsorlinux; 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.openwrites 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"/>inandroid/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.cliententitlement, since Flutter macOS apps are sandboxed.