Today, we’re excited to announce support for the Go Language/GoLang. This means Go Developers can now easily add PDFTron’s leading, high-quality document creation, editing, printing, conversion, and much, much more to their applications on Windows, Linux, and Mac.

Given Go’s recent rise in popularity, we knew adding support for a GoLang PDF library would greatly benefit developers when working with PDFs or any other digital documents. The PDFTron SDK, also top choice for commercial PDF SDK, supports functionality for more than 30 file formats.

For detailed guides, sample codes, and other resources, check out our PDFTron SDK Go documentation.

What’s Supported with PDFTron SDK for GoLang

The Go PDF library package supports all of the PDFTron SDK’s rich document processing functionalities, including:

How to Get Started with PDFTron SDK and GoLang

Start using the PDFTron SDK and GoLang with just a few lines of code.

  1. Choose the platform from the Go PDF Library.
  2. Follow the instruction to download and run the script under the Initial Setup section.

Once installed, you’re good to go, with dozens of unique document processing capabilities at your fingertips. For example, you can generate PDFs from Office documents. You can also create a PDF from scratch, and perform many other document processing actions to optimize and customize your document to taste. For instance:

How to Create a Linearized PDF Document with PDFTron Go SDK

This example demonstrates how to create a PDF document containing a blank page and linearize it for fast web view using the PDFTron Go SDK.

Create a linearized.go file under go/src/pdftron/Samples/demo folder:

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

func main()
{
 // PDFNet must be initialized before accessing any PDFTron API    
PDFNetInitialize("demo:1630436733976:78fdd6c00300000000222fa9b8dab35afb9cc6a740157513bd83ca26dd")          
    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()
}

How to Convert PDF to DOCX with PDFTron Go SDK

The next example demonstrates how to convert PDF documents to DOCX. You must download PDFTron’s PDF2Word Module to enable PDF to DOCX conversion.

Depending on your platform, extract the module above and put it in:

go/src/pdftron/PDFNetC/Lib/Linux

OR

go/src/pdftron/PDFNetC/Lib/Windows

Next, create a pdf2docx.go file under go/src/pdftron/Samples/demo folder:

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

func main() {
 // PDFNet must be initialized before accessing any PDFTron API    
PDFNetInitialize("demo:1630436733976:78fdd6c00300000000222fa9b8dab35afb9cc6a740157513bd83ca26dd")  

// Point the PDFNet Resource Path to where PDFNetC/Lib is located at.
PDFNetAddResourceSearchPath("../../PDFNetC/Lib/")
if !PDF2WordModuleIsModuleAvailable() {
	fmt.Println("")
	fmt.Println("Unable to run the sample: PDFTron SDK Word module not available.")
	fmt.Println("---------------------------------------------------------------")
	fmt.Println("The Word module is an optional add-on, available for download")
	fmt.Println( “at https://www.pdftron.com/documentation/core/info/modules/#pdf2word-module")
	fmt.Println("")
	return
}     
fmt.Println("Converting PDF to Word")
infile := "./input.pdf"
outfile := "./output.docx"
ConvertToWord(infile, outfile)
fmt.Println("Result saved in output.docx")
}

Wrap Up

Whether you are converting or editing PDFs using GoLang, we’ve now got you covered. Our Go Language package supports all of the PDFTron SDK’s rich document processing features, such as converting Office documents to PDF, while retaining the same style and formatting as the original document no matter your platform.

We hope you are as excited as we are about this new GoLang support. Feel free to contact us with any questions or suggestions!