Open and read Word or PDF file in Go SDK

Use REST API to open and read documents programmatically in Go

Easily open Word, PDF documents with just a few lines of Go code. Our Go library will provide you with everything you need to access document content programmatically.

View code snippet

Open and read documents in Go

If you want to open a text file and work with the data in plain-text format, you can do it using the most basic features of the Go language and operating system. As for reading office documents, presented in a wide variety of file formats (DOCX, DOC, PDF, RTF, ODT, HTML, etc.), this task is more difficult to solve, since such documents are described by complex tree-like data structures within the DOM model.

Our Go library is a cloud-based solution that will allow you to open documents in any office and web format. This distributed approach gives you flexibility in software development using Go language, as all resource-intensive document processing will take place on Aspose servers. All you need is to get private keys to access Cloud API in Go code.

Programmatically read Word, PDF documents in Go

You can iterate over document elements, or you can search for specific elements in the DOM tree. We provide a wide range of Go functions both for working with the structure of the document and with the data contained in the document nodes.

The following Go code example will help you quickly figure out how to load a document and perform some actions on it.

Upload a document you want to access
Run code
import (
    "os"
    "github.com/aspose-words-cloud/aspose-words-cloud-go/dev/api/models"
)

config, _ := models.NewConfiguration("config.json")
wordsApi, ctx, _ := api.CreateWordsApi(config)
fileName:= "Input.docx"

requestFileContent, _ := os.Open(ReadFile(t, fileName))
uploadDocumentRequestOptions := map[string]interface{}{}
uploadDocumentRequest := &models.UploadFileRequest{
    FileContent: requestFileContent,
    Path: ToStringPointer(fileName),
    Optionals: uploadDocumentRequestOptions,
}
_, _, _ = wordsApi.UploadFile(ctx, uploadDocumentRequest)

requestParagraph := models.ParagraphInsert{
    Text: ToStringPointer("Reading and writing to the file in the cloud occurs automatically."),
}
insertParagraphRequestOptions := map[string]interface{}{}
insertParagraphRequest := &models.InsertParagraphRequest{
    Name: ToStringPointer(fileName),
    Paragraph: &requestParagraph,
    Optionals: insertParagraphRequestOptions,
}
_, _, _ = wordsApi.InsertParagraph(ctx, insertParagraphRequest)

downloadDocumentRequestOptions := map[string]interface{}{}
downloadDocumentRequest := &models.DownloadFileRequest{
    Path: ToStringPointer(fileName),
    Optionals: downloadDocumentRequestOptions,
}
_, _ = wordsApi.DownloadFile(ctx, downloadDocumentRequest)
Run code
  
Copy Go code to the clipboard

How to open a document Word, PDF, JPG Go REST API

  1. Install Aspose.Words Cloud for Go
  2. Add a library reference (import the library) to your Go project
  3. Read a document

Install Go library to read documents

Run go get -v github.com/aspose-words-cloud/aspose-words-cloud-go/2007/api to install Aspose.Words Cloud SDK for Go. You can get a lot of useful information about other installation methods from the "How to use SDK" section.

Clone Aspose.Words Cloud SDK for Go source code from GitHub and use it in your project. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

Refer to the Repository Documentation to see the details.

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2025. All Rights Reserved.