Converting Documents to Webpages
YAML--- name: converting-documents-to-webpages description: Converts PDFs, Word docs, and PowerPoint presentations into styled HTML webpages while preserving original text, images, fonts, colors, and layout. Use when a source document (PDF/DOCX/PPTX) needs to become a faithful, browsable webpage that retains its visual identity and theme. ---
Given Notes.pdf, produce notes.html + assets/ folder:
- Open the document and extract raw text, images, and style metadata (fonts, colors, spacing).
- Save extracted images into an
assets/folder next to the output HTML. - Build an HTML file that mirrors the document's structure (headings, paragraphs, image placement) and embeds/links the extracted images.
- Derive a CSS theme (color palette, font stack) from the document and apply it via a
<style>block or linked stylesheet. - Open the HTML in a browser and visually diff it against the original document.
HTML<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Notes</title> <style> body { font-family: 'Calibri', sans-serif; color: #222222; background: #ffffff; } h1 { color: #1F4E79; font-family: 'Georgia', serif; } img { max-width: 100%; height: auto; display: block; margin: 1em 0; } .content { max-width: 800px; margin: 0 auto; padding: 2em; } </style> </head> <body> <div class="content"> <h1>Section Title</h1> <p>Extracted paragraph text...</p> <img src="assets/image1.png" alt="Extracted graph"> </div> </body> </html>
Progress:
- Step 1: Open source document and identify structural sections (title, headings, body, captions)
- Step 2: Extract all embedded media (images, charts, graphs) into an
assets/folder with descriptive filenames - Step 3: Identify styling — fonts used, heading/body colors, background colors, accent colors
- Step 4: Extract text content in reading order, preserving paragraph breaks and emphasis (bold/italic)
- Step 5: Map document structure to semantic HTML (
h1-h6,p,ul/ol,table,figure/figcaption) - Step 6: Build a CSS theme file from extracted fonts/colors (define as CSS variables for reuse)
- Step 7: Assemble the HTML, embedding images with correct relative paths and alt text
- Step 8: Preview in browser and compare against the original page-by-page
- Step 9: Fix layout mismatches (spacing, image sizing, font fallbacks for missing web fonts)
Extraction details
- Images: extract at original resolution; don't screenshot pages. Name files by content/order (
fig1-chart.png) not generic names. - Fonts: if the document uses a non-web-safe font, map it to the closest Google Font or system font stack and note the substitution.
- Colors: sample heading color, body text color, background, and any accent/highlight colors. Store as CSS custom properties:
CSS
:root { --color-primary: #1F4E79; --color-text: #222222; --color-bg: #ffffff; --font-heading: 'Georgia', serif; --font-body: 'Calibri', sans-serif; } - Layout: multi-column PPT slides become
flex/gridsections; single-column docs become a centered max-width container.
Example 1:
Input: report.docx with a blue-themed title page, two charts, and body text in Calibri.
Output: report.html + assets/chart1.png, assets/chart2.png with :root CSS variables --color-primary: #2E5AAC, --font-body: 'Calibri', sans-serif, headings styled with the primary color, charts embedded as <figure> elements with captions.
Example 2:
Input: pitch.pptx, 10 slides, dark background theme with white text and a logo on every slide.
Output: One HTML page with 10 <section class="slide"> blocks (or 10 linked HTML files), each inheriting --color-bg: #121212; --color-text: #ffffff;, logo extracted once to assets/logo.png and reused via CSS background-image or <img> in a shared header/footer.
- Preserve reading order, not just visual position — screen readers and text selection depend on it.
- Use semantic HTML (
h1-h6,figure,blockquote,table) instead of genericdiv/spanfor everything; it keeps structure faithful and improves accessibility. - Extract theme colors/fonts into CSS variables once, then reference them everywhere — makes later theme tweaks a one-line change.
- Compress extracted images (PNG for graphics/screenshots, JPEG for photos) to keep page weight reasonable.
- Always add
alttext to images, generated from captions or nearby text if available. - Keep a consistent naming convention for assets (
page1-img1.png) so large documents stay organized. - For multi-page documents, decide upfront: one long scrolling HTML page, or multiple linked pages (mirrors PPT slides well; mirrors long reports poorly).
- Don't screenshot entire pages as images — this destroys text selectability, SEO, and accessibility.
- Don't hardcode pixel-perfect absolute positioning copied from a PDF; it breaks on different screen sizes. Use flow-based layout (flex/grid) that approximates the original design.
- Don't skip font-fallback stacks — if the original font isn't web-safe or licensed for web embedding, always specify a fallback.
- Don't leave images unoptimized (multi-MB PNGs) — this makes the resulting webpage slow.
- Don't flatten headings into styled
<p>tags — this breaks document outline/SEO/accessibility. - Don't rely purely on manual copy-paste for large documents — for anything beyond a few pages, use a scriptable extraction approach (e.g., a PDF/DOCX parsing library) to avoid missed content and manual errors.