Some test text!
Core / Guides
This guide will help you integrate a free trial of the Apryse SDK with Go using Apryse Headers on macOS, Linux or Windows in an existing Go app to create a new PDFDoc. (Or see instructions for creating a new Go app .)
macOS
Linux
Windows
Apryse collects some data regarding your usage of the SDK for product improvement.
If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.
Start by adding these lines to the beginning of your .go
file:
// #cgo CFLAGS: -Ipath/to/your/download/PDFNetCMac/Headers
// #cgo LDFLAGS: -Lpath/to/your/download/PDFNetCMac/Lib -Wl,-rpath,PDFNetC64/Lib -lPDFNetC
Before calling other Apryse API, you must initialize PDFNet. The PDFNet initialize header is found in C/PDF/TRN_PDFNet.h
and the PDFDoc header is found in C/PDF/TRN_PDFDoc.h
. Include both at the beginning of your .go
file:
// #include "C/PDF/TRN_PDFNet.h"
// #include "C/PDF/TRN_PDFDoc.h"
Also import the unsafe
library:
import (
"unsafe"
)
Then initialize PDFNet by calling these lines:
// Declare a license key and convert it to CString
ccp := C.CString("Insert commercial license key here after purchase");
// Initialize PDFNet
C.TRN_PDFNetInitialize(ccp);
// Free the memory used for the license key
C.free(unsafe.Pointer(ccp));
To create a new PDFDoc in Go, you must allocate memory for it and handle freeing the memory associated with it.
You can follow these steps to instantiate a PDFDoc:
// Declare a pointer for the PDFDoc.
var doc *C.TRN_PDFDoc;
// Get the size of the type using the pointer and allocate that amount of memory using malloc,
// then typecast void pointer returned by malloc to the required type explicitly.
doc = (*C.TRN_PDFDoc)(C.malloc(C.size_t(unsafe.Sizeof(*doc))));
// Call `TRN_PDFDocCreate` on the pointer to create the PDFDoc.
C.TRN_PDFDocCreate(doc);
To deallocate the memory used by the PDFDoc, you can use C.free
:
C.free(doc);
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales