> 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/exist-project.md).

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

Learn how to integrate a free trial of Apryse SDK with Go using Apryse Headers on macOS, Linux, or Windows. Follow step-by-step instructions to create a new PDFDoc in your existing Go app. The Apryse

{% 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 an **existing Go app** to create a new PDFDoc. (Or see instructions for [creating a new Go app](/core/get-started/get-started/go-binding.md).)

## 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

{% @apryse-download-button/apryse-download-button id="Objective\_C\_SDK\_core\_mac" title="Download for macOS" showVersion="true" %}
{% 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" %}
{% 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" %}
{% endtab %}
{% endtabs %}

* 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 %}

## Integrate Apryse SDK with Go

Start by adding these lines to the beginning of your `.go` file:

{% tabs %}
{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
// #cgo CFLAGS: -Ipath/to/your/download/PDFNetCMac/Headers
// #cgo LDFLAGS: -Lpath/to/your/download/PDFNetCMac/Lib -Wl,-rpath,PDFNetC64/Lib -lPDFNetC
```

{% endcode %}
{% endtab %}
{% endtabs %}

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:

{% tabs %}
{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
// #include "C/PDF/TRN_PDFNet.h"
// #include "C/PDF/TRN_PDFDoc.h"
```

{% endcode %}
{% endtab %}
{% endtabs %}

Also import the `unsafe` library:

{% tabs %}
{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
import (
    "unsafe"
)
```

{% endcode %}
{% endtab %}
{% endtabs %}

Then initialize PDFNet by calling these lines:

<pre class="language-go" data-line-numbers><code class="lang-go">// Declare a license key and convert it to CString
ccp := C.CString("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
// Initialize PDFNet
C.TRN_PDFNetInitialize(ccp);
// Free the memory used for the license key
C.free(unsafe.Pointer(ccp));
</code></pre>

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:

{% tabs %}
{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
// 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);
```

{% endcode %}
{% endtab %}
{% endtabs %}

To deallocate the memory used by the PDFDoc, you can use `C.free`:

{% tabs %}
{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
C.free(doc);
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 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/exist-project.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.
