PHP 7 HTML2PDF.JS Script to Add Custom TTF Fonts to PDF Document

You are currently viewing PHP 7 HTML2PDF.JS Script to Add Custom TTF Fonts to PDF Document

PHP 7 HTML2PDF.js Script to Add Custom TTF Fonts to PDF Document

<span class="hljs-variable">$html2pdf</span>->setDefaultFont(<span class="hljs-string">"the_name_you_called_your_font"</span>);
 

<span class="hljs-variable">$html2pdf</span>->AddFont(<span class="hljs-string">'opensans'</span>, <span class="hljs-string">'normal'</span>, <span class="hljs-string">'opensans.php'</span>);
<span class="hljs-variable">$html2pdf</span>->setDefaultFont(<span class="hljs-string">'opensans'</span>);
 

<span class="hljs-keyword">default</span>: opensans
bold: opensansb
italic: opensansi
bold italic: opensansbi

<span class="hljs-variable">$html2pdf</span>->addFont(<span class="hljs-string">'opensansregular'</span>, <span class="hljs-string">''</span>, <span class="hljs-string">'opensansregular'</span>);
<span class="hljs-variable">$html2pdf</span>->addFont(<span class="hljs-string">'opensansbold'</span>, <span class="hljs-string">''</span>, <span class="hljs-string">'opensansbold'</span>);
 

<style type=<span class="hljs-string">"text/css"</span>>
<!--
.uppercase {
    text-transform: uppercase;
}
* {
    font-family: opensansregular;
}
h1, h2, h3, strong {
    font-family: opensansbold;
}
-->
</style>

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply