---
title: "Converting a Word document to PDF while preserving comments"
canonical_url: "https://www.nutrient.io/guides/java/conversion/word-document-to-pdf-including-comments/"
md_url: "https://www.nutrient.io/guides/java/conversion/word-document-to-pdf-including-comments.md"
last_updated: "2026-06-05T20:16:40.258Z"
description: "Learn how to convert Word documents to PDF while preserving all comments and annotations using Nutrient Java SDK with just a few lines of code."
---

# Converting a Word document to PDF while preserving comments

Word review workflows often rely on comments and tracked changes. By default, many DOCX-to-PDF conversions remove this markup.

Use this workflow to:

- Preserve reviewer comments in the output PDF

- Keep tracked-change context for audits and approvals

- Export collaboration history together with final content

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

## Implementing comment preservation

Use Nutrient Java SDK to convert DOCX to PDF and control how comments and tracked changes are rendered.

## Preparing the project

Create a new class named `WordDocumentToPDFIncludingComments` with the following structure:

```java

package io.nutrient.Sample;

```

Import the necessary classes from Nutrient Java SDK:

```java

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

public class WordDocumentToPDFIncludingComments {

```

The `main` method throws a `NutrientException`. Catch it in your application logic for custom error management:

```java

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

```

## Configuring comment preservation

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_with_comments.docx")) {

```

To preserve comments and markups during conversion, set the appropriate `DocumentMarkupMode` enum value.

`DocumentMarkupMode` has four values that control how comments and markups appear in the PDF:

| `DocumentMarkupMode` value        | Changes displayed                                                | Comments converted to annotations |
| --------------------------------- | ---------------------------------------------------------------- | --------------------------------- |
| `DocumentMarkupMode.AllMarkup`    | All markups shown in different colors, underlined/struck through | Yes (default)                     |
| `DocumentMarkupMode.SimpleMarkup` | Document shown as if all changes were accepted                   | Yes                               |
| `DocumentMarkupMode.NoMarkup`     | Document shown as if all changes were accepted                   | No                                |
| `DocumentMarkupMode.Original`     | Document shown as if all changes were rejected                   | No                                |

```java

            document.getSettings().getWordSettings().setMarkupMode(DocumentMarkupMode.AllMarkup);

```

> If your input file doesn’t include comments, conversion still succeeds. `DocumentMarkupMode` only affects files that contain comments or tracked changes.

## Proceeding with the conversion

Export the document to 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 with comments preserved.

## Error handling

The SDK throws `NutrientException` when `Document.open()` or `exportAsPdf()` fails.

Common error scenarios include:

- Input file not found or inaccessible

- Unsupported file format

- Insufficient memory for large documents

- Write permission issues for the output directory

## Conclusion

You now have a DOCX-to-PDF conversion flow that preserves comments and annotations.

## What’s next

- Refer to the [Word-to-PDF conversion](https://www.nutrient.io/guides/java/conversion/word-document-to-pdf.md) guide to learn about basic conversion without comments

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

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

## Related pages

- [Converting a document from XLSX to PDF format](/guides/java/conversion/excel-document-to-pdf.md)
- [Converting a document from Markdown to PDF format](/guides/java/conversion/markdown-to-pdf.md)
- [Converting PDF documents to HTML format for web publishing](/guides/java/conversion/pdf-to-html.md)
- [Nutrient Java SDK conversion guides](/guides/java/conversion.md)
- [Converting PDF documents to Excel format for data analysis](/guides/java/conversion/pdf-to-excel-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 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 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)
- [Converting a document from PDF to DOCX format](/guides/java/conversion/pdf-to-word-document.md)
- [Converting a document from DOCX to PDF format](/guides/java/conversion/word-document-to-pdf.md)

