> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/get-started/go-binding.md).

# Go (C Interface Binding) new project with Apryse SDK PDF library integration

Integrate a free trial of Apryse SDK with Go using Apryse Headers on macOS, Linux, or Windows. Follow step-by-step instructions for setting up and incorporating the SDK into your Go app. Get unlimited

{% hint style="warning" %}
**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](/core/get-started/languages/go.md) documentation for more information on using our production version of Go.
{% endhint %}

This guide will help you integrate a free trial of the Apryse SDK with Go using Apryse Headers on macOS, Linux or Windows in a **new Go app**. (Or see instructions for [incorporation with an existing project](/core/get-started/get-started/go-binding/exist-project.md).) Your free trial includes unlimited trial usage and support from solution engineers.

## Prerequisites

* [Go 1.6+](https://golang.org/dl/)

{% tabs %}
{% tab title="macOS" %}
Make sure Go is installed at `/usr/local/go` and `/usr/local/go/bin`.

* Apryse SDK for macOS

{% code lineNumbers="true" %}

```sh
curl -L -O https://downloads.apryse.com/downloads/PDFNetCMac.zip
unzip PDFNetCMac.zip
```

{% endcode %}

* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

{% hint style="info" %}
**License Key Required**

The trial of Apryse SDK requires a trial license key, which is provided in the box titled "License Key". A commercial license key is required for use in a production environment. Please [contact sales](https://apryse.com/form/contact-sales) to purchase a commercial key or if you need any other license key assistance.
{% endhint %}

{% hint style="warning" %}
**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).
{% endhint %}

## Setup

1. Create a project directory called `myApp`.
2. Extract the `PDFNetCMac` package as a folder into your project directory.

{% code lineNumbers="true" %}

```sh
~/myApp
~/myApp/PDFNetCMac
~/myApp/PDFNetCMac/Headers
~/myApp/PDFNetCMac/Lib
...
```

{% endcode %}

## Integrate Apryse SDK with Go

1. In your project directory, create a new file called `myApp.go`Add the following code inside:Save and close the file.Your folder should look similar to:

{% code lineNumbers="true" %}

```go
package main
// #cgo CFLAGS: -IPDFNetCMac/Headers
// #cgo LDFLAGS: -LPDFNetCMac/Lib -Wl,-rpath,PDFNetCMac/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!");
}
```

{% endcode %}

{% code lineNumbers="true" %}

```sh
~/myApp
~/myApp/PDFNetCMac
~/myApp/PDFNetCMac/Headers
~/myApp/PDFNetCMac/Lib
...
~/myApp/myApp.go
```

{% endcode %}

1. In the project folder, run:This will produce a `myApp` executable file.

{% code lineNumbers="true" %}

```sh
go build
```

{% endcode %}

1. Run the executable file. The executable will produce a pdf with a blank page in a linearized format.
   {% endtab %}

{% tab title="Windows" %}
Make sure Go is part of your `path` variable.

* Apryse SDK for Windows

{% @apryse-download-button/apryse-download-button id="C\_C\_32\_bit\_Java\_32\_bit\_C\_NET\_Core\_core\_windows" title="Windows 32-bit Download" showVersion="true" %}

{% @apryse-download-button/apryse-download-button id="C\_C\_64\_bit\_C\_NET\_Core\_core\_windows" title="Windows 64-bit Download" showVersion="true" %}

* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

{% hint style="info" %}
**License Key Required**

The trial of Apryse SDK requires a trial license key, which is provided in the box titled "License Key". A commercial license key is required for use in a production environment. Please [contact sales](https://apryse.com/form/contact-sales) to purchase a commercial key or if you need any other license key assistance.
{% endhint %}

{% hint style="warning" %}
**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).
{% endhint %}

## Setup

1. Create a project directory inside your `go/src/` folder. Call it `myApp`By default it should be at this location:

{% code lineNumbers="true" %}

```sh
C:/Users/User_Name/go/src/
```

{% endcode %}

1. Extract the folder from the .zip file into your project directoryCopy `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:Save and close the file.Your folder should look similar to:

{% code lineNumbers="true" %}

```go
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!");
}
```

{% endcode %}

![](https://3779731113-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fziw3GiL98Xfj63F3He8h%2Fuploads%2Fgit-blob-ad92b08b92bc470dea94297c94bd5e172d26b74c%2F6a1172f4fa37f23e52a0e0eaabdd7389a26126e8-1086x226.png?alt=media)

1. In the project folder, run:This will produce a myApp.exe file.

{% code lineNumbers="true" %}

```sh
go build
```

{% endcode %}

1. Run the executable file. The executable will produce a pdf with a blank page in a linearized format.
   {% endtab %}

{% tab title="Linux" %}
Make sure Go is installed at \`/usr/local/go\` and \`/usr/local/go/bin\`.

* Apryse SDK for Linux

{% @apryse-download-button/apryse-download-button id="C\_C\_32\_bit\_Java\_32\_bit\_C\_NET\_Core\_core\_linux" title="Linux 32-bit Download" showVersion="false" %}

{% @apryse-download-button/apryse-download-button id="C\_C\_64\_bit\_C\_NET\_Core\_core\_linux" title="Linux 64-bit Download" showVersion="true" %}

* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

{% hint style="info" %}
**License Key Required**

The trial of Apryse SDK requires a trial license key, which is provided in the box titled "License Key". A commercial license key is required for use in a production environment. Please [contact sales](https://apryse.com/form/contact-sales) to purchase a commercial key or if you need any other license key assistance.
{% endhint %}

{% hint style="warning" %}
**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).
{% endhint %}

## Setup

1. Create a project directory called `myApp`.
2. Extract the `PDFNetC64` package as a folder into your project directory.

Your files and folders should look similar to:

{% code lineNumbers="true" %}

```sh
```

{% endcode %}

\~/myApp \~/myApp/PDFNetC64 \~/myApp/PDFNetC64/Headers \~/myApp/PDFNetC64/Lib ...

{% code lineNumbers="true" %}

```
```

{% endcode %}

## Integrate Apryse SDK with Go

1. In your project directory, create a new file called `myApp.go`Add the following code inside:Save and close the file.Your files and folders should look similar to:

{% code lineNumbers="true" %}

```go
package main
// #cgo CFLAGS: -IPDFNetC64/Headers
// #cgo LDFLAGS: -LPDFNetC64/Lib -Wl,-rpath,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!");
}
```

{% endcode %}

{% code lineNumbers="true" %}

```sh
~/myApp
~/myApp/PDFNetCMac
~/myApp/PDFNetCMac/Headers
~/myApp/PDFNetCMac/Lib
...
~/myApp/myApp.go
```

{% endcode %}

1. In the project folder, run:This will produce a `myApp` executable file.

{% code lineNumbers="true" %}

```sh
go build
```

{% endcode %}

1. Run the executable file. The executable will produce a pdf with a blank page in a linearized format.
   {% endtab %}
   {% endtabs %}

{% hint style="info" %}
**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\`.
{% endhint %}

## Next step

<a href="https://docs.apryse.com/core/" class="button primary">Guides</a><a href="https://sdk.apryse.com/api/PDFTronSDK/cpp/index.html" class="button primary">API docs</a><a href="/core/get-started/samples.md" class="button primary">Samples</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/core/get-started/get-started/go-binding.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
