Skip to Content
NexPDF

Running without a license key

What NexPDF for Go does before a key is activated, how the watermark works, and how to evaluate every module with a trial key.

English

You do not need a key to add the module, write code against it or run it. Until nexpdf.ActivateLicense succeeds, the SDK runs in view-only mode:

  • the viewer module works: open, render, extract text, search and read document information;
  • pages rendered with RenderPagePNG carry a "NexPDF • Unlicensed" watermark;
  • every call that needs another module returns a *nexpdf.Error.
package main

import (
	"fmt"
	"log"
	"os"

	nexpdf "github.com/nexdevit/nexpdf-go"
)

func main() {
	doc, err := nexpdf.Open("contract.pdf") // no ActivateLicense call
	if err != nil {
		log.Fatal(err)
	}
	defer doc.Close()

	status, _ := nexpdf.LicenseStatusJSON()
	fmt.Println(status) // {"state":"unlicensed","modules":["viewer"],"watermark":true}

	png, err := doc.RenderPagePNG(0, 144) // works, with the watermark
	if err != nil {
		log.Fatal(err)
	}
	os.WriteFile("page1.png", png, 0o644)

	text, _ := doc.ExtractPageText(0) // works
	fmt.Println(text)

	if _, err := doc.RotatePage(0, 90); err != nil { // needs the editor module
		fmt.Println(err) // nexpdf: no license activated: 'editor' requires a NexPDF license key
	}
}

What works without a key

AreaFunctions and methods
Opening and savingOpen, OpenBytes, OpenBytesWithPassword, OpenImage, Save, SaveBytes, SaveLinearized, Copy, InsertImagePages
RenderingPageCount, RenderPagePNG, RenderThumbPNG, PageWidth, PageHeight, PageViewJSON, SetOverprint (RenderPagePNG output is watermarked)
TextExtractPageText, ExtractMarkdown, PageBlocksJSON, SearchJSON, AskDocument
Reading structureMetadataJSON, OutlinesJSON, PageLabelsJSON, LayersJSON, SetLayerVisible, AttachmentsJSON, AttachmentData
Reading annotationsAnnotationsJSON, MeasurementsJSON
SecuritySecurityJSON
Comparing and memoryCompareJSON, CompareOverlayPNG, CompareTextJSON, CompareAnnotate, TrimMemory, MemoryUsageBytes
LibraryVersion, LicenseStatusJSON, IsLicensed, HasBundledFonts, RegisterStandardFont

Everything else (annotating, filling forms, editing, encrypting, redacting, signing, converting, OCR and PDF/A) needs a key that includes the module. Open and OpenBytes also need the conversion module when the input is a Word, Excel, PowerPoint or e-book file. The API reference names the module of every method.

Check the mode at run time

LicenseStatusJSON returns the state as JSON. Decode the fields you need:

var status struct {
	State    string   `json:"state"`
	Modules  []string `json:"modules"`
	DaysLeft *int     `json:"days_left"`
}
s, err := nexpdf.LicenseStatusJSON()
if err != nil {
	log.Fatal(err)
}
json.Unmarshal([]byte(s), &status)

switch status.State {
case "unlicensed":
	fmt.Println("view-only mode, pages are watermarked")
case "trial":
	if status.DaysLeft != nil {
		fmt.Printf("trial, %d days left\n", *status.DaysLeft)
	}
default:
	fmt.Println("licensed for", strings.Join(status.Modules, ", "))
}

Use nexpdf.IsLicensed("redaction") to hide features your key does not unlock instead of waiting for the error.

Evaluate with a trial key

A trial key unlocks every module so you can try annotations, signing, redaction and the rest. It keeps a "NexPDF • Trial" watermark on rendered pages, and ActivateLicense returns 1 instead of 2. Trial keys last 30 days; ask for one from the pricing page and activate it exactly like a commercial key; see License.

Do not ship view-only or trial builds

The watermark is drawn on the pixels of rendered pages only; documents you save are not changed. Even so, view-only and trial modes are for development and evaluation. Production apps need a commercial key for the modules they use. See Licensing and the modules per plan.

On this page