---
title: "Converting a document from DOCX to PDF format | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/conversion/word-document-to-pdf/"
md_url: "https://www.nutrient.io/guides/java/conversion/word-document-to-pdf.md"
last_updated: "2026-06-09T10:32:42.836Z"
description: "Converting a document from DOCX to PDF format using Nutrient Java SDK."
---

# Converting a document from DOCX to PDF format

Convert Word documents to PDF when you need fixed output for sharing, storage, or compliance. This helps you:

- Preserve document layout and styling

- Avoid formatting differences across devices or apps

- Create stable files for distribution and archival

- Keep the original appearance of critical records

[Download sample](https://www.nutrient.io/downloads/samples/java/word-document-to-pdf.zip)

## Use the Java SDK for conversion

Use the Java SDK to convert DOCX files to PDF directly in your app workflow.

## Preparing the project

Define a package and create a class for this conversion flow:

```java

package io.nutrient.Sample;

```

Import Nutrient Java SDK classes. Prefer explicit imports for the classes you use:

```java

import io.nutrient.sdk.Document;
import io.nutrient.sdk.exceptions.NutrientException;

public class WordDocumentToPDF {

```

Create a `main` method and declare `NutrientException`:

```java

    public static void main(String[] args) throws NutrientException {

```

Then add the SDK-specific conversion logic.

## Proceeding with the conversion

This guide uses the `Document` class. Initialize it with a [try-with-resources statement](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) to close resources correctly.

Open source files by file path or stream. This example uses a file path:

```java

        try (Document document = Document.open("input.docx")) {

```

After loading the file, call SDK methods on the document instance. For the full API surface, refer to the [API reference](https://www.nutrient.io/api/java-sdk/).

Export the document as PDF. Write to a file path or stream. This example writes `output.pdf` to the working directory:

```java

            document.exportAsPdf("output.pdf");
        }
    }
}

```

You now have a PDF file.

## Error handling

The SDK throws `NutrientException` when conversion fails. Handle this exception in your app for custom logging, retries, or fallback logic.

## Conclusion

You now have a complete DOCX-to-PDF conversion flow in Java. Download the [sample package](https://www.nutrient.io/downloads/samples/java/word-document-to-pdf.zip) to run this example as-is.

## What’s next

- Refer to the [Word to PDF with comments](https://www.nutrient.io/guides/java/conversion/word-document-to-pdf-including-comments.md) guide to learn how to preserve comments and annotations during conversion

- Refer to the [Word to PDF/UA](https://www.nutrient.io/guides/java/conversion/word-document-to-pdf-ua.md) guide to create accessible PDF documents

- Refer to the [Excel to PDF](https://www.nutrient.io/guides/java/conversion/excel-document-to-pdf.md) guide to convert spreadsheet documents
---

## Related pages

- [Converting HTML to PDF](/guides/java/conversion/html-to-pdf.md)
- [Converting CAD files to PDF](/guides/java/conversion/cad-to-pdf.md)
- [Converting email files to PDF](/guides/java/conversion/email-to-pdf.md)
- [Converting a document from XLSX to PDF format](/guides/java/conversion/excel-document-to-pdf.md)
- [Nutrient Java SDK conversion guides](/guides/java/conversion.md)
- [Converting a document from Markdown to PDF format](/guides/java/conversion/markdown-to-pdf.md)
- [Converting PDF documents to Excel format for data analysis](/guides/java/conversion/pdf-to-excel-document.md)
- [Converting PDF documents to HTML format for web publishing](/guides/java/conversion/pdf-to-html.md)
- [Converting PDF documents to image format](/guides/java/conversion/pdf-to-image.md)
- [Converting PDF documents to PDF/A format](/guides/java/conversion/pdf-to-pdf-a.md)
- [Converting PDF documents to PowerPoint presentations](/guides/java/conversion/pdf-to-powerpoint-document.md)
- [Converting PDF documents to Markdown format](/guides/java/conversion/pdf-to-markdown.md)
- [Converting PDF documents to PDF/UA format](/guides/java/conversion/pdf-to-pdf-ua.md)
- [Converting a document from PDF to DOCX format](/guides/java/conversion/pdf-to-word-document.md)
- [Converting a Word document to PDF while preserving comments](/guides/java/conversion/word-document-to-pdf-including-comments.md)
- [Converting a document from PPTX to PDF format](/guides/java/conversion/powerpoint-document-to-pdf.md)
- [Converting a document from DOCX to PDF/UA format](/guides/java/conversion/word-document-to-pdf-ua.md)

