Local PDF-to-Markdown Conversion for Scanned and Text-Based Documents

    A reliable local PDF-to-Markdown workflow requires more than text extraction. This article explains how to classify pages, recover reading order, reconstruct tables, preserve figures, and retain source metadata. It also covers technical validation, stable version comparisons, retrieval-augmented generation, and deployment checks, with particular attention to firmware specifications and register documentation.

    1. Is There a “Perfect” Local Conversion Solution?

    Both scanned and text-based PDFs can be converted to Markdown locally. However, there is no universal approach that can reliably convert every document without information loss or manual verification.

    PDF primarily describes how content appears on a page. Markdown primarily represents content structures such as headings, paragraphs, lists, and tables. Their design goals differ: a line of text in a PDF may consist of many independent character objects, and a visually continuous table may be nothing more than text and drawn lines. A scanned document may have no readable text layer at all.

    The practical engineering goal is therefore not to convert every page successfully in one pass. It is to build a pipeline that can:

    • Distinguish text-based, scanned, and mixed-content pages.
    • Recover reading order and section hierarchy.
    • Preserve images, complex tables, and their source locations.
    • Flag uncertain content for manual review.
    • Produce a stable file structure for version comparisons.
    • Provide trustworthy, traceable data for retrieval-augmented generation (RAG).

    For technical specifications, conversion quality cannot be judged solely by whether all the text was extracted. An incorrect digit in a register bit field, a missing reserved field, or a misread footnote can affect firmware implementation. The converter should therefore be treated as a document parsing and quality-control system, not simply a format export feature.

    2. Define the Outputs: One Text File Is Not Enough

    Firmware developers typically need converted documents to support three distinct uses.

    Human Reading

    Readers need a clear section hierarchy, complete register tables, and accessible block diagrams and timing diagrams.

    The output should preserve the relationship between explanatory text and visual content. An architecture diagram belongs near its associated discussion, rather than in a collection at the end of the document. Access restrictions, reset conditions, and footnotes following register tables must also remain intact.

    Knowledge Retrieval

    A retrieval system needs semantically complete content units, not a mechanical concatenation of everything printed on a page.

    A useful register knowledge chunk should include at least the register name, relevant module, field definitions, and necessary context. A field table without its section path or register name may be retrieved successfully but still leave the user unable to identify the module it describes.

    Version Comparison

    Version comparison requires stable text representations. If section boundaries, field ordering, image names, or whitespace handling change between conversion runs, the resulting diff will contain substantial noise.

    Maintain three types of artifacts:

    1. The original PDF and its source information.
    2. Intermediate data containing coordinates, page numbers, and structural relationships.
    3. Markdown and image assets for reading and retrieval.

    Markdown is the presentation layer; it should not be the only storage layer. Retaining intermediate structures allows documents to be regenerated after parsing rules change, without repeating the entire recognition process.

    3. Overall Architecture: Recover Structure Before Generating Markdown

    A recommended local workflow is:

    1. Original PDF
    2. ↓
    3. Document registration and page classification
    4. ↓
    5. Text-layer extraction / page-image recognition
    6. ↓
    7. Layout analysis and reading-order recovery
    8. ↓
    9. Structuring of headings, paragraphs, tables, and figures
    10. ↓
    11. Repeated-noise handling and technical-field validation
    12. ↓
    13. Markdown and asset generation
    14. ↓
    15. Manual review, retrieval indexing, and version comparison

    The central principle is separate parsing paths, unified structure. Different pages can use different parsing methods, but their results should enter a consistent intermediate data model.

    For example, a content block might contain:

    1. Content block:
    2. Document identifier
    3. Version identifier
    4. PDF page index
    5. Printed page number
    6. Bounding coordinates
    7. Content type
    8. Section path
    9. Text or asset reference
    10. Parsing method
    11. Quality status

    Store the PDF page index separately from the printed page number. Specifications may include covers, tables of contents, and appendices, so a page’s position in the file may not match the number printed on it.

    This metadata allows readers to return directly to the original page when they encounter a possible error.

    4. Page Classification: Do Not Force One Method onto the Entire Document

    Text-Based PDFs

    Text-based PDFs usually contain extractable text objects, but extractable text is not necessarily reliable text.

    Common problems include:

    • Incorrect character mappings that make copied text differ from the displayed content.
    • Text stored in drawing order, causing left and right columns to become interleaved.
    • Words split across multiple text objects.
    • Missing superscripts, subscripts, mathematical symbols, or special characters.
    • Watermark text inserted into ordinary paragraphs.

    Assess character readability, text coverage, spatial relationships, and the proportion of anomalous characters together. If a text layer is clearly damaged, apply optical character recognition (OCR) to the affected regions rather than continuing to use incorrect extracted text.

    Scanned PDFs

    Scanned PDFs require page rendering followed by orientation correction, appropriate denoising, layout analysis, and text recognition.

    Rendering resolution should reflect character size and page quality. Too little resolution can lose small bit-field numbers and footnotes. Too much increases memory consumption and processing time without necessarily improving recognition of poor-quality scans.

    Preprocessing also requires care. Aggressive binarization or denoising can erase thin table borders, minus signs, and decimal points. A visually “clean” page is not necessarily a more accurate recognition input.

    Mixed-Content PDFs

    Technical documents often combine selectable body text, scanned tables, and diagrams built from vector objects.

    A more appropriate strategy is to choose methods by region:

    • Read the text layer for normal body text.
    • Use image recognition and table-structure recovery for scanned tables.
    • Render vector diagrams by region.
    • Export embedded images directly where appropriate.

    Do not default to OCR for the entire document. Doing so may introduce recognition errors into technical characters that were already accurate in the original text layer.

    5. Layout Recovery: Reading Order Matters More Than Character Count

    Recovering reading order is one of the main challenges in PDF conversion.

    Technical specifications may contain two-column text, side notes, captions, tables spanning multiple pages, and footnotes at the bottom of a page. Simply sorting characters by coordinates can place captions inside paragraphs or insert right-column content into the middle of the left column.

    Layout analysis should first identify regions, then determine their order, and finally reconstruct lines and paragraphs within each region.

    Heading detection should not depend on font size alone. Register names, table titles, and highlighted notices may also use large fonts. Combine numbering patterns, position, table-of-contents information, font characteristics, and contextual hierarchy.

    Handling Headers, Footers, and Watermarks

    Headers and footers can be identified through repetition across pages. Consider whether the same content repeatedly appears in similar positions, remains separate from the body, and matches a page-number or document-identifier pattern.

    Do not simply delete all repeated text. Repeated column headers in tables spanning multiple pages are often essential to understanding the data.

    For watermarks, consider position, rotation, transparency, and repetition across pages. In scanned documents, watermarks are already part of the image. When they overlap body content, lossless removal generally cannot be guaranteed.

    Confidentiality markings may be unsuitable for inclusion in the searchable body text, but they should remain in document metadata. Conversion must not erase the source document’s security classification or usage restrictions.

    6. Table Reconstruction: The Critical Quality-Control Step for Register Documentation

    Why Borderless Tables Are Difficult

    For bordered tables, drawn lines can help identify cells. Borderless tables rely mainly on text alignment, spacing, and semantics.

    A register bit-field table might contain:

    • Bit range.
    • Field name.
    • Access type.
    • Reset value.
    • Field description.

    The description column often contains multiple lines, while the bit-range column contains only a few characters. Treating every visual line as an independent record breaks the relationship between a field and its description.

    Table recognition must therefore do more than locate a table. It must reconstruct rows, columns, merged cells, and continuation lines.

    Do Not Force Every Table into a Markdown Table

    Standard Markdown tables work well for simple structures with short cell contents. They are less suitable for complex merged cells, nested structures, or lengthy descriptions.

    Use a tiered output strategy:

    • Simple tables: Generate Markdown tables for reading and retrieval.
    • Complex tables: Generate HTML tables when supported by the target renderer, while retaining structured data.
    • Low-confidence tables: Preserve a screenshot of the table region, accompanied by recognized text and a review flag.

    For complex register tables, a supplementary field-by-field representation can also be useful:

    1. Field name: Control field
    2. Bit range: 7:4
    3. Access type: Read/write
    4. Reset value: 0
    5. Description: ...
    6. Source: Register definition table on the relevant page

    This does not reproduce the original layout exactly, but it supports retrieval and field-level verification.

    Add Technical Semantic Checks

    After reconstructing tables, check for anomalies such as:

    • Bit ranges exceeding the register width.
    • Unexpected overlaps between fields.
    • Reset values that cannot be represented by the corresponding field width.
    • Clearly suspicious access-type recognition.
    • Inconsistent field counts between headers and rows.
    • Incorrect association of continuation tables with registers.

    These checks should detect possible problems, not automatically “correct” the source. Overlapping fields may represent aliases used in different modes, and reset values may include undefined states. Preserve the source content and request review.

    7. Preserving Figures: Object Extraction and Region Capture Are Different Capabilities

    An architecture diagram in a PDF is not necessarily a single image. It may consist of lines, text, arrows, and multiple image objects.

    Figure handling should distinguish two methods:

    1. Export independent raster images directly.
    2. Render and crop identified regions for vector or mixed-content diagrams.

    Exporting only the PDF’s internal image objects may produce an incomplete block diagram. For example, the background image may be exported while labels and arrows remain on the page.

    Manage assets through relative paths:

    1. knowledge/
    2. document/
    3. overview.md
    4. chapters/
    5. chapter-01.md
    6. assets/
    7. figure-001.png
    8. table-001.png
    9. metadata/
    10. source.json
    11. review.json

    A chapter can reference an image as follows:

    1. ![Module interconnect diagram](../assets/figure-001.png)

    Keep image filenames as stable as possible. Names can be based on the document’s figure numbers, section identifiers, and asset types. Content fingerprints can support deduplication, but should not be the sole basis for display filenames: even a small image change would then change the filename.

    Preserve captions and nearby explanatory paragraphs to support retrieval. If additional image descriptions are generated, label them clearly as supplementary descriptions. Inferred connections, signal directions, or timing behavior must not be presented as facts from the source.

    8. Version Comparison: Compare Semantic Changes, Not Just Text Changes

    Markdown supports convenient text diffs, but unstable conversion quality can create excessive noise between document versions.

    For meaningful comparisons, standardize:

    • Section-splitting rules.
    • Heading levels.
    • Table serialization.
    • Whitespace and line-break handling.
    • Image naming.
    • Conversion configuration and model versions.

    General-purpose text normalization must not be applied indiscriminately to technical content. Symbol substitutions, hyphen joining, or numeric-format changes can alter the meaning of register names and expressions.

    For specification revisions, use two comparison layers.

    Layer 1: Text differences.
    Review changes to explanations, restrictions, and notes.

    Layer 2: Structured differences.
    Compare bit ranges, access types, reset values, and descriptions using register and field identifiers.

    Images need separate handling. A changed file fingerprint establishes that the file content differs, not that the diagram’s technical meaning has changed. Different rendering settings can also produce different images. Evaluate image differences using original figure numbers, captions, and manual inspection.

    9. Preparing for RAG: Avoid Mechanical Character-Based Chunking

    RAG quality depends on parsing quality, chunking, retrieval strategy, and answer constraints—not simply on whether the document has been converted to Markdown.

    Technical documents are better divided into semantic units, such as:

    • A register and all its fields.
    • An operating procedure and its precautions.
    • A table and its footnotes.
    • A complete conceptual explanation within a section.

    If a unit is too long and must be split, attach the section path, register name, version, and source page numbers to each chunk so that context is not lost.

    Exact retrieval is often more important than semantic similarity alone for register identifiers, hexadecimal addresses, and bit ranges. Keyword retrieval can therefore be combined with vector retrieval, with results filtered by metadata such as document version and module type.

    When supplying this material to AI coding tools, require them to:

    • Cite specific source locations.
    • Distinguish source requirements from inferred conclusions.
    • Avoid mixing register definitions from different versions.
    • Request manual confirmation for low-confidence recognized content.

    Converted documents can assist code generation, but they do not replace final verification against the original specification.

    10. Local Deployment and Acceptance Testing: Build a Benchmark Before Processing the Full Collection

    Local deployment means more than keeping PDFs off remote servers. Review how model files, dependencies, telemetry, logs, and temporary files are handled. Offline execution does not automatically guarantee data security.

    For restricted technical documents, control access to input, output, and cache directories, and prevent source excerpts from entering shared logs. Images, indexes, and intermediate data should receive the same sensitivity classification as the original document.

    Processing documents with thousands of pages requires batch execution, retry handling, and resumable processing. OCR and layout analysis are usually the main computational workloads. Adjust concurrency to available hardware, but avoid speed promises that ignore document characteristics and equipment.

    Before full conversion, create a representative set of test pages covering:

    • Ordinary single-column text.
    • Two-column text.
    • Borderless register tables.
    • Tables spanning multiple pages.
    • Architecture block diagrams.
    • Small-print footnotes.
    • Watermarked pages.
    • Low-quality scans.

    Acceptance testing should assess text accuracy, structural accuracy, and technical correctness. Track errors in critical numbers, bit ranges, reset values, and access types separately. An overall character-recognition score can otherwise conceal high-risk mistakes.

    Finally, classify pages into three groups: ready to use, spot-check required, and mandatory review. This directs manual effort toward complex tables and critical technical fields.

    Conclusion

    The real challenge in converting scanned and text-based PDFs to Markdown is not changing a file extension. It is recovering trustworthy technical structure from a visual layout.

    A local workflow suitable for firmware development should use the original PDF as the source of truth, structured intermediate data to retain parsing results, and Markdown for reading and linking. Figure preservation, technical validation, stable output, and version management make the resulting documents more useful and reliable.

    Rather than searching for a single tool that claims to convert every document perfectly, build a process that can detect failures, preserve evidence, support review, and improve over time. That is a more realistic foundation for engineering reliability.