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

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:

package io.nutrient.Sample;

Import the necessary classes from Nutrient Java SDK:

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:

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(opens in a new tab) to close resources correctly.

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

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 valueChanges displayedComments converted to annotations
DocumentMarkupMode.AllMarkupAll markups shown in different colors, underlined/struck throughYes (default)
DocumentMarkupMode.SimpleMarkupDocument shown as if all changes were acceptedYes
DocumentMarkupMode.NoMarkupDocument shown as if all changes were acceptedNo
DocumentMarkupMode.OriginalDocument shown as if all changes were rejectedNo
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:

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