<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Doctor PDF</title>
    <description>The latest articles on DEV Community by Doctor PDF (@doctorpdfapp).</description>
    <link>https://dev.to/doctorpdfapp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3993762%2F71c7b9f9-cc99-4024-a93b-7f8d28591522.png</url>
      <title>DEV Community: Doctor PDF</title>
      <link>https://dev.to/doctorpdfapp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/doctorpdfapp"/>
    <language>en</language>
    <item>
      <title>How I built a PDF Word converter that runs 100% in the browser (no server)"</title>
      <dc:creator>Doctor PDF</dc:creator>
      <pubDate>Wed, 24 Jun 2026 14:17:33 +0000</pubDate>
      <link>https://dev.to/doctorpdfapp/how-i-built-a-pdf-word-converter-that-runs-100-in-the-browser-no-server-57a8</link>
      <guid>https://dev.to/doctorpdfapp/how-i-built-a-pdf-word-converter-that-runs-100-in-the-browser-no-server-57a8</guid>
      <description>&lt;p&gt;"Extracting text with coordinates from pdf.js, rebuilding paragraphs and tables, fixing Arabic right-to-left order, and generating a real .docx — all client-side, no upload."&lt;br&gt;
tags: javascript, webdev, pdf, opensource&lt;br&gt;
canonical_url: &lt;a href="https://doctor-pdf.com/pdf-to-word.html" rel="noopener noreferrer"&gt;https://doctor-pdf.com/pdf-to-word.html&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  cover_image:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; — I built a PDF → Word (.docx) converter that does everything in the browser: no file ever leaves the user's device. The hard parts weren't the file formats — they were &lt;em&gt;reconstructing layout&lt;/em&gt; (paragraphs, tables, headings) from a flat stream of positioned glyphs, and getting &lt;strong&gt;Arabic / right-to-left&lt;/strong&gt; text to come out in logical order. Here's how it works, with the gotchas I hit along the way. Live tool: &lt;strong&gt;&lt;a href="https://doctor-pdf.com/pdf-to-word.html" rel="noopener noreferrer"&gt;doctor-pdf.com/pdf-to-word.html&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Why client-side?
&lt;/h2&gt;

&lt;p&gt;Almost every "free" PDF tool uploads your file to a server. For contracts, IDs, and confidential documents that's a non-starter for a lot of people. Browsers are now powerful enough that the &lt;em&gt;entire&lt;/em&gt; pipeline — parsing the PDF, reconstructing the document, and writing a Word file — can run in JavaScript on the user's machine. Nothing is uploaded. That constraint shaped every decision below.&lt;/p&gt;

&lt;p&gt;The stack is intentionally boring and CDN-only:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://mozilla.github.io/pdf.js/" rel="noopener noreferrer"&gt;&lt;strong&gt;pdf.js&lt;/strong&gt;&lt;/a&gt; — read text, positions, fonts, colours, and the operator list.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docx.js.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;docx&lt;/strong&gt;&lt;/a&gt; — generate a real &lt;code&gt;.docx&lt;/code&gt; (lazy-loaded ~740 KB, only when the user clicks &lt;em&gt;Download&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; — the browser's own text shaper, which turns out to be the secret weapon for Arabic.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 1 — PDF text isn't text, it's positioned glyphs
&lt;/h2&gt;

&lt;p&gt;The first surprise for anyone new to PDFs: there are no paragraphs, no lines, often no spaces. pdf.js hands you &lt;code&gt;textContent.items&lt;/code&gt;, each roughly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invoice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fontName&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a glyph run with a position. A "line" of text might arrive as ten fragments; a visual space between two columns might be &lt;em&gt;no character at all&lt;/em&gt;, just a horizontal gap. So step one is to &lt;strong&gt;rebuild lines and spaces from geometry&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// group items into lines by their y coordinate&lt;/span&gt;
&lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// top-to-bottom&lt;/span&gt;

&lt;span class="c1"&gt;// within a line, rebuild missing spaces from the x-gap&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// a normal word space&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;   &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// a column gap → several spaces&lt;/span&gt;
  &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;fs * 0.18&lt;/code&gt; threshold (a fraction of the font size) is the single most-tuned number in the whole project. Too low and words run together; too high and you get &lt;code&gt;H e l l o&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 — From lines to paragraphs, headings, and lists
&lt;/h2&gt;

