Magic Tools
Document ProcessingBy CooconApril 22, 20263091 views8 min read

Document Format Conversion Guide: Markdown, HTML, PDF & More

The modern developer and writer lives in a world of format fragmentation. You write documentation in Markdown, your client wants a PDF, your CMS accepts HTML, your legal team uses Word, and your static site generator expects frontmatter-annotated .md files. Every handoff between systems is a potential format mismatch — and every format mismatch is friction.

Understanding how document formats relate to each other, what survives conversion, and which tools handle each path best can save hours of manual reformatting. This guide covers the major conversion paths, with honest assessments of what each one preserves well and where it falls short.

Format Overview

Format Human Readability Editability Render Quality Best For
Markdown High (plain text) Any text editor Depends on renderer Documentation, blogs, READMEs
HTML Moderate (with tags) Browser dev tools, code editor Excellent (native web) Web publishing, email templates
PDF High (rendered) Poor (locked layout) Excellent (fixed) Reports, invoices, print distribution
DOCX Low (binary) Word, Google Docs, LibreOffice Good (app-dependent) Business documents, tracked changes
RST High (plain text) Any text editor Good (Sphinx/docutils) Python ecosystem documentation
LaTeX Low (markup-heavy) Specialized editors Excellent (for math/print) Academic papers, books

Key Conversion Paths

Markdown → PDF

This is the most common conversion request: you've written documentation or a report in Markdown and need to share it as a professional PDF.

Browser print method is the simplest approach. Render your Markdown to HTML (using any Markdown previewer), then use the browser's Print dialog with "Save as PDF" selected. The output quality depends entirely on the CSS applied to the rendered HTML. Without explicit print CSS, you may get broken page breaks and unstyled output.

For better results, define print-specific CSS:

@media print {
  pre, blockquote { page-break-inside: avoid; }
  h1, h2, h3 { page-break-after: avoid; }
  body { font-size: 12pt; line-height: 1.5; }
}

Dedicated CLI tools offer more control:

# Using Pandoc with a LaTeX engine (best quality)
pandoc input.md -o output.pdf --pdf-engine=xelatex

# Using wkhtmltopdf (HTML-based rendering)
pandoc input.md -o temp.html && wkhtmltopdf temp.html output.pdf

# Using md-to-pdf (npm package, CSS customizable)
npx md-to-pdf input.md

Pandoc with a LaTeX engine produces the highest-quality PDFs and handles mathematical notation correctly. The trade-off is that you need LaTeX installed (~3GB), and tables require careful formatting.

Online tools: MagicTools Markdown Editor, Dillinger.io, and StackEdit all support direct PDF export for occasional use without any local installation.

Styling considerations: Syntax-highlighted code blocks, custom fonts, and page headers/footers require either a custom CSS file (for HTML-based rendering) or a Pandoc template (for LaTeX-based rendering). Plan for this overhead before committing to a Markdown → PDF workflow at scale.

Markdown → HTML

This path powers most static site generators and is arguably the most important conversion in the modern web stack.

Static site generators (Hugo, Jekyll, Eleventy, Astro) handle this automatically: you drop .md files in a content directory, run a build command, and get an optimized HTML site. This is the recommended approach for anything that will be published regularly.

For embedding Markdown in existing web pages without a full SSG, several libraries handle the conversion:

// Using the 'marked' library (client-side or Node.js)
import { marked } from 'marked';
const html = marked.parse(markdownContent);

// Using 'unified' pipeline (server-side, more extensible)
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';

const result = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(markdownContent);

For email templates: Markdown → HTML is appealing for email because it lets you write content without wrestling with HTML tables. However, email clients strip many HTML elements and most CSS. Run the output through a tool like Juice to inline all CSS, and test with Litmus before sending at scale.

HTML → Markdown

This conversion is less predictable than the reverse. HTML supports far more formatting options than Markdown, so some information is inevitably lost or simplified.

Blog migration is the primary use case. If you're moving from WordPress or Ghost to a static site generator, you need to convert hundreds of HTML posts to Markdown. The workflow:

  1. Export posts as HTML (WordPress has a built-in exporter)
  2. Use Pandoc for bulk conversion:
    # Convert a single file
    pandoc input.html -o output.md
    
    # Batch convert all HTML files in a directory
    for file in *.html; do
      pandoc "$file" -o "${file%.html}.md"
    done
    
  3. Review and fix: tables, custom shortcodes, and embedded media will need manual attention

MagicTools HTML to Markdown is the fastest option for individual pages — paste HTML or enter a URL, get clean Markdown immediately. Ideal for converting web-scraped content or individual articles.

What gets lost: <div> and <span> styling, CSS classes, colspan/rowspan in tables, inline style attributes, and embedded <iframe> content. If your HTML relied heavily on CSS classes for visual structure, the Markdown output will be structurally accurate but visually stripped down.

PDF → Text/Markdown

This is the hardest conversion because PDFs are presentation-optimized, not content-optimized. The internal structure of a PDF is a collection of positioned text elements — it doesn't preserve the semantic meaning of headings, paragraphs, or lists.

When the PDF contains real text (not scanned images), extraction tools work reasonably well:

