Platform notes
Threading, memory, linking, packaging, iOS, Android and deployment notes for NexPDF for Rust.
Threading
- A
DocumentisSendbut notSync. You can move it to another thread, but the compiler stops you from using one document from two threads at once. - Different documents can be used on different threads at the same time, so threads scale across cores for independent files. The state shared between documents (the license and the renderer's caches) is thread-safe.
doc.try_clone()gives an independent document you can hand to another thread.- The license is process-wide: one
license::activatecall covers every thread. - Errors are tracked per thread, so an error on one thread never leaks into another.
use nexpdf_sdk::Document;
fn render_first_page(path: &str) -> nexpdf_sdk::Result<Vec<u8>> {
Document::open(path)?.render_page_png(0, 144.0) // one document per task
}
let pngs: Vec<_> = std::thread::scope(|s| {
let handles: Vec<_> = paths.iter().map(|p| s.spawn(move || render_first_page(p))).collect();
handles.into_iter().map(|h| h.join().unwrap()).collect()
});The same works with rayon (paths.par_iter().map(|p| render_first_page(p))). In async code, run
NexPDF calls on a blocking pool (for example tokio::task::spawn_blocking): they are synchronous
native calls.
Memory
- A document is read fully into memory when it is opened. Budget roughly the file size plus the decoded pages you touch.
- A rendered page at 144 dpi of an A4 page is about 1190 x 1684 pixels before PNG compression. Render large documents page by page instead of keeping every PNG.
- The renderer keeps process-wide caches of parsed fonts, glyphs and decoded images, shared by every document so a logo or font used in many files is decoded once. 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. Memory that stays high after a rendering batch is this cache being reused, not a leak.
- A document is freed when it is dropped, at a predictable point. Call
drop(doc)to free it before the end of its scope. memory_usage_bytes()andtrim_memory()let long-lived documents give memory back; see Compare and optimise.
Linking and size
- The engine is one library per platform, about 20 MB for one architecture (the macOS library is
universal and holds two). With
NEXPDF_STATIC=1it is linked into your executable, which then needs nothing at run time; otherwise shiplibnexpdf_ffi.so,libnexpdf_ffi.dylibornexpdf_ffi.dllwith it. See Installation. - The default engine compiles in the Liberation fonts (about 4 MB) used for non-embedded standard
fonts and PDF/A.
nexpdf_sdk::has_bundled_fonts()tells you which build you have. nexpdf_sdk::sysre-exportsnexpdf-sys, the raw C declarations.Document::as_ptr,as_mut_ptr,into_rawand theunsafeDocument::from_rawmove a handle between the safe and the raw API.
iOS and Android
Build your Rust library for the device targets with NEXPDF_LIB_DIR_<target> set to the matching
slice of NexPdfCore.xcframework (iOS, static) or ABI folder of the AAR (Android, shared); see
Installation.
- On iOS the engine is linked statically into your library; nothing else needs to be bundled.
Activate the license with platform
ios. - On Android, package
libnexpdf_ffi.soin the APK'sjniLibs/<abi>/next to your own library. Activate the license with platformandroid. - Documents are read from memory, so pass files from the app sandbox with
Document::openor bytes from assets withDocument::from_bytes.
Serverless
Container and function runtimes work like any Linux x86_64 or arm64 host, as long as the image has
glibc 2.35 or later (see Troubleshooting). A static build is a single
executable. Activate the license once at start-up so warm invocations reuse it. Use /tmp for
intermediate files, or work with from_bytes and save_bytes to stay in memory.
Network
The engine makes no network calls of its own: license keys are verified offline and documents
never leave the process. Only signing options you set (tsa_url for a timestamp, ltv for OCSP
and CRL lookups) and add_ltv contact the servers named in the certificates.