Page Size and Orientation

This guide will demonstrate how to specify the size and orientation of the document you want to create.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniOffice SDK, follow this guide to set up a local development environment.

Clone the project repository

In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unioffice-examples

To get the example navigate to the path document/page-size-and-orientation folder in the unioffice-examples directory.

cd unioffice-examples/document/page-size-and-orientation

How it works

Lines 4-11 import the UniOffice packages and other required dependencies.

The init function in lines 13-20 authenticates your request with your UNIDOC_LICENSE_API_KEY.

In the main function, spanning from lines 22 to 45, a new document is created. Two paragraphs are added to this document, one with a title style and the other with a heading1 style. Additionally, a Run containing text is inserted into each of these paragraphs.

The key part of this example starts at line 41, where the body section of the document is obtained using the BodySection function. Following that, at line 42, you can see how the document’s dimensions and orientation are customized to the user’s preference using the SetPageSizeAndOrientation function. In this case, it configures the document to use A4 paper size and landscape orientation.

Finally, the file is saved at line 44.

Run the code

Run this command to generate a A4 paper with landscape orentation:

go run main.go

Sample output

Paper A4 with Landscape Orentation

Got any Questions?

We're here to help you.