Converting a document from DOCX to PDF/UA format
Convert Word documents to PDF/UA when you need fixed output and accessibility compliance. PDF/UA (ISO 14289) defines requirements for accessible PDF files, including support for assistive technologies such as screen readers.
This workflow helps you:
- Preserve document layout and styling
- Avoid formatting differences across viewers
- Generate accessible output for compliance use cases
- Keep document conversion inside your app
Use the Java SDK for conversion
Use the Java SDK to convert DOCX files to PDF/UA directly in your document workflow.
Preparing the project
Define a package and create a class for this conversion flow:
package io.nutrient.Sample;Import Nutrient Java SDK classes. Prefer explicit imports for the classes you use:
import io.nutrient.sdk.Document;import io.nutrient.sdk.editors.WordEditor;import io.nutrient.sdk.enums.PdfConformance;import io.nutrient.sdk.exceptions.NutrientException;import io.nutrient.sdk.settings.PdfSettings;
import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;
public class WordDocumentToPDFUA {Create a main method and declare NutrientException:
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(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.docx")) { // Configure PDF settings for PDF/UA conformance. PdfSettings pdfSettings = document.getSettings().getPdfSettings(); pdfSettings.setConformance(PdfConformance.PDF_UA_1);After loading the file, set PDF conformance to PDF_UA_1, and then call SDK methods on the document instance. For the full API surface, refer to the API reference.
Export the document as PDF/UA. 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/UA-compliant 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/UA conversion flow in Java. Download the sample package to run this example as-is.