Merge Documents
This guide demonstrates the process of merging two different documents into a single one.
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/merge-documents folder in the unioffice-examples directory.
cd unioffice-examples/document/merge-documents
The repository holds two DOCX files and the example code, “main.go,” which is utilized in this demonstration.
How it works
Lines 6-12 import the UniOffice packages and other required dependencies.
The init function in lines 14-21 authenticates your request with your UNIDOC_LICENSE_API_KEY.
In the main function, spanning lines 23 to 41, the process begins by opening both files. Subsequently, after opening the initial document and adding a new paragraph, a page break is inserted into the paragraph using the AddPageBreak() function at line 34. To complete the operation, the Append(doc1) function on line 36 is employed to successfully merge both documents, resulting in a successful consolidation, which is then saved as the final output.
Run the code
Run this command to do the mail merge:
go run main.go
Sample output

