This topic is locked

Optimizing dompdf

11/9/2017 8:35:50 AM
PHPRunner General questions
mbintex author

Hi all,
all my apps with PHPrunner use the dompdf plugin for exporting to PDF. That work´s fine.
But the fonts inside DOMPDF are about 40 MB and these 40 MB get copied to my webspace for every installation of a PHPrunner app. Currently I have 60 databases for customers and therefor 60*40 MB of fonts saved.
Is there any possibility to tell phprunner to use fonts from one central folder for all installations?
Thanks in advance
I have already tried editing the file dompdf_config.inc.php with the line

def("DOMPDF_FONT_DIR", DOMPDF_DIR . "http://www.mywebsite.com/dompdffonts/";);


and copied the fonts folder to this address.
But then I get a message that in line 234 of font_mectrics.cls.php an error appears. So I changed that to

$dist_fonts = require_once "http://www.mywebsite.com/dompdffonts/dompdf_font_family_cache.dist.php";;


Now I get another error "Uncaught DOMPDF Exception: unable to find a suitable fon replacement" ...

mbintex author 11/9/2017

This is actually what I am doing.
Now I´d like to save space and upload effort by using common components - the fonts folder is the first try, since that is much of the whole upload

HJB 11/9/2017



This is actually what I am doing.
Now I´d like to save space and upload effort by using common components - the fonts folder is the first try, since that is much of the whole upload


https://stackoverflow.com/questions/14612531/create-pdf-with-dom-pdf-outside-dompdf-directory
... found this, say, an option to activate ENABLE_REMOTE_PDF is mentioned ..., which practically

means at least to me, there is ONE directory with DOMPDF fonts from where other REMOTE pages are

fed with functionality on PDF generation. For inspiration purposes only ...

mbintex author 11/9/2017

Thanks for your efforts.
But I think that is not the solution here - the files to render aren´t remote, they are locally from the current phprunner app-site.
The only thing that should be somehow centralized is the font folder.
I think I have to change dompdf_font_family_cache.dist.php too, since there are a bunch of links inside to the fonts, but I don´t get it right somehow.

<?php return array (

'arial' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arialuni',

/* 'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',*/

),

/* 'arial' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arial',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

),
... and so on ...
HJB 11/9/2017



Thanks for your efforts.
But I think that is not the solution here - the files to render aren´t remote, they are locally from the current phprunner app-site.
The only thing that should be somehow centralized is the font folder.
I think I have to change dompdf_font_family_cache.dist.php too, since there are a bunch of links inside to the fonts, but I don´t get it right somehow.

<?php return array (

'arial' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arialuni',

/* 'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',*/

),

/* 'arial' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arial',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

),
... and so on ...



Okay, noted. At least me is thinking, in this connection, that anything seen OUTSIDE the content of the WWW directory is REMOTE (even it is within the same web root, but other web directory like in your case) while usually the term REMOTE is understood to be a REMOTE hard- and software location, other than your system, somewhere on this planet.

mbintex author 11/10/2017

gave it a try and change "remote ..." to true.
Doesn´t change anything - still get
Uncaught DOMPDF_Exception: Unable to find a suitable fon replacement for: helvetica, arial, sans serif

HJB 11/10/2017



gave it a try and change "remote ..." to true.
Doesn´t change anything - still get
Uncaught DOMPDF_Exception: Unable to find a suitable fon replacement for: helvetica, arial, sans serif


quote excerpt ex https://groups.google.com/forum/#!topic/dompdf/3oBN-fpob8k
Just a guess, but is magic_quotes enabled on your deployment server? I

believe this may be the source of the error you are receiving.

magic_quotes will encode any text imported using file_get_contents().

This function is used to load the font map. You can either disable

magic_quotes_runtime on your deployment server, or temporarily disable

it in your script using "set_magic_quotes_runtime(false);"

-b

unquote
quote ditto

that did the trick. your guess is spot on. i was just comparing all the differences in phpinfo for php 5.2.11 and php 5.3 installations; and you posted.
i immediately turned it off in php.ini and it worked perfect.

its working now. thanks a lot.

unquote

mbintex author 11/10/2017

seems that I can´t edit the php.ini myself on the server.
Tried
set_magic_quotes_runtime(0);
in the login-script, as proposed here: https://stackoverflow.com/questions/2217955/how-can-i-replace-the-deprecated-set-magic-quotes-runtime-in-php
but get
Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime()
with this.
Server is Running PHP 7.x

HJB 11/10/2017



seems that I can´t edit the php.ini myself on the server.
Tried
set_magic_quotes_runtime(0);
in the login-script, as proposed here: https://stackoverflow.com/questions/2217955/how-can-i-replace-the-deprecated-set-magic-quotes-runtime-in-php'>https://stackoverflow.com/questions/2217955/how-can-i-replace-the-deprecated-set-magic-quotes-runtime-in-php
but get
Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime()
with this.
Server is Running PHP 7.x


Okay, noted. It is definitely a problem caused by configuration, versions and subsequently deprecated code where one would need to drill very deep into it, consuming a lot of time.

Anyway, found this:

quote excerpt ex https://stackoverflow.com/questions/2217955/how-can-i-replace-the-deprecated-set-magic-quotes-runtime-in-php'>https://stackoverflow.com/questions/2217955/how-can-i-replace-the-deprecated-set-magic-quotes-runtime-in-php

add these code into the top of your script to solve problem

@set_magic_quotes_runtime(false);

ini_set('magic_quotes_runtime', 0);

unquote

and cannot say whether it could work, it's untested and so, just for inspiration purposes only ...

mbintex author 11/10/2017
@set_magic_quotes_runtime(false);

ini_set('magic_quotes_runtime', 0);


used that, thanks, but same error as before

mbintex author 11/10/2017

To my findings the real big thing in the dompdf fonts folder provided by Xlinesoft is the font file
arialuni.ttf
This one file alone is 22731 KB heavy.
So I deleted that and edited dompdf_font_family_cache.dist.php to

<?php return array (

/* 'arial' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arialuni',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

),*/

