---
title: "Converting file streams to PDF/UA | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/conversion/convert-from-file-stream-to-pdf-ua/"
md_url: "https://www.nutrient.io/guides/java/conversion/convert-from-file-stream-to-pdf-ua.md"
last_updated: "2026-08-10T00:00:00.000Z"
description: "How to convert documents from file streams to accessible PDF/UA using Nutrient Java SDK."
---

# Converting file streams to PDF/UA

Applications don’t always receive documents as file paths. A document might already be open as a file stream when it reaches a conversion service.

This sample converts a PDF supplied through a `FileInputStream` into a PDF/UA document written through a `FileOutputStream`. Keeping the conversion stream-based avoids reopening the input and output through SDK file-path overloads.

## Preparing the project

Specify a package name and import the SDK and Java I/O classes used by the sample:

```java

package io.nutrient.Sample;

import io.nutrient.sdk.Document;
import io.nutrient.sdk.enums.PdfConformance;
import io.nutrient.sdk.settings.PdfSettings;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class ConvertFromFileStreamToPdfUa {

```

Create the entry point and open the input file, output file, and document in a try-with-resources statement. Keep the input stream open for the lifetime of the document. Java closes the document before it closes either stream.

```java

    public static void main(String[] args) {
        try (FileInputStream inputStream = new FileInputStream("input.pdf");
             FileOutputStream outputStream = new FileOutputStream("output.pdf");
             Document document = Document.open(inputStream)) {

```

## Converting file streams to PDF/UA

Set PDF/UA-1 conformance and pass the output stream to `exportAsPdf()`:

```java

            PdfSettings pdfSettings = document.getSettings().getPdfSettings();
            pdfSettings.setConformance(PdfConformance.PDF_UA_1);

            document.exportAsPdf(outputStream);
            System.out.println("Successfully converted the file stream to PDF/UA.");
        } catch (Exception e) {
            System.err.println("Failed to convert the file stream to PDF/UA: " + e.getMessage());
            System.exit(1);
        }
    }
}

```

`Document.open(FileInputStream)` reads the source through the supplied stream. `exportAsPdf(FileOutputStream)` writes the converted document through the supplied output stream. Both streams remain owned by the application and are closed by the try-with-resources statement.

## Error handling

The sample catches exceptions from Java file operations and SDK document processing. It writes an error message and returns a nonzero exit code when either operation fails.

## Conclusion

The sample opens a PDF from a `FileInputStream`, applies PDF/UA-1 conformance settings, and writes the converted document to a `FileOutputStream`.

Download [this ready-to-use sample package](https://www.nutrient.io/downloads/samples/java/convert-from-file-stream-to-pdf-ua.zip).
---

## Related pages

- [Nutrient Java SDK conversion guides](/guides/java/conversion.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)
- [Converting HTML to PDF](/guides/java/conversion/html-to-pdf.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 Markdown format](/guides/java/conversion/pdf-to-markdown.md)
- [Converting PDF documents to PDF/A format](/guides/java/conversion/pdf-to-pdf-a.md)
- [Converting PDF documents to PDF/UA format](/guides/java/conversion/pdf-to-pdf-ua.md)
- [Converting PDF documents to PowerPoint presentations](/guides/java/conversion/pdf-to-powerpoint-document.md)
- [Converting a document from PDF to DOCX format](/guides/java/conversion/pdf-to-word-document.md)
- [Converting a document from PPTX to PDF format](/guides/java/conversion/powerpoint-document-to-pdf.md)
- [Preparing and troubleshooting PDF/A conversion](/guides/java/conversion/prepare-and-troubleshoot-pdf-a-conversion.md)
- [Validate PDF conformance](/guides/java/conversion/validate-pdf-conformance.md)
- [Converting a Word document to PDF while preserving comments](/guides/java/conversion/word-document-to-pdf-including-comments.md)
- [Converting a document from DOCX to PDF/UA format](/guides/java/conversion/word-document-to-pdf-ua.md)
- [Converting a document from DOCX to PDF format](/guides/java/conversion/word-document-to-pdf.md)

