Open and read Word or PDF file in Swift SDK

Use REST API to open and read documents programmatically in Swift

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

View code snippet

Open and read documents in Swift

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 Swift 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 Swift 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 Swift 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 Swift code.

Programmatically read Word, PDF documents in Swift

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

The following Swift 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 AsposeWordsCloud

let config = Configuration(clientId: "####-####-####-####-####", 
   clientSecret: "##################");
let api = try WordsAPI(configuration: config);
let fileName = "Input.docx";

let requestFileContent = InputStream(url: URL(
   string: try String(contentsOf: fileName, isDirectory: false)))!;
let uploadDocumentRequest = UploadFileRequest(fileContent: requestFileContent, path: fileName);
_ = try api.uploadFile(request: uploadDocumentRequest);

let requestParagraph = ParagraphInsert()
  .setText(text: "Reading and writing to the file in the cloud occurs automatically.");
let insertParagraphRequest = InsertParagraphRequest(name: fileName, paragraph: requestParagraph);
_ = try api.insertParagraph(request: insertParagraphRequest);

let downloadDocumentRequest = DownloadFileRequest(path: fileName);
_ = try api.downloadFile(request: downloadDocumentRequest);
Run code
  
Copy Swift code to the clipboard

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

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

Install Swift library to read documents

You can use Swift package manager and Cocoapods dependency manager to install Aspose.Words Cloud SDK for Swift. Detailed information on installing the package is given in the "Installation and Usage" section.

As an alternative, you can clone Aspose.Words Cloud SDK for Swift 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

Swift 4.2 or newer

Refer to the Repository Documentation to see more 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.