&lt;p&gt;Once you have lines, you infer structure from typography and whitespace — the same cues a human reads:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;New paragraph&lt;/strong&gt; when the vertical gap between lines jumps, when alignment changes, or when a line stops well short of the right margin (a "short last line").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heading&lt;/strong&gt; when a line's font size is meaningfully larger than the body — &lt;em&gt;or&lt;/em&gt; it's short, bold, and standalone. Important caveat I learned the hard way: in a document where &lt;strong&gt;everything&lt;/strong&gt; is bold (lots of legal letters are), "bold" carries no signal. So I compute a document-wide &lt;code&gt;boldFraction&lt;/code&gt; and only treat bold as a heading hint when bold is &lt;em&gt;uncommon&lt;/em&gt; (&amp;lt; 40%).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;List item&lt;/strong&gt; when a line starts with a bullet/number glyph.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A fun bug: bullet characters (&lt;code&gt;U+2022&lt;/code&gt;) are often drawn in a &lt;code&gt;SymbolMT&lt;/code&gt; font. Carry that font name into Word and the bullet renders as a &lt;strong&gt;□ tofu box&lt;/strong&gt;. The fix is to &lt;em&gt;drop&lt;/em&gt; the font for known symbol fonts so the bullet falls back to a Unicode-capable default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — The hard one: Arabic and right-to-left
&lt;/h2&gt;

&lt;p&gt;This is where most converters fall over. Legacy PDFs frequently emit Arabic glyphs in &lt;strong&gt;visual order&lt;/strong&gt; — i.e. already laid out left-to-right on the page — instead of logical order. Concatenate the fragments naively and you get Arabic that's reversed and, worse, mixed Arabic/Latin lines like &lt;code&gt;QUOTATION / عرض أسعار&lt;/code&gt; that come out scrambled.&lt;/p&gt;

&lt;p&gt;The reconstruction is a small bidi pass per line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// line contains Arabic drawn in visual (LTR) order →&lt;/span&gt;
&lt;span class="c1"&gt;// 1) reverse all runs to base right-to-left logical order&lt;/span&gt;
&lt;span class="nx"&gt;runs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// 2) re-flip maximal runs of Latin / digits so they read left-to-right again&lt;/span&gt;
&lt;span class="nf"&gt;flipLatinRunsBackToLTR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;runs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pure-Latin lines short-circuit out (so English documents are untouched), and the same routine runs inside table cells. The payoff: &lt;code&gt;الإمارات العربية المتحدة / Sharjah - United Arab Emirates&lt;/code&gt; comes out correct in both scripts, and the Word runs get &lt;code&gt;bidirectional: true&lt;/code&gt; + &lt;code&gt;rightToLeft: true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One more Arabic-specific gotcha: italic / sheared text. A naive "skip rotated text" watermark filter (checking the transform matrix) also kills &lt;strong&gt;faux-italic&lt;/strong&gt; text, because the shear shows up in the same matrix entries. The fix is to normalise by scale and separate &lt;em&gt;rotation&lt;/em&gt; from &lt;em&gt;shear&lt;/em&gt; before deciding to drop a run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 — Reconstructing tables geometrically
&lt;/h2&gt;

&lt;p&gt;Tables are the other place server engines usually win, because a PDF table is just… lines of text that happen to align into columns, often with rows that &lt;strong&gt;wrap across several text-lines&lt;/strong&gt;. My first attempt (split each line at big x-gaps) produced fragmented messes on real multi-column tables.&lt;/p&gt;

&lt;p&gt;The approach that actually worked is a small geometric reconstructor:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Find a region&lt;/strong&gt; — consecutive lines that each have ≥ 2 well-separated fragment groups ("anchors").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rows&lt;/strong&gt; — group fragment y-positions; a gap bigger than &lt;code&gt;fontSize * 1.5&lt;/code&gt; starts a new row, so wrapped multi-line rows &lt;em&gt;merge&lt;/em&gt; correctly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Columns&lt;/strong&gt; — cluster fragment x-positions (tolerance ~25pt) and keep clusters that appear in at least half the rows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assign&lt;/strong&gt; each fragment to its nearest column centre.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The make-or-break part is the &lt;strong&gt;precision guards&lt;/strong&gt; — what separates a real data table from a page that merely &lt;em&gt;looks&lt;/em&gt; columnar (like a two-column CV):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;cols&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="nx"&gt;fillRatio&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="nx"&gt;fullRowFraction&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;   &lt;span class="c1"&gt;// most rows fill EVERY column&lt;/span&gt;
&lt;span class="nx"&gt;headerRowFullyFilled&lt;/span&gt;        &lt;span class="c1"&gt;// kills "contact block" false positives&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fullRowFraction&lt;/code&gt; is the key signal: a genuine table has rows that fill every column (≈1.0); a sidebar layout doesn't (≈0.67). With those guards the tool reconstructs reflowed/wrapped tables that match what the commercial converters produce — while a CV's two-column layout correctly stays as prose. Borderless &lt;strong&gt;label/value info-grids&lt;/strong&gt; (the &lt;code&gt;Client | …&lt;/code&gt;, &lt;code&gt;Project | …&lt;/code&gt; block at the top of invoices) get their own lighter detector and render without grid lines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 — Carrying images
&lt;/h2&gt;

