docling-java icon indicating copy to clipboard operation
docling-java copied to clipboard

docling-core: export DoclingDocument to markdown/text locally (Python parity)

Open rkudryashov opened this issue 5 months ago • 3 comments

DoclingDocument in Java deserializes from JSON, but there is no local export API (export_to_markdown() / text) like in Python.

We persist Docling JSON as canonical artifact and need text/md in later (async) document processing stages (moderation, etc.) without re-parsing the original file and without a Serve round-trip (JSON_DOCLING → md|text works but adds HTTP coupling).

Proposal: add local export in docling-core, e.g. toMarkdown() / toText().

Use case: offline/async workers reading archived JSON only.

rkudryashov avatar Jun 18 '26 16:06 rkudryashov

Can't you receive the export in both Markdown and json from the api? In your request you can ask for both JSON & Markdown and in DocumentResponse there is both the jsonContent (the DoclingDocument) and markdownContent (as well as textContent and htmlContent)

edeandrea avatar Jun 19 '26 06:06 edeandrea

That makes sense — requesting both formats up front would work.

The reason I'm asking for local export is that I intentionally persist only the Docling JSON as the canonical artifact. Hybrid chunking already consumes JSON_DOCLING directly, while Markdown/text are derived representations that other downstream stages (e.g. moderation) may need later.

So rather than storing multiple representations, I'd prefer to store only the JSON and derive Markdown/text from the archived DoclingDocument when needed, ideally without another Serve round-trip.

rkudryashov avatar Jun 19 '26 07:06 rkudryashov

This API is just a wrapper around docling-serve. It doesn't really do anything on its own. The Java API doesn't do any processing on its own.

That being said let me do some investigation and see if there's anything possible. If the conversion involves some logic performed by Docling itself then unfortunately we won't be able to do that here.

But I'll do some investigation.

edeandrea avatar Jun 19 '26 07:06 edeandrea