Some test text!

Search
Hamburger Icon

Core / Guides

Get started with Go (C Interface Binding)

Welcome to Apryse. Go (C Interface Binding) for the Apryse SDK is supported on Windows, Linux, macOS. To get started, choose your preferred platform from the tabs below.

New Go (C Interface Binding) project & Windows PDF library integration

C interface binding example
This guide is a demo for using our C interface binding and is not a production version of the Go wrapper. Please visit our Apryse SDK for Go documentation for more information on using our production version of Go.

This guide will help you integrate a free trial of the Apryse SDK with Go using Apryse Headers on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • Go 1.6+

    Make sure Go is part of your path variable.

  • Apryse SDK for Windows

Trial license key required.
The trial of Apryse SDK requires a trial key. A commercial license key is required for use in a production environment. Please fill out our licensing form if you do not have a valid license key.
Keep your license keys confidential.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Setup

  1. Create a project directory inside your go/src/ folder. Call it myApp

    By default it should be at this location:

    C:/Users/User_Name/go/src/
  2. Extract the folder from the .zip file into your project directory

    Copy src/myApp/PDFNetC(64)/Lib/PDFNet.dll into src/myApp/

Integrate Apryse SDK with Go

  1. In your project directory, create a new file called myApp.go

    Add the following code inside:

    package main
    // #cgo CFLAGS: -IPDFNetC64/Headers
    // #cgo LDFLAGS: -LPDFNetC64/Lib -Wl,-rpath,$$ORIGIN/PDFNetC64/Lib -lPDFNetC
    // #include "C/PDF/TRN_PDFNet.h"
    // #include "C/SDF/TRN_SDFDoc.h"
    // #include "C/PDF/TRN_PDFDoc.h"
    // #include "C/PDF/TRN_Page.h"
    // #include "C/Common/TRN_UString.h"
    // #include "C/Common/TRN_Types.h"
    // #include <stdlib.h>
    // #include <stdio.h>
    import "C"
    import (
        "fmt";
        "unsafe"
    )
    func main() {
        // PDFNet must be initialized before calling other Apryse API
        ccp := C.CString("YOUR_DEMO_KEY")
        C.TRN_PDFNetInitialize(ccp)
    
        // Create a new PDFDoc
        var doc *C.TRN_PDFDoc
        doc = (*C.TRN_PDFDoc)(C.malloc(C.size_t(unsafe.Sizeof(*doc))))
        C.TRN_PDFDocCreate(doc)
    
        // Allocate memory for a blank page
        var page *C.TRN_Page
        page = (*C.TRN_Page)(C.malloc(C.size_t(unsafe.Sizeof(*page))))
    
        // Allocate memory for a default rectangle
        var box *C.TRN_Rect
        box = (*C.TRN_Rect)(C.malloc(C.size_t(unsafe.Sizeof(*box))))
    
        // Create the page and add it to the document
        C.TRN_PDFDocPageCreate(*doc, box, page)
        C.TRN_PDFDocPagePushBack(*doc, *page)
    
        // Save the document as a linearized PDF
        var filepath C.TRN_UString
        C.TRN_UStringCreateFromCharString(C.CString("output.pdf"), C.int(10),
        C.e_UString_utf8, &filepath)
        C.TRN_PDFDocSave(*doc, filepath, 0);
        fmt.Println("Hello World!");
    }

    Save and close the file.

    Your folder should look similar to:

    Go folder

  2. In the project folder, run:

    go build

    This will produce a myApp.exe file.

  3. Run the executable file. The executable will produce a pdf with a blank page in a linearized format.

Want to generate your own bindings?

You can generate bindings for Apryse SDK APIs using various methods. It is recommended to use SWIG to generate these bindings. The header files to include can be found in PDFNET_BASE\Headers\ and the library can be found in PDFNET_BASE\Lib\.

Next step

Guides API docsSamples

Get the answers you need: Chat with us