&lt;p&gt;To match diagrams in English docs and stamps/signatures in Arabic ones, I walk pdf.js's &lt;strong&gt;operator list&lt;/strong&gt;, track the current transformation matrix through &lt;code&gt;save&lt;/code&gt;/&lt;code&gt;restore&lt;/code&gt;/&lt;code&gt;transform&lt;/code&gt;, and on each &lt;code&gt;paintImageXObject&lt;/code&gt; pull the bitmap from &lt;code&gt;page.objs&lt;/code&gt;, draw it to a canvas at ~2× for sharpness, and emit a PNG. Images that overlap vertically get grouped into a single side-by-side row so figures that sit next to each other in the PDF stay next to each other in Word.&lt;/p&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Hang warning worth its own paragraph:&lt;/strong&gt; &lt;code&gt;page.objs.get(id, callback)&lt;/code&gt; will wait &lt;em&gt;forever&lt;/em&gt; if an image object never becomes ready — on some files that froze the whole conversion. The fix was to make the lookup &lt;strong&gt;synchronous and skippable&lt;/strong&gt;: &lt;code&gt;objs.has(id) ? objs.get(id) : null&lt;/code&gt;. A skipped image is infinitely better than a frozen tab.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6 — Writing the .docx
&lt;/h2&gt;

&lt;p&gt;With an ordered list of blocks (&lt;code&gt;paragraph&lt;/code&gt; / &lt;code&gt;table&lt;/code&gt; / &lt;code&gt;image&lt;/code&gt;), the &lt;a href="https://docx.js.org/" rel="noopener noreferrer"&gt;docx&lt;/a&gt; library does the heavy lifting. The thing to get right is &lt;strong&gt;fidelity of the runs&lt;/strong&gt;: explicit font size (real points), colour (only when it's &lt;em&gt;not&lt;/em&gt; near-black, so dark-mode Word doesn't get weird), bold/italic, alignment, and — a detail that bit me — set the heading run's size and colour &lt;strong&gt;explicitly&lt;/strong&gt; instead of relying on Word's &lt;code&gt;Heading2&lt;/code&gt; style, which otherwise renders everything the same size and &lt;strong&gt;blue&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextRun&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;cleanFontName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fontName&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;   &lt;span class="c1"&gt;// strip "ABCDEF+" subset prefix, map Helvetica→Arial&lt;/span&gt;
  &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;// docx uses half-points&lt;/span&gt;
  &lt;span class="na"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;italics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ital&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;nearBlack&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;rightToLeft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isArabic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Packer.toBlob()&lt;/code&gt; produces the file, and a classic &lt;code&gt;appendChild → click → remove&lt;/code&gt; anchor triggers the download. No server round-trip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things I'd tell my past self
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PDF is a &lt;em&gt;presentation&lt;/em&gt; format, not a &lt;em&gt;content&lt;/em&gt; format.&lt;/strong&gt; You're not parsing a document; you're reverse-engineering one from ink positions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tune thresholds against real files, not synthetic ones.&lt;/strong&gt; Every magic number here (&lt;code&gt;0.18&lt;/code&gt;, &lt;code&gt;1.5&lt;/code&gt;, &lt;code&gt;0.7&lt;/code&gt;) was calibrated on actual contracts, CVs, and invoices — and re-checked for regressions on every change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The browser is a great text shaper.&lt;/strong&gt; For anything involving Arabic shaping or RTL, rendering to &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; and embedding the result sidesteps a whole category of font-embedding pain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never ship a feature that can hang.&lt;/strong&gt; A wrong-but-fast result beats a correct-but-frozen tab every time. Guard every async decode with a synchronous fallback or a timeout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know your limits.&lt;/strong&gt; Damaged &lt;code&gt;ToUnicode&lt;/code&gt; maps (the PDF's own defect) extract as &lt;code&gt;�&lt;/code&gt;, and Arabic OCR isn't good enough to silently recover small/decorative text. When that happens the tool shows an honest quality banner instead of pretending.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it / read the code
&lt;/h2&gt;

&lt;p&gt;The tool is live and free, no signup, nothing uploaded: &lt;strong&gt;&lt;a href="https://doctor-pdf.com/pdf-to-word.html" rel="noopener noreferrer"&gt;doctor-pdf.com/pdf-to-word.html&lt;/a&gt;&lt;/strong&gt;. It's part of a suite of 15 browser-only PDF tools I'm building — Arabic-first, since 400M+ Arabic speakers had no real privacy-respecting option.&lt;/p&gt;

&lt;p&gt;If you're building something similar, happy to compare notes in the comments. 🔒&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
