Installation and first applications

Introduction

As UniPDF is a SDK library for Go, there is no traditional installation.  The releases are available on our GitHub repository: https://github.com/unidoc/unipdf.  New releases are tagged and can be obtained via Go Modules.  For an overview of past releases, see: https://github.com/unidoc/unipdf/releases

Importing UniPDF into your project.

To import UniPDF into your project, simply do

go get github.com/unidoc/unipdf/v3

and it will fetch the newest version and place into your project´s go.mod file.  Then you are able to import the UniPDF packages readily.

Starting from an Example

The easiest way to get started with UniPDF is typically to find an example that is close to the use case you want to achieve and then adjusting it to your own requirements.  You can find all our example by category in our GitHub unipdf-examples repository: https://github.com/unidoc/unipdf-examples

If you want to get started superfast, you can also try our Playground: https://play.unidoc.io/ The playground enables you to easily test UniDoc libraries, including UniPDF, and play with code and see the result immediately in action.  Also easy to save and share the code or even embed on a website.  For example, when reaching out to our Support, it can be handy to have a Play link available to share, so our support can quickly triage the request.

Creating a Hello World PDF

Let's start with the most simple case we can think of, a single page PDF with the text "Hello World".  It does not get much more simple than that.  For this we use the creator package which can be used to create new PDF content or add content on top of existing PDF files.

Note that the example is shown above with the embedded playground, so you can see both the code, and the output file at the bottom.  Or you can open it in the playground and view the code and see the output file simultaneously.  Also easy to modify and run on the go and see the output immediately.

Creating a Page with More Paragraphs

OK.  That was easy.  Let's go one step further and add more paragraphs and a few more formatting options.  To do this we can simply create more Paragraphs and Draw to the creator, it handles the positioning automatically unless the components are set to an absolute position.  So here it goes:

This happens to be the default example when starting on the UniDoc Playground: https://play.unidoc.io/

Creating a Full Report

That was nice and easy. But in real applications we typically need something more powerful.  Next we look at a full reporting example.  For this we use one of our examples on our GitHub unipdf-examples repository:  https://github.com/unidoc/unipdf-examples/blob/master/report/pdf_report.go which is a pretty fully fledged report and easy to add more sections and such.