<?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: longshixu</title>
    <description>The latest articles on DEV Community by longshixu (@x_5401f2d00c08ac20c69be4).</description>
    <link>https://dev.to/x_5401f2d00c08ac20c69be4</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3821346%2F535373a3-682e-441d-8c85-1bc9c8425dbc.png</url>
      <title>DEV Community: longshixu</title>
      <link>https://dev.to/x_5401f2d00c08ac20c69be4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/x_5401f2d00c08ac20c69be4"/>
    <language>en</language>
    <item>
      <title>How to Export a Web Page as a Vector PDF — Introducing dom-to-vector-pdf</title>
      <dc:creator>longshixu</dc:creator>
      <pubDate>Fri, 13 Mar 2026 03:34:20 +0000</pubDate>
      <link>https://dev.to/x_5401f2d00c08ac20c69be4/how-to-export-a-web-page-as-a-vector-pdf-introducing-dom-to-vector-pdf-4mm</link>
      <guid>https://dev.to/x_5401f2d00c08ac20c69be4/how-to-export-a-web-page-as-a-vector-pdf-introducing-dom-to-vector-pdf-4mm</guid>
      <description>&lt;p&gt;Hey everyone! Today I'd like to introduce an open-source library called &lt;a href="https://github.com/xzboss/dom-to-vector-pdf" rel="noopener noreferrer"&gt;dom-to-vector-pdf&lt;/a&gt;. It exports rendered DOM elements directly as &lt;strong&gt;vector PDFs&lt;/strong&gt;, entirely in the browser — no server required.&lt;/p&gt;




&lt;h2&gt;
  
  
  Live Demo
&lt;/h2&gt;

&lt;p&gt;Want to try it before reading? Check out the &lt;a href="https://dom-to-vector-pdf.xzboss.cn/vue-example" rel="noopener noreferrer"&gt;online demo&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Documentation
&lt;/h2&gt;

&lt;p&gt;Full configuration options, lifecycle hooks, and more can be found in the official docs: &lt;a href="https://dom-to-vector-pdf.xzboss.cn" rel="noopener noreferrer"&gt;dom-to-vector-pdf.xzboss.cn&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is a Vector PDF?
&lt;/h2&gt;

&lt;p&gt;The most common approach to exporting a web page as PDF is via canvas (e.g. html2canvas), which essentially takes a screenshot. The result is a rasterized image: it blurs when zoomed in, text cannot be selected, and file sizes tend to be large.&lt;/p&gt;

&lt;p&gt;A vector PDF is different — text, shapes, and paths are all stored as vectors. It stays sharp at any zoom level, text is selectable and copyable, and print quality is noticeably better. For reports, contracts, and document-style pages, vector PDF is the right choice.&lt;/p&gt;




&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;Install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;dom-to-vector-pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usage:&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;import&lt;/span&gt; &lt;span class="nx"&gt;fontTTF&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/assets/your-font.ttf&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;vectorInstance&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dom-to-vector-pdf&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;exportToPDF&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;vectorInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerFont&lt;/span&gt;&lt;span class="p"&gt;([&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="nx"&gt;fontTTF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontWeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;400&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;normal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&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="nx"&gt;fontTTF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontWeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;700&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;normal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="nx"&gt;vectorInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exportPDF&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;filename&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;Call &lt;code&gt;exportToPDF('#my-content', 'report.pdf')&lt;/code&gt; to export the target DOM area as a PDF file.&lt;/p&gt;




&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;The core pipeline is: &lt;strong&gt;DOM → SVG → PDF&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/felixfbecker/dom-to-svg" rel="noopener noreferrer"&gt;dom-to-svg&lt;/a&gt;: Serializes the DOM into SVG, preserving styles, layout, and font information&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yWorks/svg2pdf.js" rel="noopener noreferrer"&gt;svg2pdf.js&lt;/a&gt;: Renders the SVG as vector content onto the jsPDF canvas&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/parallax/jsPDF" rel="noopener noreferrer"&gt;jsPDF&lt;/a&gt;: Generates and downloads the final PDF file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The SVG serialization step adds a small overhead, but performance is generally fine for most pages. If export is slow, the font file size is usually the culprit — subsetting the font is the most effective optimization.&lt;/p&gt;




&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Non-Latin characters appear garbled — how do I fix it?
&lt;/h3&gt;

&lt;p&gt;Characters like Chinese require a font to be registered manually, otherwise they will not render correctly. Pass a TTF font file to &lt;code&gt;registerFont&lt;/code&gt; (supports both local &lt;code&gt;import&lt;/code&gt; and online CDN URLs).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Things to watch out for:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Only TTF format is currently supported&lt;/li&gt;
&lt;li&gt;Font files can be subsetted — a common Chinese character set (3500 chars) can be trimmed down to under 1 MB, significantly reducing file size and export time&lt;/li&gt;
&lt;li&gt;⚠️ Many online subsetting tools strip the space character, which causes rendering failures. It's recommended to use a command-line tool like &lt;code&gt;pyftsubset&lt;/code&gt; to subset fonts, and make sure to include the space and newline characters explicitly&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;If you run into any issues or have feature requests, feel free to open an Issue or Pull Request on &lt;a href="https://github.com/xzboss/dom-to-vector-pdf" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>opensource</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