# Using pdftotext (part of poppler-utils)
pdftotext input.pdf output.txt

# Using Pandoc (limited PDF support)
pandoc input.pdf -o output.md

When the PDF is a scanned image, you need OCR (Optical Character Recognition):

  • Tesseract (open source): tesseract input.pdf output -l eng
  • Adobe Acrobat (paid): Best commercial OCR quality
  • Google Drive: Upload a PDF, open with Google Docs — it performs OCR automatically (free)

Expect significant cleanup: OCR output typically requires fixing hyphenation breaks, removing page headers/footers that repeat, re-establishing paragraph structure, and manually identifying headings. For a 50-page scanned document, plan 2–4 hours of cleanup regardless of OCR quality.

When to use manual transcription: If the PDF contains complex layouts (multi-column, sidebars, tables with merged cells) or mathematical notation, OCR will produce unusable output. Manual transcription or a professional conversion service is often more cost-effective than cleaning up bad OCR output.

Word/DOCX → Markdown

DOCX is structurally richer than HTML or Markdown, but the conversion is surprisingly reliable for straightforward documents.

Pandoc is the go-to tool:

pandoc input.docx -o output.md --extract-media=./images

The --extract-media flag saves embedded images to a folder and creates relative references to them in the Markdown output.

What survives conversion well:

  • Headings (H1–H6)
  • Bold, italic, strikethrough
  • Unordered and ordered lists
  • Code blocks (if formatted with a monospace style)
  • Hyperlinks

What needs manual attention:

  • Tables with merged cells (converted to simple tables or lost)
  • Text boxes and callouts (often dropped entirely)
  • Custom paragraph styles (normalized to basic formatting)
  • Comments and tracked changes (usually stripped)
  • Footnotes (converted to inline references in some renderers)

Online converters: CloudConvert, Word2Markdown, and Pandoc's web interface all handle DOCX → Markdown. For occasional one-off conversions, these are faster than setting up Pandoc locally.

Conversion Quality: What to Check

After any conversion, verify these specific elements before using the output:

Element Common Issues How to Check
Tables Alignment lost, merged cells broken Review in Markdown preview
Images Broken paths, missing alt text Check rendered output visually
Code blocks Language hints missing, indentation broken Test with syntax highlighter
Links Relative vs absolute URL mismatches Click-test a sample
Headings Hierarchy flattened or skipped levels Check H1–H3 nesting
Special characters Encoding issues with non-ASCII Search for replacement characters (?)

Real-World Workflow: WordPress → Hugo Migration

Here's a concrete end-to-end example. A technical blog with 200 posts needs to migrate from WordPress to Hugo.

Step 1 — Export from WordPress Use the WordPress Exporter to download an XML file. Then use wordpress-to-hugo-exporter to convert the XML directly to Hugo-formatted Markdown files with frontmatter.

Step 2 — Batch convert and review Run the exporter script. Expect ~85% of posts to convert cleanly. The remaining 15% will have issues — typically shortcode plugins, embedded tweets/YouTube, or heavy custom HTML in specific posts.

Step 3 — Handle images Download all media from the WordPress media library. Update image paths in Markdown files (WordPress uses absolute URLs; Hugo expects paths relative to the static/ directory).

Step 4 — Fix shortcodes WordPress shortcodes like [caption] or [gallery] have no Markdown equivalent. Either replace them with standard Markdown image syntax or use Hugo shortcodes for complex cases.

Step 5 — Verify in Hugo Run hugo server, check 20–30 posts manually, run a broken link checker (linkchecker or htmlproofer), and verify all images load correctly.

Total migration effort for 200 posts: approximately 8–16 hours depending on content complexity.

FAQ

Why does conversion lose formatting even when using good tools?

Format conversion is fundamentally a lossy process when moving from a richer format to a simpler one. HTML supports hundreds of CSS properties; Markdown supports a handful of formatting options. A tool can only convert what the target format can express. When a source document uses a feature the target format doesn't support (merged table cells, sidebars, custom fonts), that feature is either dropped or approximated.

Can I batch convert multiple files automatically?

Yes. Pandoc supports batch conversion via shell scripting. For more complex workflows (DOCX files with images, PDFs requiring OCR), tools like make or simple Python scripts can orchestrate multi-step conversion pipelines across hundreds of files. For very large migrations (thousands of files), dedicated migration services may be more cost-effective.

When are paid converters worth it over free options?

Paid converters and services are worth considering for: high-volume migrations where manual cleanup time has real cost, scanned PDFs where OCR accuracy matters, documents with complex layouts that free tools handle poorly, and production workflows where consistent output quality is required. For occasional personal use, the free tools in this guide handle the vast majority of cases well.

Conclusion

Format conversion is a solved problem for common paths — Markdown → HTML, DOCX → Markdown, HTML → Markdown — with mature tools like Pandoc handling most cases reliably. The difficulty increases when converting from locked formats (PDF, especially scanned) or when source documents rely on formatting features the target format can't express.

The practical rule: for anything important, always preview the converted output before using it, and budget time for cleanup on complex documents. For routine conversions, automate with Pandoc or a dedicated tool and spend your time on the 10–15% that needs human judgment.

Published by Magic Tools