Class Docling

java.lang.Object
org.docling.Docling

public final class Docling extends Object
A thin, embeddable Java wrapper around the docling command-line tool.

It does not reimplement conversion — it shells out to the docling executable, which must be installed and on your PATH (e.g. pip install docling).

Typical usage:

Docling docling = Docling.builder().build();
String markdown = docling.convert("path/to/file.pdf");

Instances are immutable and safe to reuse across conversions.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Fluent builder for Docling.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder with default settings (docling on the PATH, 600s timeout).
    convert(byte[] data, String extension)
    Converts in-memory document bytes to Markdown and returns it as a string.
    convert(byte[] data, String extension, boolean removeBase64Images)
    Converts in-memory document bytes to Markdown and returns it as a string.
    convert(byte[] data, String extension, boolean removeBase64Images, boolean insertPageNumbers)
    Converts in-memory document bytes to Markdown and returns it as a string.
    convert(String source)
    Converts the given source (local file path or URL) to Markdown and returns it as a string.
    convert(String source, boolean removeBase64Images)
    Converts the given source (local file path or URL) to Markdown and returns it as a string.
    convert(String source, boolean removeBase64Images, boolean insertPageNumbers)
    Converts the given source (local file path or URL) to Markdown and returns it as a string.
    convert(Path source)
    Converts a local file to Markdown and returns it as a string.
    convert(Path source, boolean removeBase64Images)
    Converts a local file to Markdown and returns it as a string.
    convert(Path source, boolean removeBase64Images, boolean insertPageNumbers)
    Converts a local file to Markdown and returns it as a string.
    convertToDir(String source, Path outputDir)
    Converts the given source to Markdown, writing the .md file into outputDir.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • builder

      public static Docling.Builder builder()
      Creates a new builder with default settings (docling on the PATH, 600s timeout).
    • convert

      public String convert(String source)
      Converts the given source (local file path or URL) to Markdown and returns it as a string.
      Parameters:
      source - path or URL of the document to convert
      Returns:
      the generated Markdown
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero
    • convert

      public String convert(String source, boolean removeBase64Images)
      Converts the given source (local file path or URL) to Markdown and returns it as a string.
      Parameters:
      source - path or URL of the document to convert
      removeBase64Images - when true, strips images embedded as base64 data URIs from the generated Markdown (both ![...](data:image/...) and <img src="data:image/..."> forms)
      Returns:
      the generated Markdown
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero
    • convert

      public String convert(String source, boolean removeBase64Images, boolean insertPageNumbers)
      Converts the given source (local file path or URL) to Markdown and returns it as a string.
      Parameters:
      source - path or URL of the document to convert
      removeBase64Images - when true, strips images embedded as base64 data URIs from the generated Markdown (both ![...](data:image/...) and <img src="data:image/..."> forms)
      insertPageNumbers - when true, inserts a ---- Page N ---- marker line at the start of each page's content. Page boundaries come from docling's JSON output, so this runs a single conversion that also emits JSON. To keep that JSON small and fast (its only purpose here is page provenance), images are exported as placeholders rather than embedded, so the Markdown produced in this mode contains image placeholders instead of inline base64 images. Best-effort: pages with no locatable text are left unmarked.
      Returns:
      the generated Markdown
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero
    • convert

      public String convert(Path source)
      Converts a local file to Markdown and returns it as a string.
    • convert

      public String convert(Path source, boolean removeBase64Images)
      Converts a local file to Markdown and returns it as a string.
      Parameters:
      source - path of the document to convert
      removeBase64Images - when true, strips base64-embedded images from the output
    • convert

      public String convert(Path source, boolean removeBase64Images, boolean insertPageNumbers)
      Converts a local file to Markdown and returns it as a string.
      Parameters:
      source - path of the document to convert
      removeBase64Images - when true, strips base64-embedded images from the output
      insertPageNumbers - when true, inserts a ---- Page N ---- marker at the start of each page (see convert(String, boolean, boolean))
    • convert

      public String convert(byte[] data, String extension)
      Converts in-memory document bytes to Markdown and returns it as a string.

      docling infers the input format from the file extension, so an extension matching the data is required. The bytes are written to a temporary file (deleted afterwards) before being handed to docling.

      Parameters:
      data - the raw document bytes (e.g. the contents of a PDF or DOCX)
      extension - the file extension describing the data, with or without a leading dot (e.g. "pdf", ".docx")
      Returns:
      the generated Markdown
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero
    • convert

      public String convert(byte[] data, String extension, boolean removeBase64Images)
      Converts in-memory document bytes to Markdown and returns it as a string.

      docling infers the input format from the file extension, so an extension matching the data is required. The bytes are written to a temporary file (deleted afterwards) before being handed to docling.

      Parameters:
      data - the raw document bytes (e.g. the contents of a PDF or DOCX)
      extension - the file extension describing the data, with or without a leading dot (e.g. "pdf", ".docx")
      removeBase64Images - when true, strips base64-embedded images from the output
      Returns:
      the generated Markdown
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero
    • convert

      public String convert(byte[] data, String extension, boolean removeBase64Images, boolean insertPageNumbers)
      Converts in-memory document bytes to Markdown and returns it as a string.

      docling infers the input format from the file extension, so an extension matching the data is required. The bytes are written to a temporary file (deleted afterwards) before being handed to docling.

      Parameters:
      data - the raw document bytes (e.g. the contents of a PDF or DOCX)
      extension - the file extension describing the data, with or without a leading dot (e.g. "pdf", ".docx")
      removeBase64Images - when true, strips base64-embedded images from the output
      insertPageNumbers - when true, inserts a ---- Page N ---- marker at the start of each page (see convert(String, boolean, boolean))
      Returns:
      the generated Markdown
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero
    • convertToDir

      public Path convertToDir(String source, Path outputDir)
      Converts the given source to Markdown, writing the .md file into outputDir.
      Parameters:
      source - path or URL of the document to convert
      outputDir - directory the Markdown file is written to (created if missing)
      Returns:
      the path of the generated Markdown file
      Throws:
      DoclingException - if docling cannot be launched, times out, or exits non-zero