Change font in PDF
-
Hi,
I’m trying to apply font-family: arial in the custom CSS but it doesn’t go through.
I can change the background, font-size, etc but not the font. It always ends up font-family: ‘Roboto’, ‘Noto’, sans-serif;
-
Hi FlatText,
CSS in the PDF is a mix of mPDF(the PDF library used to generate the PDF), the CSS in DK PDF CSS Settings, the CSS of your theme and if you’re using a plugin that outputs content in the PDF it may also affect.
try to add !important in your DK PDF CSS Settings to see if it has effect.
if you can post an URL here I could take a look, otherwise is difficult for me to figure out what’s happening.
Thanks,
EmiliHi Emil,
Thanks for replying.
I’ve tried the !important route and didn’t get anywhere.
I’d rather not show the client’s site so I used Google to shorten the URL. I’ll remove it once you have it.
Here it is: [removed]
Click on PDF Download and you’ll see the font is different than the content it’s from.
- This reply was modified 7 years, 6 months ago by FlatText.
Hi FlatText,
I checked it out, the fonts are pretty similar in my opinion. I think that the PDF is using the Sans font that comes with mPDF (it comes with a Sans, a Serif and a Courier type font), if you need to output a custom font in the PDF you have to do it tweaking the plugin, more info here:
https://mpdf.github.io/fonts-languages/fonts-in-mpdf-6-x.html
Thanks,
EmiliHi Emili,
Thanks, that did it ??
– Added arial.ttf to mpdf60/ttfonts
– Added ‘arial’ => ‘arial’ to $this->fonttrans = array
– Added “arial” => array( ‘R’ => “arial.ttf”) to $this->fontdata = array- This reply was modified 7 years, 6 months ago by FlatText.
Hi trying to change fonts as well. Can you please give instructions on how to do this, is there a function to add in my theme functions or is it to change the files within this plugin of which will be removed once the plugin is upgraded?
ThanksDK PDF is a great plugin.
Edit includes/dkpdf-functions.php change font family to one of the available fonts on mpdf60
// font size
$dkpdf_font_size = get_option( ‘dkpdf_font_size’, ’12’ );
$dkpdf_font_family = ‘trebuchet‘;You can use one of these font families defined in config_fonts.php under /mpdf60
‘times’ => ‘timesnewroman’,
‘courier’ => ‘couriernew’,
‘trebuchet’ => ‘trebuchetms’,
‘comic’ => ‘comicsansms’,
‘franklin’ => ‘franklingothicbook’,
‘ocr-b’ => ‘ocrb’,
‘ocr-b10bt’ => ‘ocrb’,
‘damase’ => ‘mph2bdamase’,Any possibility we can get custom fonts added through a filter? Or any other way to ensure custom fonts aren’t lost after a plugin update?
I second @blindmikey on that feature request. It would be very helpful to add font’s without the need to hack the plugin.
I third @blindmikey on this. FINALLY got it figured out by going into the mpdf60 folders but it’s quite the hassle especially with plugin updates.
I fourth @blindmikey on this – a system like done for the template, loading a custom mPDF folder from the themes folder would be a great solution
in /wp-content/plugins/dk-pdf/includes/dkpdf-functions.php on line 114 replace:
include('mpdf60/mpdf.php');
with somtething similar to “dkpdf_get_mpdf()” and then have checks like in “DKPDF_Template_Loader”
- This reply was modified 6 years, 10 months ago by netzgestaltung.
I edited the dkpdf-functions.php to this, i dont exactly know if thats an appropirate way:
if ( is_dir(get_template_directory() . '/dkpdf') && is_dir(get_template_directory() . '/dkpdf/mpdf60') && file_exists(get_template_directory() . '/dkpdf/mpdf60/mpdf.php') ) { include(get_template_directory() . '/dkpdf/mpdf60/mpdf.php'); } else { include('mpdf60/mpdf.php'); }
and copied the whole mpdf60 folder to <themename>/dkpdf/mpdf60
so now i only have to replace that code when an update arrives and the customized mpdf directory stays untouched.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
the same applies to DK PDF Generator in “dkpdfg-functions.php” on line 57 change:
if ( file_exists( ABSPATH . '/wp-content/plugins/dk-pdf/includes/mpdf60/mpdf.php' ) ) { include( ABSPATH . '/wp-content/plugins/dk-pdf/includes/mpdf60/mpdf.php' ); } else { require_once ABSPATH . '/wp-content/plugins/dk-pdf/vendor/autoload.php'; define( '_MPDF_TTFONTDATAPATH', sys_get_temp_dir() . "/" ); }
to
if ( is_dir(get_template_directory() . '/dkpdf') && is_dir(get_template_directory() . '/dkpdf/mpdf60') && file_exists(get_template_directory() . '/dkpdf/mpdf60/mpdf.php') ) { include(get_template_directory() . '/dkpdf/mpdf60/mpdf.php'); } else if ( file_exists( ABSPATH . '/wp-content/plugins/dk-pdf/includes/mpdf60/mpdf.php' ) ) { include( ABSPATH . '/wp-content/plugins/dk-pdf/includes/mpdf60/mpdf.php' ); } else { require_once ABSPATH . '/wp-content/plugins/dk-pdf/vendor/autoload.php'; define( '_MPDF_TTFONTDATAPATH', sys_get_temp_dir() . "/" ); }
- This reply was modified 6 years, 10 months ago by netzgestaltung.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
- This reply was modified 6 years, 10 months ago by netzgestaltung.
I have another solution to want it interested. Editing the body of the file dkpdf-index.php in your theme. Like this : <body style = “font-family: Verdana”>. At least if you use a child theme updates will not erase your changes.
Excuse my English mistakes
Nicolas
- The topic ‘Change font in PDF’ is closed to new replies.