---
title: "Save PDF to server on Android | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/android/save-a-document/to-remote-server/"
md_url: "https://www.nutrient.io/guides/android/save-a-document/to-remote-server.md"
last_updated: "2026-05-30T02:20:01.173Z"
description: "Learn to upload PDF documents from your Android app to a remote server using OkHttp. Streamline your document management with efficient code examples in Kotlin and Java."
---

# Save PDFs to a remote server on Android

If you already have a document saved locally and you want to commit it to a remote server once a user is done editing it, you can achieve this by uploading the contents of the document. Below is an example that uses [`OkHttp`](https://square.github.io/okhttp/). We chose to use it because it’s a common dependency most projects already have, but you’re by no means required to use it if you have a different networking setup already in place:

### KOTLIN

```kotlin

val dataProvider = activity.requirePdfFragment().document?.documentSource?.dataProvider?: return
val data = dataProvider.read(dataProvider.size, 0)
val requestBody = data.toRequestBody("application/pdf".toMediaType())
val request = Request.Builder().url("http://127.0.0.1:12345").post(requestBody).build()
val client = OkHttpClient()
val response = client.newCall(request).execute()

```

### JAVA

```java

final PdfDocument document = activity.requirePdfFragment().getDocument();
if (document == null) return;
final DataProvider dataProvider = document.getDocumentSource().getDataProvider();
if (dataProvider == null) return;

final byte[] data = dataProvider.read(dataProvider.getSize(), 0);
final RequestBody requestBody = RequestBody.create(data, MediaType.parse("application/pdf"));
final Request request = new Request.Builder().url("http://127.0.0.1:12345").post(requestBody).build();
final OkHttpClient client = new OkHttpClient();
final Response response = client.newCall(request).execute();

```
---

## Related pages

- [Auto saving PDF files on Android](/guides/android/features/document-checkpointing.md)
- [Incremental PDF saving on Android](/guides/android/faq/growing-pdf-file-size.md)
- [Save PDFs to Document Engine on Android](/guides/android/save-a-document/to-document-engine.md)
- [How to save documents as PDFs on Android](/guides/android/save-a-document/save-as.md)
- [Saving a PDF file on Android](/guides/android/save-a-document.md)
- [Save PDFs to a custom data provider on Android](/guides/android/save-a-document/to-custom-data-provider.md)
- [Save PDFs to local storage on Android](/guides/android/save-a-document/to-local-storage.md)

