Troubleshooting
Fixes for the most common problems with NexPDF for Go - cgo builds, linking and loading the native library, license and watermark issues, fonts, signatures and OCR.
The module uses cgo. With CGO_ENABLED=0 (the default when no C compiler is found, and common in
cross-compiling setups) the package's cgo files are skipped and its functions appear undefined.
Install a C compiler (gcc or clang) and build with:
export CGO_ENABLED=1
go build .cgo cannot find the C header. Point it at the include/ folder of the extracted release archive:
export CGO_CFLAGS="-I/opt/nexpdf-ffi-1.1.0-linux-x64/include"See Installation.
The linker cannot find the library. Pass its folder with -L, and add an rpath so the program finds
the shared library at run time:
export CGO_LDFLAGS="-L/opt/nexpdf-ffi-1.1.0-linux-x64/lib -Wl,-rpath,/opt/nexpdf-ffi-1.1.0-linux-x64/lib"The module cache is read-only, so copying the library into the module folder does not work.
The header and the library come from different releases: a newer header declares a function the
older library does not have. Use the include/ and lib/ folders of the same archive, and the
archive of the release that matches the module version.
With the static library on Linux, undefined references to dlopen or pthread_* mean the system
libraries are missing from CGO_LDFLAGS: add -lpthread -ldl -lm. On macOS add
-framework Security -framework CoreFoundation. See
Installation.
The program was linked against the shared library but cannot find it at run time. Either keep the
rpath you linked with pointing to where the library is installed, set LD_LIBRARY_PATH
(DYLD_LIBRARY_PATH on macOS), or link the static library so the program needs no
libnexpdf_ffi at all.
The library's install name is @rpath/libnexpdf_ffi.dylib, so the program needs an rpath to its
folder. Add -Wl,-rpath,<folder> to CGO_LDFLAGS. If macOS blocks a library you downloaded with a
browser, remove the quarantine attribute:
xattr -d com.apple.quarantine /opt/nexpdf-ffi-1.1.0-macos-universal/lib/libnexpdf_ffi.dylibThe Linux release libraries are built on Ubuntu 22.04 (glibc 2.35) and can fail to load on older
systems. Build and run on a newer base image, for example golang:1.22-bookworm and
debian:bookworm-slim (Debian 12). There is no musl build, so Alpine images, scratch and other
images without glibc cannot run the program, even with the static library: it removes the
dependency on libnexpdf_ffi, not on glibc.
cgo on Windows uses a MinGW toolchain, while the release's Windows library is built with MSVC. Linking it from Go on Windows is not verified. Build Linux binaries (for example in WSL or a container) or macOS binaries instead.
Check what nexpdf.LicenseStatusJSON() returns in the process that renders:
unlicensed:ActivateLicensewas never called in this process, or it returned an error. Call it at start-up, before you serve requests, and check its error.trial: trial keys always keep the "NexPDF • Trial" watermark.licensed: commercial keys render without a watermark. If you still see one, it is an old render served from a cache.
The key does not list the platform (-6) or application id (-7) you passed. On servers use
platform server and the app id registered for the license, character for character. You can change
both in the dashboard and download a re-signed key.
The machine's clock is earlier than the key's issue date. Fix the clock (NTP) and activate again.
Your plan does not include that module. See Modules and tiers for which
plan unlocks it, and use nexpdf.IsLicensed("xyz") to hide the feature.
In 1.0.0, IsLicensed searched the whole status text, so it could report true for a name that
appeared outside the module list. 1.0.1 decodes the JSON and checks only modules. Update the
module; see the changelog.
In 1.0.0, Open and OpenBytes sent every ZIP-based file to the Office converter. 1.0.1 detects
e-books and comics and converts them. On 1.0.0, call nexpdf.OpenEbook(data) directly.
The PDF uses a standard font (Helvetica, Times, Courier) without embedding it. The default build
bundles the Liberation fonts as substitutes. If nexpdf.HasBundledFonts() returns 0, register
them yourself:
for _, path := range []string{"LiberationSans-Regular.ttf", "LiberationSerif-Regular.ttf", "LiberationMono-Regular.ttf"} {
data, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
nexpdf.RegisterStandardFont(data)
}The page is a scanned image with no text layer. Run OCR first; it adds an invisible text layer that extraction and search then read.
Signing returns the complete signed file. Write those bytes to disk unchanged. Calling doc.Save
afterwards rewrites the file and invalidates the signature. See
Signatures.
With "engine": "auto", Tesseract is used only when the tesseract program is on PATH and has
data for every requested language. Check with tesseract --list-langs, or pass
"engine": "tesseract" to get an error instead of the fallback. In containers, install Tesseract
in the runtime image, not only in the build stage.
The built-in engine reads Latin-script text only. Load a detection model and a recognition model
for the script with nexpdf.OCRLoadModel before calling OCR, and pass matching languages.
nexpdf.OCRModelsJSON() lists what is loaded; the report's engine says neural (<name>) when a
model was used. See OCR.
The file is a dynamic XFA form, which most viewers no longer lay out. Convert it with
XfaToAcroform() or XfaFlatten(); see XFA forms. Scripts in the
form (FormCalc, JavaScript) are not run.
The document was converted as far as possible, but some PDF/A rules still fail; the error lists
their clauses. Run ValidatePDFAJSON(level) to see each failure with its page and object. See
PDF/A and PDF/UA validation.
Close every document with defer doc.Close(). The finalizer frees documents you forget, but the Go
garbage collector does not see native memory, so it may run late. Documents that stay open for a
long time can call TrimMemory() after large operations. See
Compare and optimise.
Still stuck? Check Error handling for the meaning of each error, or the general FAQ.