Converting PDF to Dynamic HTML Certificate
Converting PDF to Dynamic HTML Certificate
Transforms source documents (PDF, MarkItDown markdown, or raw extracted text) into corporate-styled, print-ready HTML with dynamic variables, without altering legal/textual content.
Given a PDF or markdown source, produce exactly two deliverables:
documento.html— modern HTML, A4-print-ready, with{{snake_case_variables}}for all dynamic fieldsvariables_documento.txt— complete list of every variable used, no duplicates, no orphans
Minimal HTML skeleton to start from:
HTML<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Red+Hat+Display:wght@400;500;600;700;800&display=swap" rel="stylesheet"> <style> :root { --chn-blue: #002159; --chn-blue-2: #00599B; --chn-red: #EE2624; --line: #d7dee5; --soft: #f5f8fb; } * { font-family: 'Red Hat Display', sans-serif; box-sizing: border-box; } @page { size: A4 portrait; margin: 9mm; } @media print { -webkit-print-color-adjust: exact; print-color-adjust: exact; } .header { position: relative; padding-top: 14px; } .header:before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 6px; background: linear-gradient(90deg, #002159 0 72%, #EE2624 72% 100%); } .institution { color: var(--chn-blue-2); font-weight: 600; font-size: 13px; } .title { color: var(--chn-blue); font-weight: 800; font-size: 22px; } .section { background: var(--chn-blue); color: #fff; font-weight: 700; padding: 8px 14px; border-radius: 6px; margin: 14px 0 8px; border-left: 5px solid var(--chn-red); } .input { border: 1px solid var(--line); background: var(--soft); border-radius: 4px; padding: 4px 8px; font-size: 13px; } table { border-collapse: collapse; width: 100%; } th { background: #edf5fa; color: var(--chn-blue); border: 1px solid var(--line); padding: 6px; } td { border: 1px solid var(--line); padding: 6px; } </style> </head> <body> <header class="header"> <div class="institution">{{nombre_institucion}}</div> <div class="title">{{nombre_documento}}</div> </header> <!-- sections follow --> </body> </html>
Progress:
- [ ] Step 1: Ingest source (PDF / MarkItDown markdown / raw text)
- [ ] Step 2: Map document structure (headers, sections, tables, fields, signatures, legal text, page numbers)
- [ ] Step 3: Transcribe content verbatim — no summarizing, correcting, or inventing data
- [ ] Step 4: Identify every dynamic data point → convert to {{snake_case_variable}}
- [ ] Step 5: Build HTML with corporate CSS (palette, Red Hat Display, A4 print rules)
- [ ] Step 6: Insert inputs/radios for variables using size classes (small/medium/large)
- [ ] Step 7: Handle repeating rows (beneficiario_1, _2, _3...) based on source count
- [ ] Step 8: Generate variables_<documento>.txt from all {{...}} found in HTML
- [ ] Step 9: Validate (regex cross-check, duplicates, @page A4, fonts, colors, legal text intact)
- [ ] Step 10: Deliver documento.html + variables_documento.txt
Step detail
Step 1-2 (Ingest & map): If given a PDF, enumerate pages, headers, titles, sections, tables, fillable fields, signature blocks, legal disclaimers, footers, and page numbers before writing any HTML. If MarkItDown output is provided, use it as structural source but cross-check against the original PDF when available.
Step 3 (Content fidelity — non-negotiable):
- DO NOT: summarize, correct, reinterpret, remove clauses, change resolution numbers, institution names, dates, percentages, or invent data.
- MAY freely change: HTML, CSS, visual structure, field layout, spacing, hierarchy, table presentation.
Step 4 (Variables): Convert every data point that must be supplied dynamically into {{snake_case}}. Rules:
- lowercase, snake_case, no spaces
- descriptive and consistent across the whole document
- avoid ambiguous names (
{{dato}},{{valor}},{{campo1}}) - prefer precise names (
{{fecha_inicio_vigencia}},{{suma_asegurada_1}})
Step 6 (Input sizing):
HTML<input class="input" value="{{primer_nombre}}"> <input class="input inline-input small-input" value="{{edad}}"> <input class="input inline-input medium-input" value="{{dpi_pasaporte}}"> <input class="input inline-input large-input" value="{{nombre_completo}}">
Radio buttons keep a variable per option, or collapse to one result variable depending on the target processing system:
HTML<label><input type="radio" name="sexo" value="{{sexo_m}}"> M</label> <label><input type="radio" name="sexo" value="{{sexo_f}}"> F</label>
Step 7 (Repeating rows): Number sequentially (_1, _2, _3...) based on how many rows the source document actually has, or what the user requests. Never fabricate an arbitrary large number of rows.
Step 8 (Variables file format):
LISTADO DE VARIABLES
====================
{{poliza_no}}
{{certificado_no}}
{{contratante}}
{{primer_nombre}}
{{primer_apellido}}
...
Total: N variables
Step 9 (Validation checklist):
- Every
{{variable}}in HTML appears in the .txt, and vice versa (no orphans, no missing) - No duplicates in the .txt
- Regex
\{\{[a-zA-Z0-9_]+\}\}used to extract and cross-check - HTML contains
@page { size: A4 portrait; margin: 9mm; } - Font
Red Hat Displayis imported and applied - Colors
#002159,#00599B,#EE2624present in CSS - All main sections of source document are represented
- Legal/disclaimer text is unabridged, word-for-word
Example 1: Input: PDF insurance certificate with fields "No. de Póliza: ______", "Nombre del Asegurado: _____", "Fecha de Emisión: //", a beneficiaries table with 3 blank rows, and a legal consent paragraph. Output:
documento.htmlwith header (institution + title), a.sectionbar "I. Datos del Asegurado", inputs{{poliza_no}},{{nombre_asegurado}},{{fecha_emision}}, a table with 3 rows using{{beneficiario_1_nombre}}…{{beneficiario_3_porcentaje}}, and the consent paragraph reproduced verbatim in a styled text block.variables_documento.txtlisting all 11 variables used, total count at the end.
Example 2:
Input: MarkItDown markdown of a bank account opening form with a "Sexo: M / F" checkbox field.
Output: HTML radio group using {{sexo_m}} / {{sexo_f}} (or single {{sexo}} if user specifies single-variable processing), documented accordingly in the txt file.
- Always build the structural outline (sections list) before writing CSS/markup — content fidelity first.
- Use
.sectionbars (dark blue, red accent) to replace outdated boxed/bordered PDF section headers. - Keep table headers light blue (
#edf5fa) with blue text (#002159) and#d7dee5borders — never gradient or saturated colors. - Default to the fixed palette and Red Hat Display unless the user explicitly provides a different brand.
- Keep page breaks logical: don't let a section or table split awkwardly — use
break-inside: avoidon.section/table wrappers for print. - When uncertain about variable granularity (e.g., full name vs. first/last name), mirror how the source document separates the fields.
- Do NOT summarize or "clean up" legal paragraphs — reproduce them exactly.
- Do NOT invent beneficiary rows, dates, or percentages that aren't in the source.
- Do NOT use vague variable names like
{{campo1}}or{{valor}}. - Do NOT forget to sync the
.txtfile — every variable must appear in both files, zero duplicates. - Do NOT use decorative gradients, heavy shadows, or off-palette colors — this is a corporate insurance/banking document, not a marketing page.
- Do NOT skip the
@page A4andprint-color-adjust: exactrules — the HTML must print cleanly. - Do NOT hardcode a placeholder as plain visual text when the user explicitly requested variables inside
<input>elements.