Jump to content

PDF to Markdown Conversion

From LemonWiki共筆
Revision as of 17:42, 15 September 2026 by Planetoid (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

PDF to Markdown Conversion

Many people recommend MarkItDown, a tool developed by Microsoft, which works well on text-based PDFs but requires enabling its OCR plugin for image-based PDFs and even then, conversions can still fail;

for Chinese-language PDFs in particular, the OCR models with better accuracy tend to come from Chinese vendors, which adds the extra burden of converting between Simplified and Traditional Chinese and proofreading the results, making this data-cleaning process quite labor-intensive, so by comparison, converting documents directly with a multimodal large language model turns out to be more efficient.

1. Text-Based PDFs

If the PDF content is primarily text-based, you can use:

2. Image-Based PDFs

If the PDF content is primarily image-based (scanned documents, screenshots, charts, etc.), it's recommended to:

  • Use a model with vision/graphical recognition or multimodal capabilities directly, such as GPT-4.5 (consumes AI tokens)
  • Or use the MarkItDown OCR Plugin (consumes AI tokens), though it tends to make mistakes with more complex charts/diagrams

Introduction

This prompt is designed to convert a PDF document into structured Markdown while preserving not only its textual content, but also information contained in images, charts, screenshots, scanned pages, diagrams, and other visual elements.

The goal is to produce a Markdown representation that preserves the original document as faithfully as possible, including its content, structure, reading order, tables, formatting, visually embedded text, and source references.

Model Requirements

This prompt should be used with an AI model that supports vision, image understanding, or multimodal input.

The model must be capable of analyzing visual content inside a PDF, rather than relying solely on text extracted from the PDF's text layer.

Examples of suitable multimodal or vision-capable models include:

  • OpenAI: GPT-4.5[1], GPT-4.1, GPT-5 series
  • Google: Gemini models with multimodal/image understanding capabilities, such as Gemini 2.5 Flash[2] or Gemini 2.5 Pro
  • Anthropic: Claude models with vision/image-input support

Equivalent or newer multimodal models or models with vision capabilities may also be used, provided that they can inspect images and graphical content contained within the PDF.

A text-only model, or a PDF processing pipeline that extracts only the PDF text layer, is not sufficient for this task because text embedded in screenshots, scanned pages, charts, diagrams, or other images may otherwise be omitted.

Prompt

Prompt


I will provide a PDF file. Convert its contents into Markdown-formatted text.

Please follow these requirements:

# If the PDF contains images, charts, screenshots, scanned pages, diagrams, or other graphical content, inspect the visual content and extract '''all readable text contained within it'''.

   Transcribe that text into the Markdown output. Do not omit text simply because it is embedded in an image rather than stored in the PDF text layer.

# If a graphical element contains no text, such as a photograph, icon, illustration, or purely visual diagram, do not skip it.

   Represent it using the following format:

   <code>[Image: Brief description of its content or purpose]</code>

# Preserve the original document's structure and hierarchy as closely as possible, including:

* Headings (<code>#</code>, <code>##</code>, <code>###</code>, etc.)
* Paragraphs
* Ordered and unordered lists
* Tables
* '''Bold text'''
   '' ''Italic text*
* Blockquotes
* Code blocks
* Other meaningful structural formatting

# Convert tables into standard Markdown table syntax whenever possible.

   If a table is too complex to reproduce accurately in Markdown, explain the limitation and preserve the relationships between rows, columns, headers, and values as faithfully as possible.

# If a page contains both textual and graphical content, preserve the original '''reading order'''.

   Insert transcribed image content or image descriptions at the position where the corresponding visual element appears in the document.

# Do not add, rewrite, correct, infer, summarize, or guess information that does not appear in the original PDF.

   The output should be a transcription and structural conversion, not an interpretation of the document.

# If any text is blurry, obscured, incomplete, or otherwise impossible to identify reliably, use:

   <code>[Unrecognizable]</code>

   Do not guess the missing text.

# When both the PDF text layer and the visual rendering contain the same text, avoid unnecessary duplication.

   Prefer the version that most accurately represents the document while preserving visually significant information that may not exist in the text layer.

# Pay particular attention to visual elements that commonly contain important text, including:

* Screenshots
* Scanned documents
* Infographics
* Flowcharts
* Charts and graphs
* Forms
* Presentation slides embedded in the PDF
* Captions and annotations
* Labels inside diagrams
* Text rendered as part of an image

Similar tools

References