This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/java/conversion/pdf-to-markdown.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Converting PDF documents to Markdown format | Nutrient Java SDK

PDF-to-Markdown conversion transforms static documents into editable, version-controlled text. This process enables content teams to extract information from reports and documentation for use in modern platforms and CMS workflows.

Programmatic conversion is essential for:

  • Managing large document libraries.
  • Transitioning technical documentation teams from PDF-based to Markdown-driven processes.
  • Processing and republishing content across digital platforms via automation systems.
Download sample

Streamlining document workflows with our Java SDK

Developers can implement this feature by adding a few lines of code to their applications. The SDK integrates PDF-to-Markdown conversion directly, which removes the requirement for external tools or complex setups. Our SDK provides a reliable solution for building documentation systems or adding export functionality to content management platforms.

Preparing the project

Specify a package name and create a new class:

package io.nutrient.Sample;

Import Nutrient Java SDK. It’s recommended to specify the actual classes used, but using a wildcard to include everything is also possible:

import io.nutrient.sdk.Document;
import io.nutrient.sdk.exceptions.NutrientException;
public class PdfToMarkdown {

Create the main function and specify that it can throw a NutrientException. This exception can be caught in the program logic for custom error management:

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

After the Java application setup, focus on the SDK-specific steps.

Loading the PDF document

This guide focuses on the Document class. Initialize Document using a try-with-resources(opens in a new tab) statement to enable proper lifecycle management of the document instance.

The SDK supports multiple integration methods to provide flexibility when connecting with your application. Specify the source file using a file path or a stream. This guide uses a file path as the source:

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

This path can be absolute or relative. This example loads the file from the application’s working directory, which typically resides next to the executable.

Converting to Markdown format

The core conversion operation transforms loaded PDF content into structured Markdown format while preserving the document’s logical organization and formatting:

document.exportAsMarkdown("output.md");
}
}
}

The exportAsMarkdown method executes a conversion process that analyzes the PDF’s text content and identifies structural elements like headings and paragraphs. It preserves formatting information in Markdown syntax and generates clean, standards-compliant output.

The conversion algorithm recognizes document patterns such as headers, lists, and tables, translating these elements into Markdown equivalents. The method handles various PDF content types, including:

  • Flowing text
  • Structured documents with hierarchies
  • Tables and lists
  • Mixed content layouts

Markdown output behavior

In version 2.1.13, Markdown export has the following behavior:

  • Page headers and footers are included by default. Enable emitHeaderFooterMarkers in the Markdown settings to wrap them in <!-- page-header --> … <!-- /page-header --> and <!-- page-footer --> … <!-- /page-footer --> comment markers.
  • Code fences include inferred language tags when the code block content identifies a language.
  • Checkboxes render as Markdown task-list items.
  • Labeled form fields render as label: value lines.
  • Inline formatting is opt-in. Enable enableInlineFormatting to preserve bold, italic, highlights, and other inline styles. Runs that are both bold and italic are emitted as **_text_**.
  • Wrapped words are rejoined using language-specific dictionaries where available. A compound’s own hyphen is retained, so quasi- followed by experimental remains quasi-experimental; wrapped number ranges also keep their hyphens.
  • Paragraphs and tables identified as continuations across pages are merged in Markdown output.
  • Captions render as plain text, and charts render as data tables without generated summaries.
  • Pictures with alternative text use valid image syntax. Pictures without alternative text or extractable words don’t emit a bare [Figure] placeholder unless emitFigurePlaceholders is enabled.
  • Chart and table output handles multi-panel chart tables, corrected row and column spans, and tall tables whose rows require banded recovery.

Configure these options through document.getSettings().getMarkdownSettings() before exporting. For example, setEnableInlineFormatting(true) preserves inline styles, and setEmitFigurePlaceholders(true) enables otherwise-empty picture placeholders. To keep line-wrap fragments rather than rejoining them, call setJoinHyphenatedLineBreaks(false); the fragments remain separated by a space.

For born-digital text without word-level language metadata, hyphen joining uses the lexicon for the configured OCR language. The advanced OCR setting detectLanguageFromDigitalText is off by default; enable it to detect the language from born-digital text when an explicit OCR language is configured.

Output encoding and Unicode handling

The Markdown exporter writes UTF-8 Markdown without a byte order mark (BOM). This keeps the output compatible with tools that treat a BOM as content.

The exporter also handles stray Unicode surrogate characters in source content gracefully. These malformed characters don’t stop PDF-to-Markdown conversion, so the rest of the document remains available to downstream processing.

Content encoding

Markdown export escapes <, backticks, tildes, and character references in document text, so the text displays literally and can’t create HTML or code blocks. Ordinary & and > characters stay as they are. Generated tables and formatting remain intact. HTML table cells are always encoded. Encoding is enabled by default. To preserve raw HTML from trusted content, call setEncodeDocumentText(false) on the document’s Markdown settings before exporting.

Error handling

Nutrient Java SDK handles errors with exception handling. Both methods presented in this guide throw a NutrientException if a failure occurs. This helps with troubleshooting and implementing error handling logic.

Conclusion

That’s all it takes to convert a PDF document into Markdown format. The converted content is ready for integration with modern documentation workflows and content management systems. You can also download this ready-to-use sample package, which is configured to help you explore file format conversion capabilities.