Rich Text & Word to PDF Converter
Convert formatted text, Google Docs, or Word clipboard content into clean A4 PDF documents while preserving bolding, headers, lists, and colors.
Technical Architecture: Reverse-Engineering Clipboard Ingestion & Print Layout​
Copy-pasting styled content from Microsoft Word, Google Docs, or Apple Pages injects hundreds of proprietary MSO tags (e.g. <!--[if gte mso 9]>, class="MsoNormal"). This converter normalizes the DOM tree into clean semantic HTML before applying A4 print styles and compiling the PDF.
1. Clipboard HTML Sanitization & Normalization​
When pasted into the ContentEditable container, the ingestion pipeline strips proprietary Microsoft Office metadata while preserving structural semantic formatting:
function cleanPastedWordHtml(rawHtml: string): string {
// Strip MSO header and comment blocks
let clean = rawHtml.replace(/<!--[\s\S]*?-->/g, '');
clean = clean.replace(/<o:p>[\s\S]*?<\/o:p>/g, '');
clean = clean.replace(/class="MsoNormal"/g, '');
// Preserve core semantic elements: <b>, <i>, <ul>, <ol>, <h1>-<h3>, <table>
return clean;
}
2. High-DPI Canvas Rendering & Multi-Page Calculation​
To prevent low-resolution raster artifacts on high-DPI and Retina screens, the document is rasterized using a 2x device pixel ratio scale factor before generating PDF pages:
import html2pdf from 'html2pdf.js';
function exportRichTextToPdf(element: HTMLElement, filename: string) {
const options = {
margin: [15, 15, 15, 15], // 15mm margins
filename: `${filename}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true, letterRendering: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
};
html2pdf().set(options).from(element).save();
}
Supported Rich Text Formatting Attributes​
| Formatting Feature | Clipboard Source | Implementation Note |
|---|---|---|
| Typography Hierarchy | Word / Google Docs H1–H3 | Scaled with proportional line heights |
| Lists | Bulleted (<ul>) & Numbered (<ol>) | Native indentation and margin preservation |
| Inline Styles | Bold, Italic, Underline, Strikethrough | Rendered with standard font weights |
| Text Colors | Hex & RGB text colors | High-contrast reproduction |
| Page Sizing | ISO Standard A4 (210 × 297 mm) | Automatic page breaks between long sections |
Client-Side Security & Zero-Server Data Isolation​
- Pure Local Execution: 100% of clipboard parsing, styling, and PDF assembly occurs in your local browser thread. Private legal memos, resumes, and proprietary corporate documents are never uploaded to any server.
- Ephemeral Memory State: Pasted rich text is not written to
localStorageor transmitted across background network requests. - Zero Telemetry on Content: Document titles and clipboard data remain completely private.
Get notified about updates to this tool
No spam. Just high-quality updates about new features and guides.
Related Tools​
Related Posts​
Learn how to create, style, and decode 1D barcodes and 2D codes in Python. Master python-barcode, Pillow rendering options (including removing label text), pyzbar, and OpenCV decoding.
You can check the history of a specific line in VS Code using the built-in features or the specific view. You can also install the free extension.
A comprehensive guide to working with QR codes in Python. Learn how to generate custom QR codes, embed brand logos, decode images, parse vectors (SVG), handle video arrays, and host online links.


