Command line
The doc2mark command (also python -m doc2mark) converts one file or a folder with the
same loader as the Python API.
doc2mark report.pdf # Markdown on stdout (see "Output" below)
doc2mark report.pdf -o report.md # write report.md
doc2mark report.pdf --format json -o report # write report.json
doc2mark report.pdf --format both -o report # write report.md and report.json
doc2mark scan.pdf --ocr tesseract --ocr-images -o scan.md
doc2mark documents/ -r -o converted/ --skip-errors
OCR is off unless you pass --ocr <provider> --ocr-images.
Output
One file, no
-o: Markdown goes to stdout, cut after 1,000 characters with a... (truncated, use -v for full output)line unless-vis given;--format jsonprints the whole JSON. stdout carries only the document: logs and MuPDF’s messages go to stderr.One file with
-o PATH: the extension ofPATHis replaced by.mdor.json(-o reportand-o report.txtboth writereport.md; the folder must exist);--format bothwrites both files. The command printsOutput saved to: ...(not with-q).A folder: with
-o DIRevery converted document is written to the same relative path underDIRwith.md(or.json) in place of its extension (docs/2024/report.pdfbecomesDIR/2024/report.md), as soon as it is converted: a failure that stops the run keeps what was written before it; a file is written whole or not at all (a document the--encodingcannot hold is a failed file). Files of one folder that would write the same name (report.txtandreport.md) are written asreport.txt.mdandreport.md.md; a warning names them.-omust not be the input folder (usage error, exit code 2: the outputs would sit among their sources and be converted again by the next run); an output folder inside the input folder is left out of the input files, so the run can be repeated. Without-oonly a summary is printed.
The JSON is ProcessedDocument.to_dict(): content
(the Markdown), metadata (with extra), images, tables, sections and
json_content.
Options
OCR
--ocr {openai,vertex_ai,tesseract,none}OCR provider (default
none).geminiis not accepted here; usevertex_ai.--ocr-images/--no-ocr-imagesOCR scanned pages and pictures (default off). Needs
--ocrother thannone(otherwise the command stops with a usage error) and implies--extract-images.--extract-images/--no-extract-imagesExtract pictures (default off).
--api-key KEYKey for the provider; OpenAI otherwise reads
OPENAI_API_KEY.--ocr-lang LANGTesseract language(s) (default
eng): codes such asdeu,chi_tra,eng+chi_traor long names such aschinese_traditional(see Tesseract languages). A language that is not installed fails the run. Only used with--ocr tesseract.--ocr-task {auto,table,document,form,receipt,handwriting,code}Task hint for the LLM providers (default
auto).--no-structuredFree-form Markdown answers instead of structured OCR (LLM providers).
--ocr-detail {raw,full}rawskips the interpretation part of structured answers (defaultfull).--judge {none,typesafe}The optional judge (Optional judge (TypeSafe / Jev)). Default:
$DOC2MARK_JUDGE, elsenone.
Output
-o, --output PATHOutput file or folder.
--format {markdown,json,both}Default
markdown.--table-style {minimal_html,markdown_grid,styled_html}How tables with merged cells are written (default
minimal_html; Tables).--encoding ENCEncoding of the files written (default
utf-8).--include-metadataPut a
---block with the file name, size and modification time before the content.--max-length NCut the content after
Ncharacters and add... (truncated).--preserve-structureDeprecated: accepted with a warning and ignored, because a folder run always mirrors the input tree under
-o.
Folders
-r, --recursiveInclude sub-folders.
--pattern GLOBWhich files to convert (default
*: every file; sub-folders are never converted themselves,-rdecides whether the files inside them match too). A file in a format doc2mark does not read fails the run, so use a pattern such as"*.pdf"or--skip-errors.--exclude GLOBLeave out file names matching
GLOB(repeatable).--max-files N,--sort {name,size,date}Keep the first
Nfiles after sorting (ascending; defaultname), so--sort size --max-files 10keeps the ten smallest files and--sort datethe oldest.-p, --parallel NConvert
Nfiles at once. Every file of a folder run is converted in a worker process (one at a time without-p).--skip-errorsReport a file that fails and go on (the command then exits 0); without it the first failure stops the run.
--retry NTry a failing file
Nmore times (default1;0or more).--timeout SECONDSThe longest time one file of a folder run may take, its retries included (default
0: no limit, so a slow scan is never cut off). A file that takes longer is stopped (its worker process is terminated, and with it a LibreOffice it started) and counts as failed:timed out after 600 s (--timeout). A single-file run is not limited.
Messages
-v, --verboseDebug logging on stderr, and the whole document on stdout.
-q, --quietErrors only.
--log-file FILEAlso log to
FILE.--progress {bar,dots,none},--no-colorProgress display for folders (on stdout; default
bar).
Exit codes
0 success (also when --skip-errors skipped files), 1 the input does not exist or a
conversion failed (the message is on stderr), 2 invalid options. An OCR engine that cannot
run (for example Tesseract without the requested language) is a failure.
doc2mark scan.pdf --ocr tesseract --ocr-images --ocr-lang eng+chi_tra -o scan.md
doc2mark documents/ -r --pattern "*.pdf" -p 4 -o converted/
doc2mark documents/ -r --exclude "*.csv" --skip-errors -o converted/
doc2mark report.pdf --table-style markdown_grid --include-metadata --max-length 5000 -o report.md
DOC2MARK_JUDGE=typesafe doc2mark report.pdf --ocr tesseract --ocr-images -o report.md