Some test text!
PDFTron’s PDF SDK ships with a powerful C API for bringing accurate, reliable, and fast document reading, writing, editing, and printing capabilities to commercial applications. Using the PDFTron C headers, you can bind the PDFTron C library to other languages not directly supported by PDFTron. You can see a list of supported languages and frameworks here.
The PDFTron SDK download package contains headers detailing the methods available in the C API which can be used as an interface for various other languages, including but not limited to Go, Rust and more. You can find these headers in the
PDFNetC(64)/Headers/C directory. Importing these headers into your project will allow you to use the PDFTron API, but the method of importing the library differs from language to language.
Responsibility for creating or deallocating certain variables or chunks of memory depends on the function. The best way to learn about this is to look at:
All of these are contained in the
Headers folder of the package.
The following example shows how to include these headers with Golang and use them to create a new PDFDoc. Start by adding these lines to the beginning of your
// #cgo CFLAGS: -Ipath/to/your/download/PDFNetC64/Headers // #cgo LDFLAGS: -Lpath/to/your/download/PDFNetC64/Lib -Wl,-rpath,$$ORIGIN/PDFNetC64/Lib -lPDFNetC
Before calling other PDFTron 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
// #include "C/PDF/TRN_PDFNet.h" // #include "C/PDF/TRN_PDFDoc.h"
Also import the
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 Golang, 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
Get the answers you need: Support
Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.
Select a platform to get started with your free trial.
Unlimited usage. No email address required.
PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital PartnersLearn more