'glyphicons halflings' =>

array (

'normal' => DOMPDF_FONT_DIR . '/lib/fonts/glyphicons-halflings-regular',

),



'Source Sans Pro' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arial',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

),



'Calibri' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arial',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

),



'Candara' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arial',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

),





'arial' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/arial',

'bold' => DOMPDF_DIR . '/lib/fonts/arialb',

'italic' => DOMPDF_DIR . '/lib/fonts/ariali',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/arialbi',

),

'sans-serif' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Helvetica',

'bold' => DOMPDF_DIR . '/lib/fonts/Helvetica-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-Oblique',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-BoldOblique',

),

'times' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Times-Roman',

'bold' => DOMPDF_DIR . '/lib/fonts/Times-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Times-Italic',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Times-BoldItalic',

),

'times-roman' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Times-Roman',

'bold' => DOMPDF_DIR . '/lib/fonts/Times-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Times-Italic',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Times-BoldItalic',

),

'courier' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Courier',

'bold' => DOMPDF_DIR . '/lib/fonts/Courier-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Courier-Oblique',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Courier-BoldOblique',

),

'helvetica' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Helvetica',

'bold' => DOMPDF_DIR . '/lib/fonts/Helvetica-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-Oblique',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Helvetica-BoldOblique',

),

'zapfdingbats' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats',

'bold' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats',

'italic' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/ZapfDingbats',

),

'symbol' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Symbol',

'bold' => DOMPDF_DIR . '/lib/fonts/Symbol',

'italic' => DOMPDF_DIR . '/lib/fonts/Symbol',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Symbol',

),

'serif' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Times-Roman',

'bold' => DOMPDF_DIR . '/lib/fonts/Times-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Times-Italic',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Times-BoldItalic',

),

'monospace' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Courier',

'bold' => DOMPDF_DIR . '/lib/fonts/Courier-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Courier-Oblique',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Courier-BoldOblique',

),

'fixed' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/Courier',

'bold' => DOMPDF_DIR . '/lib/fonts/Courier-Bold',

'italic' => DOMPDF_DIR . '/lib/fonts/Courier-Oblique',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/Courier-BoldOblique',

),

'dejavu sans' =>

array (

'bold' => DOMPDF_DIR . '/lib/fonts/DejaVuSans-Bold',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSans-BoldOblique',

'italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSans-Oblique',

'normal' => DOMPDF_DIR . '/lib/fonts/DejaVuSans',

) ,

'dejavu sans light' =>

array (

'normal' => DOMPDF_DIR . '/lib/fonts/DejaVuSans-ExtraLight',

),

'dejavu sans condensed' =>

array (

'bold' => DOMPDF_DIR . '/lib/fonts/DejaVuSansCondensed-Bold',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSansCondensed-BoldOblique',

'italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSansCondensed-Oblique',

'normal' => DOMPDF_DIR . '/lib/fonts/DejaVuSansCondensed',

),

'dejavu sans mono' =>

array (

'bold' => DOMPDF_DIR . '/lib/fonts/DejaVuSansMono-Bold',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSansMono-BoldOblique',

'italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSansMono-Oblique',

'normal' => DOMPDF_DIR . '/lib/fonts/DejaVuSansMono',

),

'dejavu serif' =>

array (

'bold' => DOMPDF_DIR . '/lib/fonts/DejaVuSerif-Bold',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSerif-BoldItalic',

'italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSerif-Italic',

'normal' => DOMPDF_DIR . '/lib/fonts/DejaVuSerif',

),

'dejavu serif condensed' =>

array (

'bold' => DOMPDF_DIR . '/lib/fonts/DejaVuSerifCondensed-Bold',

'bold_italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSerifCondensed-BoldItalic',

'italic' => DOMPDF_DIR . '/lib/fonts/DejaVuSerifCondensed-Italic',

'normal' => DOMPDF_DIR . '/lib/fonts/DejaVuSerifCondensed',

),

) ?>


plus I out-commented

define("DOMPDF_DEFAULT_FONT", "arial");


in dompdf_config.custom.inc.php
This way everything works without any error messages and my upload is >20 MB lighter, which makes between 50 and 30% of my whole upload :-)
Only problem that persists currently is, that the headers aren´t printed to PDF with a sans serif font, but with Times, which looks a bit funny.
Any ideas?

mbintex author 11/10/2017

and now another approach.
Since arialuni.ttf is the big one, I searched for a free replacement. Found some here
https://www.digitaldownloads.io/arial-font-free-download/
Downloaded Mytupi-Font and uploaded that to the dompdf fonts folder renamed as arialuni.ttf to replace the big fat one.
Reverted all other changes on dompdf settings to standard and guess what. Everything works, PDFs get generated, headline fonts are correct and everything. So far I can´t see any bad side effects :-)
If that´s it, it would be an easy way to offer pdf export and save 20 MB of webspace and upload :-)