---
title: "Process documents with Document Engine and Rust"
canonical_url: "https://www.nutrient.io/sdk/document-engine/getting-started/rust/"
md_url: "https://www.nutrient.io/sdk/document-engine/getting-started/rust.md"
last_updated: "2026-05-20T19:49:34.959Z"
description: "Master PDF document processing with Document Engine. Follow our guide for step-by-step instructions on how to process and merge PDF documents using HTTP API and Rust."
---

# Process documents with Document Engine and Rust

This guide walks you through the steps necessary to start Document Engine. It also shows you how to use it to process documents. By the end, you’ll be able to merge two PDF documents into one using Document Engine’s HTTP API from Rust.

## Requirements

Document Engine is compatible with a range of platforms. Below is the list of supported operating systems.

- **macOS**:
  - Ventura
  - Monterey
  - Mojave
  - Catalina
  - Big Sur

- **Linux**:
  - Ubuntu, Fedora, Debian, and CentOS
  - Ubuntu and Debian derivatives (such as Kubuntu, Xubuntu) are also supported

**Processor requirements**:

- 64-bit Intel (x86_64) processors

- ARM (AArch64) processors

**Minimum system requirements**:

- At least 4GB of RAM, regardless of the operating system

## Installing Docker

Document Engine is distributed as a Docker container. To run it on your computer, you need to install a Docker runtime distribution for your operating system.

### macOS

Install and start Docker Desktop for Mac. For detailed instructions, refer to the [Docker website](https://docs.docker.com/docker-for-mac/install/).

### Windows

Install and start Docker Desktop for Windows. For detailed instructions, refer to the [Docker website](https://docs.docker.com/docker-for-windows/install/).

> Document Engine runs as a Linux container. If you’re using Docker Desktop for Windows, ensure it’s configured to work with Linux containers. For detailed steps, refer to the **How do I switch between Windows and Linux containers?** section in the [Docker documentation](https://docs.docker.com/desktop/setup/install/windows-install/). Users with Docker already set up might need to switch from Windows containers to Linux containers for compatibility.

### Linux

Install and start Docker Engine. For detailed instructions on how to install Docker Engine for your Linux distribution, refer to the [Docker website](https://docs.docker.com/engine/install/#server).

Once you finish installing Docker Engine, follow the [instructions](https://docs.docker.com/compose/install/#install-compose-on-linux-systems) to install Docker Compose.








## Starting Document Engine

To start Document Engine, follow the steps below.

1. Open your terminal emulator.

   ### macOS

   Use the terminal emulator integrated with your code editor or IDE. Alternatively, you can use `Terminal.app` or [iTerm2](https://iterm2.com/).

   ### Windows

   Use your code editor’s integrated terminal or [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell?view=powershell-7.5).

   ### Linux

   Use the terminal emulator integrated with your code editor or IDE, or the one bundled with your desktop environment.

2. Run the following command to start the Document Engine container:

```sh

docker run --rm -t -p 5000:5000 -e API_AUTH_TOKEN=secret pspdfkit/document-engine:1.15.0

```

This command may take some time to complete depending on your internet connection speed, as it needs to pull the Docker image. You’ll know that Document Engine is successfully running when you see a message similar to the following in your terminal:

```

[info]  2024-02-05 18:56:45.286  Running Document Engine version 1.15.0

```

Document Engine is now up and running!




## Installing Rust

The interaction with Document Engine happens through its HTTP API. Documents and commands are sent in API request calls, and the resulting files are received in response. API calls are invoked from the Rust code, so you need to install Rust.

To install Rust:

1. Follow the instructions for your operating system in Rust’s [installation guide](https://www.rust-lang.org/tools/install).

2. Go to any directory in your system using your terminal. Create a new directory called `merging-pdfs` and go the newly created directory:

   ```

   mkdir merging-pdfs
   cd merging-pdfs
   ```

3. Create a new `cargo` project:

   ```

   cargo new merging-pdfs-pspdfkit
   ```

4. Run the project with the `cargo run` command.

## Merging PDFs with Rust

If you don’t have any sample documents, download and use these files: [cover.pdf](https://www.nutrient.io/assets/nutrient-media/files/cover.pdf) and [document.pdf](https://www.nutrient.io/assets/nutrient-media/files/document.pdf).

Paste the following content into the `Cargo.toml` file in the `merging-pdfs-pspdfkit` project directory:

```

[dependencies]
tokio = { version = "1.23.0", features = ["full"] }
reqwest = { version = "0.11.13", features = ["json", "multipart"] }
serde_json = "1.0.91"

```

Next, replace `/path/to/cover.pdf` on line 24 and `/path/to/document.pdf` on line 30 with the actual paths to the example documents on your machine. Then, replace the contents of the `src/main.rs` file with this code:

```src/main.rs

use reqwest::Result;
use std::borrow::Cow;
use std::fs;
use std::fs::File;
use std::io::Write;

#[tokio::main]

async fn main() -> Result<()> {
  // Multipart Request
  let body = serde_json::json!({
    "parts": [
      {
        "file": "cover"
      },
      {
        "file": "document"
      }
    ],
    "output": {
      "type": "pdf"
    }
  });

  let cover = fs::read("src/cover.pdf").unwrap();
  let cover_part = reqwest::multipart::Part::bytes(cover).file_name("cover.pdf").mime_str("application/pdf").unwrap();

  let document = fs::read("src/document.pdf").unwrap();
  let document_part = reqwest::multipart::Part::bytes(document).file_name("document.pdf").mime_str("application/pdf").unwrap();

  let instructions = serde_json::to_vec(&body).unwrap();
  let instructions_bytes = Cow::from(instructions);
  let instructions_part = reqwest::multipart::Part::bytes(instructions_bytes);

  let form = reqwest::multipart::Form::new().part("cover", cover_part).part("document", document_part).part("instructions", instructions_part);

  let client = reqwest::Client::new();
  let res = client.post("http://localhost:5000/api/build").header("Authorization", "Token token=secret").multipart(form).send().await?;

  let mut result_file = File::create("result.pdf").expect("Error creating file");

  result_file.write_all(&res.bytes().await.unwrap()).expect("Error writing to file");

  Ok(())
}

```

Most of this code deals with creating and sending a [multipart request](https://www.nutrient.io/blog/a-brief-tour-of-multipart-requests/) containing files and `instructions` to Document Engine’s `/api/build` endpoint using Rust’s `reqwest` crate.

To run the code, ensure you’re in the `merging-pdfs` directory and type the following command in your terminal:

```

cargo run

```

To learn more about the various actions you can apply to PDFs using Document Engine, go to Document Engine’s [API Reference](https://www.nutrient.io/api/reference/document-engine/upstream/#tag/Build-API).
---

## Related pages

- [Process documents with Document Engine and curl](/sdk/document-engine/getting-started/curl.md)
- [Document Engine with Docker](/sdk/document-engine/getting-started/docker-deployment-react-frontend.md)
- [Document Engine with Docker and EJS templates](/sdk/document-engine/getting-started/docker-deployment-ejs-templates.md)
- [Process documents with Document Engine and Golang](/sdk/document-engine/getting-started/golang.md)
- [Getting started with Document Engine](/sdk/document-engine/getting-started.md)
- [Process documents with Document Engine and Python](/sdk/document-engine/getting-started/python.md)
- [Process documents with Document Engine and PHP](/sdk/document-engine/getting-started/php.md)

