<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Berkay Ülgüel on Medium]]></title>
        <description><![CDATA[Stories by Berkay Ülgüel on Medium]]></description>
        <link>https://medium.com/@berkayyyulguel?source=rss-ff13347bf90a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*48vEkIT5Ez04soXEMT3avQ.jpeg</url>
            <title>Stories by Berkay Ülgüel on Medium</title>
            <link>https://medium.com/@berkayyyulguel?source=rss-ff13347bf90a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:52:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@berkayyyulguel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[jsPDF UTF-8 Support]]></title>
            <link>https://medium.com/@berkayyyulguel/jspdf-utf-8-support-b7df7a76e593?source=rss-ff13347bf90a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7df7a76e593</guid>
            <category><![CDATA[utf-8]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[pdf-export]]></category>
            <category><![CDATA[jspdf]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Berkay Ülgüel]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 08:27:47 GMT</pubDate>
            <atom:updated>2022-04-19T08:27:47.933Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*c55e7yGt01fROlAS9t7C_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2xZQAhBvwZ3sNJJAOOPaGQ.png" /></figure><p>Hey devs, I assume you already know how to export a PDF document using the jsPDF library. If the answer is no, you can go and check my previous <a href="https://medium.com/@berkayyyulguel/angular-convert-html-to-pdf-via-jspdf-8c63c8c61ad9">article</a>. In this post, I will introduce a common issue about PDF files including UTF-8 characters and explain how to avoid it during a PDF export operation.</p><p>The following example shows a PDF output of a description and tags. We can see that the last 2 tags seem corrupted, and the reason is that they contain UTF-8 characters. Since the jsPDF library doesn’t support these characters automatically, we need to add a custom font family to be able to create the desired output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*U97GZ5ZvDyCnWl6bCly2oQ.png" /></figure><p>After creating a new jsPDF instance, we can console log “getFontList” and “getFont” methods to see default fonts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45150d305b29ab249e6589666cd9f36d/href">https://medium.com/media/45150d305b29ab249e6589666cd9f36d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*EGJFH_uX-CHvQlCfOBMemw.png" /><figcaption>Font List</figcaption></figure><p>None of the above works for us as they don’t support UTF-8. You can go to <a href="https://fonts.google.com/">google fonts</a> and check different types of fonts to see which one of them has the required glyphs for you. In this demo, I will use Open Sans as it works perfectly fine for my texts.</p><p>You can also select your font, charsets, and font size <a href="https://google-webfonts-helper.herokuapp.com/fonts">here</a> and download the files. I have chosen all charsets and regular font sizes for my project. Among the downloaded files, what we need is a TTF formatted file since we need to convert that file at “<a href="https://rawgit.com/MrRio/jsPDF/master/fontconverter/fontconverter.html">fontconverter</a>” to a Javascript file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*XpwNggUyWYomlCdxiIEYWQ.png" /><figcaption>Font Files</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*4wU46tWyR-OOPPaNLP9CzQ.png" /><figcaption>Font Converter</figcaption></figure><p>After you choose your font TTF file to convert, you will find a base64 encoded string within that Javascript file. You can export that string or you can copy and store it somewhere else. I have copied that encoded string and stored it in a Typescript file to export easily.</p><pre>export const OpenSansEncoded: string = &#39;AAEAAAASAQAABAAgR0RFRqOgoD8AAZxAAAABpkdQT1OT967xAAGd6AAAN4RHU1VCHQIfmgAB1WwAAAcwT1MvMpZAgywAAV2YAAAAYFNUQVRe+0M1AAHcnAAAAF5j……………&#39;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c2601f045169dee092cd91c53fdeea8/href">https://medium.com/media/4c2601f045169dee092cd91c53fdeea8/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de10c20952dc005bcdff4da3918b24e6/href">https://medium.com/media/de10c20952dc005bcdff4da3918b24e6/href</a></iframe><p>Then you can import that encoded string to use in your export method. The library itself has vFS which handles files. We need to execute 3 methods step by step. First, we add our base64 encoded string with the name of the file by calling the “addFileToVFS” function. Then we can add our custom font to the current PDF instance, and we can console log the “getFontList” to check if it has been added or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*ApqQyi20rUHFhQcQr213hQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99a2fe901b16cf82b102ddb2c65dd32a/href">https://medium.com/media/99a2fe901b16cf82b102ddb2c65dd32a/href</a></iframe><p>As we see our custom font added in the font list, we can call the “setFont” method to set our font as default. If you are planning to add texts by the jsPDF “text” method, you will see our desired UTF-8 characters are not corrupted anymore. If you try to use the jsPDF “html” method and the font you downloaded is your current project’s default font then still everything is good. However, if your project’s default font is different, then you will see nothing has changed. All you need to do is set your custom font as inline CSS to override your default font when exporting a PDF file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30a4494862c3881392a222f148e9e9ec/href">https://medium.com/media/30a4494862c3881392a222f148e9e9ec/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*U73ViK1wg9W7jKXy4AO2nw.png" /></figure><p>The project’s default font is “Verdana” which doesn’t support UTF-8 charsets. In the example above, both divs include words with UTF-8 characters. The div with description id has inline Open Sans style to override Verdana but the div with tag id doesn’t. We can see that tags are still corrupted while the description is all good. As a result, if you encounter this kind of problem, you should override your font with inline CSS.</p><p>Thanks for reading and I hope you found out the answer. I would appreciate your feedback!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7df7a76e593" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting HTML documents to PDF using jsPDF and Angular]]></title>
            <link>https://medium.com/@berkayyyulguel/angular-convert-html-to-pdf-via-jspdf-8c63c8c61ad9?source=rss-ff13347bf90a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c63c8c61ad9</guid>
            <category><![CDATA[jspdf]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[export]]></category>
            <category><![CDATA[html-to-pdf]]></category>
            <category><![CDATA[pdf]]></category>
            <dc:creator><![CDATA[Berkay Ülgüel]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 08:27:31 GMT</pubDate>
            <atom:updated>2026-08-20T17:25:15.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*c55e7yGt01fROlAS9t7C_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2xZQAhBvwZ3sNJJAOOPaGQ.png" /></figure><p>Hey, devs! In this article, I will guide you to export pure HTML elements to PDF with the advantages of the library called jsPDF. The code in this post is developed using jsPDF and Angular 12.</p><p>If you are familiar with exporting HTML to an image or PDF you may have heard html2canvas. Html2canvas renders the content as a canvas image by reading the DOM. So, can we briefly say that it takes a screenshot of the content? No, it builds the screenshot based on the page content, and of course, build time depends on the content. If you have simple content with a few texts, images, and icons in it then everything is all right. However, trying to export HTML codes with high complexity might take a terrible amount of time or even end up crashing the site. That’s why converting the whole content at once is a better idea than separating it into divs and then converting one by one. The method I will use is the jsPDF’s html function which depends on html2canvas.</p><p>I will try to explain what I have done so far step by step. Let’s start with installing the jsPDF library.</p><pre>npm install jspdf –save<br> — — — — or — — — — <br>yarn add jspdf</pre><p>As we have installed our library, we will be able to start implementing it. Creating a PDF export preview would be a great idea if we want to export multiple pages! I wanted to have a fullscreen preview to display content with 2 different page format options (A3 and A4). Giving fixed width and height will help us to export HTML without any modification afterward.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6271ce678fb4cfdf47e221347c3d9bc/href">https://medium.com/media/f6271ce678fb4cfdf47e221347c3d9bc/href</a></iframe><p>In the template, we have a container div with the all-pages class name and ngClass attribute to set page height and width. A4 pixel sizes are 595 for width and 842 for height and A3 pixel sizes are 842 for width and 1191 for height. So we can define 2 different classes which are called a4 and a3. With radio buttons on the interface and the ngClass attribute, we will be able to change the sizes based on user preference. Div with page class attached, represents single page content, you can multiply those pages with ngFor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*o5z3bJie6rLAdpjhEVSVwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*xLJIg2ddfsW5Me3ql9BEqg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68f1ace3654a279e95e8a2c05b7ef4ad/href">https://medium.com/media/68f1ace3654a279e95e8a2c05b7ef4ad/href</a></iframe><p>Query selector allows us to get HTMLElement which has an all-pages class name. As I have mentioned earlier, this element contains all displaying pages in the preview. Now it is time to import our library into the service and create the export function.</p><pre>import { jsPDF } from &#39;jspdf&#39;;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a46cdcd19047d928d857a36abcc5ebc/href">https://medium.com/media/4a46cdcd19047d928d857a36abcc5ebc/href</a></iframe><p>We generate a new jsPDF instance with the requested options. In my example, I have created radio buttons that will allow the user to select page format. After the user confirms the export operation, the state gets updated with the selected page format preference. We can get state’s value with pdfOptions.value.pageFormat. You can get the selected page format by giving an additional parameter to the export method as well.</p><p><strong>Unit:</strong> Base unit to be used when coordinates are specified (pt, px, cm, mm, etc). The default value is mm.</p><p><strong>Format:</strong> The format of pages e.g a4, a3 and so on. The default value is a4.</p><p>Note that, you can set the unit property as px and the format property with fixed values or you can set the unit as pt and the format with predefined values like a4, a3, a5, and so on. Both ways will give the same result.</p><p>After that, we execute a callback function as an option of the html method. The reason why I call deletePage function with the given getNumberOfPages parameter is to remove unnecessary last empty page. The final touch is executing the save method with the requested file name. All done, we can see the exported PDF file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOpkAW5nOtNGojc-dRerng.png" /><figcaption>Exported PDF File</figcaption></figure><p>Thanks for reading my first article. You can also check out my next <a href="https://medium.com/@berkayyyulguel/jspdf-utf-8-support-b7df7a76e593">article</a> about exporting PDF files including UTF-8 characters. I would appreciate hearing your feedback!</p><p><strong>The Server-Side Version</strong></p><p>Worth being clear this is an architecture change, not a drop-in — the export moves from Angular to your backend, and the client just downloads the result.</p><p><a href="https://ironpdf.com/nodejs/"><strong>IronPDF for Node.js</strong></a> renders with a managed Chromium engine, so the same HTML produces the same PDF regardless of who requested it:</p><p>bash</p><pre>npm i @ironsoftware/ironpdf</pre><p>javascript</p><pre>import { PdfDocument, defaultChromePdfRenderOptions, PaperSize } from &quot;@ironsoftware/ironpdf&quot;;<br><br>app.post(&quot;/export&quot;, async (req, res) =&gt; {<br>  const options = defaultChromePdfRenderOptions();<br>  options.paperSize = req.body.format === &quot;a3&quot; ? PaperSize.A3 : PaperSize.A4;<br>  options.margin = { top: 10, bottom: 10, left: 10, right: 10 };<br><br>  const pdf = await PdfDocument.fromHtml(req.body.html, { renderOptions: options });<br>  await pdf.saveAs(&quot;/tmp/export.pdf&quot;);<br>  res.download(&quot;/tmp/export.pdf&quot;);<br>});</pre><p>Your Angular side keeps the A4/A3 radio buttons and just posts the container’s innerHTML (or a route the server renders directly via fromUrl) instead of running html2canvas.</p><p><strong>Two things this also fixes</strong>, both of which you’ve hit:</p><ul><li><strong>The “might crash the site” problem</strong> you mention for complex content — rasterising a large DOM blocks the main thread. Moving it server-side means the browser stays responsive no matter how heavy the document is.</li><li><strong>UTF-8</strong> — the subject of your follow-up article. jsPDF’s default fonts don’t cover Turkish characters, hence the font-embedding workaround. A Chromium renderer handles ş ğ ı ö ü ç natively with no font registration at all, since it’s the same engine that displays them in the browser.</li></ul><p><strong>Honest note:</strong> jsPDF is free and stays entirely in the frontend, which matters if you have no backend to call — that’s a real advantage and the reason this approach is popular. IronPDF is commercial (from $999, free 30-day trial, watermarks until a licence key is set) and requires a server. It earns that when consistent cross-device output, large documents, or non-Latin text are involved.</p><p>👉<a href="https://ironpdf.com/nodejs/"> IronPDF for Node.js</a> ·<a href="https://ironpdf.com/nodejs/tutorials/html-to-pdf/"> HTML to PDF</a> ·<a href="https://ironpdf.com/nodejs/"> Free trial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c63c8c61ad9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>