Wrap Text Around Image
This guide will demonstrate how to adjust images within the text of a document.
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/image-text-wrap
folder in the unioffice-examples directory.
cd unioffice-examples/document/image-text-wrap/
How it works
Lines 4-15
import the UniOffice packages and other required dependencies.
The init function in lines 17-24
authenticates your request with your UNIDOC_LICENSE_API_KEY
.
In the main function in lines 28-145
, the code follows a distinct pattern. In lines 32-35
, an image is directly accessed, while in lines 36-43
, a file is opened and subsequently converted into an image. These images are then incorporated into the document, and references for future use are acquired in lines 45-52
.
Moving forward to lines 54-66
, an anchored image is introduced with meticulous adjustments to measurements and alignments. Subsequently, a loop is executed to repeat the text stored in the lorem
variable 40 times, and both images are inserted at various indices (controlled by the i
variable), altering their positioning and alignments, between lines 68 and 147
.
Ultimately, the code concludes by saving the file.
Run the code
Run this command to create a new document with many images added between the text.
go run main.go