Class MarkItDown

java.lang.Object
io.github.cyber655.markitdown.MarkItDown

public final class MarkItDown extends Object
A Java API for Microsoft MarkItDown.

This is a thin, dependency-free wrapper that invokes the markitdown command-line tool as a subprocess. The MarkItDown CLI (a Python package) must be installed and reachable, either on the PATH or via an explicit path supplied to MarkItDown.Builder.executable(String).

MarkItDown md = MarkItDown.create();
String markdown = md.convert(Path.of("report.pdf"));

Instances are immutable and safe to share between threads. Each conversion spawns its own subprocess.

Security: MarkItDown performs I/O with the privileges of the current process. Sanitize inputs in untrusted environments and prefer the narrowest conversion entry point for your use case.

  • Method Details

    • create

      public static MarkItDown create()
      Creates a client with default settings (markitdown on the PATH).
    • builder

      public static MarkItDown.Builder builder()
      Creates a new client builder.
    • convert

      public String convert(Path file)
      Converts a file to Markdown using default options.
    • convert

      public String convert(Path file, ConversionOptions options)
      Converts a file to Markdown.
    • convert

      public String convert(byte[] data, ConversionOptions options)
      Converts in-memory bytes to Markdown by piping them to the tool's standard input. Because there is no filename, supplying an ConversionOptions.Builder.extensionHint(String) or MIME-type hint is strongly recommended so MarkItDown can pick the right converter.
    • convert

      public String convert(InputStream input, ConversionOptions options)
      Converts the contents of a stream to Markdown by piping them to standard input.
    • convertToFile

      public void convertToFile(Path input, Path output, ConversionOptions options)
      Converts a file and writes the Markdown directly to output (maps to the CLI -o flag). The output file is written by the MarkItDown process itself using UTF-8.
    • version

      public String version()
      Returns the MarkItDown CLI version string (output of markitdown --version).
    • isAvailable

      public boolean isAvailable()
      Returns true if the markitdown executable can be located and run, i.e. if version() succeeds.
    • listPlugins

      public String listPlugins()
      Returns the raw output of markitdown --list-plugins.