Some test text!

Loading...
Guides
Go

Go & macOS PDF library integration

This guide will help you run PDFTron samples and integrate the PDFTron SDK into Go applications on macOS. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

Run PDFTron SDK in production
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 commercial license key confidential.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Run our macOS Go installer script located on github:
source <(curl -s https://raw.githubusercontent.com/PDFTron/pdftron-go/main/RunSampleMac.sh)
  1. Get your PDFTron trial key.
Loading...

If your OS or Go version is not supported, the installation will fail.

Run the samples

  1. Open a command line console
  2. Change the directory to the samples folder
  3. Run all samples:
cd $HOME/go/src/pdftron/Samples
sh runall_go.sh

You can also enter any individual sample folder to run them separately. For example, here's how to run the AddImageTest sample:

cd $HOME/go/src/pdftron/Samples/AddImageTest/GO
sh RunTest.sh

Integrate into your application

This section will show you how to use our SDK to create a simple PDFTron "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.

  1. Navigate into your /Samples directory and make a new directory called myApp (if it does not exist already). This guide will assume your application is named myApp. For organization, create a new directory inside myApp called GO.

  2. Navigate inside that GO directory and create a new GO file called myApp.go. Open it with your favorite text editor and paste this into it:

package main
import (
    "fmt"
    . "pdftron"
)

func main(){
    PDFNetInitialize()           // PDFNet must be initialized before accessing any PDFTron API
    doc := NewPDFDoc()
    page := doc.PageCreate()     // Start a new page
    doc.PagePushBack(page)       // Add the page to document
    doc.Save("output.pdf", uint(SDFDocE_linearized)); // Save the document as a linearized PDF
    doc.Close()
}

Run your application by executing go run myApp.go. Make sure that your interpreter can find the PDFNetC library. If all goes well, your console should output:

PDFNet is running in demo mode.
Permission: write
Hello World!

Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.

Next step

Guides Samples

Get the answers you need: Support