REDDIT 原始帖子

How to convert from Scanned PDF to Docx with correct formatting?

What seems to be a simple task but after hours of researching the internet, i haven't found a standard solution. The requirements are as below: The PDF are mostly scanned texts. The convert Docx should have a similar formatting to the original (small…

原帖正文r/LocalLLaMA

What seems to be a simple task but after hours of researching the internet, i haven't found a standard solution. The requirements are as below: The PDF are mostly scanned texts. The convert Docx should have a similar formatting to the original (small variation in spacing, table column width...are acceptable) The texts should stay unmodified The conversion should also create an intermediate format that can be further process for LLM ingestion. (basically, i am trying to digitalize my paper documents, and also preparing to inject them into LLM for further queries)

已收录讨论

8 条评论

u/finah1995

Try Docling livrary from IBM with open weight models. I believe it covers your every use case. Someone else might be able to help you do RAG after you get this output using Docling.

u/x11iyu

docling? it can pdf -> docx, or pdf -> markdown for llm most vlm-based OCR I know can do pdf -> markdown, not sure about -> docx though actual accuracy will depend on your data

u/indicava

You could probably setup a pipeline for this using Docling->md (I’m not sure it’s the in thing now, it was 1.5 years ago when I was processing PDFs) and then pandoc/pypandoc->docx Have an LLM help you set it up.

u/yes-im-hiring-2025

Well if you can parse it as xml, then formatting to word is trivial. As others have suggested, try docling. I also believe you can pass your own LLM to so long it's being served via API in the OpenAI format.

u/Karyo_Ten

It's not a simple task. You need a VLM + framework with proper layout detection, including complex tables, image extraction, Latex formulas, ... PaddleOCR is good

u/Various_Story8026

For scanned (image-only) PDFs the tool that has worked best for me locally is MinerU or docling - both do OCR + layout analysis and can emit structured output that keeps headings, tables and reading order, which is where naive OCR falls apart. Pipeline that works: docling to markdown or html first, then pandoc to docx. You lose exact visual fidelity but keep the structure, which is usually what people actually need in the docx. If the formatting really has to look identical (letterheads, forms), no OCR path will fully get you there - the honest workaround is OCRmyPDF, which keeps the original page image and adds an invisible text layer, so the file stays pixel-identical and becomes searchable/copyable. Then only rebuild the pages you truly need to edit. Marker is a third option between the two: faster than docling on long docs, slightly worse on complex tables in my runs.

u/Creative-Type9411

Use NAPS2 - https://www.naps2.com Drag PDF into window, save as DOC it's actually scanning software, but it has the awesome side effect of being able to drag PDFs into it and rearrange them or re-save them to docs Its always my goto EDIT: I just realized where I was. I'm not sure if it has CLI. But in leaving this anyway cause NAPS is awesome

u/Equivalent_Bit_461

It's simple until it's not It's a nightmare beyond human comprehension, had a similar issue