How to Create PDFs from Microsoft Office Documents using Go Language

By Rachmat Hartano | 2021 Nov 23

Sanity Image
Read time

3 min

The Apryse SDK now supports Go Language/GoLang. As a Go developer, you can use Apryse’s GoLang PDF library and document processing functionalities to create, edit, print, convert, and more in your applications on Windows, Linux, and Mac.

This blog post explains how to run a GoLang DOCX to PDF conversion–without requiring a Microsoft Office license or any other plugins!

Download Apryse SDK and GoLang

Copied to clipboard

To start, first download and install the Apryse SDK and GoLang.

  1. Go to the Go PDF Library and select your platform (Windows, Linux, or Mac).
  2. Follow the instructions to download and run the script under the Initial Setup section.

Convert a Microsoft Office document to PDF in Go

Copied to clipboard

After installing the Apryse SDK GoLang package, you can start converting Office documents.

1. First, navigate into the Apryse Go SDK/Samples directory and create a new directory named myApp (if it does not exist already).

Note: This blog assumes your application is called myApp.

2. Next, create a new directory inside myApp called GO (Samples/myApp/GO).

3. Then, create a Go file named officetopdf.go and define the Go package and imports using the following example:

4. Now, create subfolders called input and output and write a simple function to convert DOCX to PDF:

5. For a more flexible Office to PDF conversion, you can also create the function below. This provides status updates on conversion progress and return warnings/errors.

6. Finally, declare the main function in Go:

7. Make sure your interpreter finds the PDFNetC library, then run your application by executing:

go run officetopdf.go

And that’s it! You’ve created a PDF by converting an Office document using the GoLang PDF library.

Next Steps

Copied to clipboard

In this blog, we showed just how easy it is to generate PDFs from Office documents using the new Apryse SDK for Go PDF Library.

For Apryse SDK for Go documentation, sample codes, and other resources, visit the Go PDF library.

And as always, we are here to help; if you have trouble with any of the steps here, or with getting started, feel free to contact us. We're happy to answer any questions about the Apryse SDK Go Language package.

Sanity Image

Rachmat Hartano

Share this post

email
linkedIn
twitter