cooltronicpl / Craft-document-helpers

Craft CMS 3 and 4, 5 alpha, beta plugin enabling PDF document generation from template Twig files, code blocks and URLs
Other
12 stars 6 forks source link

Default font error message #15

Closed arentsen closed 1 year ago

arentsen commented 1 year ago

Hi guys, since the latest update of the plugin, I get the following error message:

Cannot find TTF TrueType font file "DejaVuSerifCondensed.ttf" in configured font directories.

I downloaded the font and added it to the config folder, but it did not solve it. The font file is present in the vendor/mpdf/mpdf/ ttfonts folder.

But in the templates, I only use Arial and no other fonts. Any help would be really appreciated, since this causes an internal server error. Thanks!

cooltronicpl commented 1 year ago

The variable was changed from fontDirsto fontDir. There was some misconfiguration in the code and this variable was corrected. Are you using 0.x for 3 or 1.x for 4? Now after updating to the 4.x branch also have a problem with this variable. We'll try to fix, it to pass the absolute path as follows on Linux, but we think that was changed due to some changes in MPDF package which is updated when you update a plugin, this is a path of config for some ISP Config 3.2 host: fontDir: "/var/www/clients/client0/web21/private/config/" When you have only one site it should be an absolute path to in server. fontDir:"/path_to/config/" Also, I confirmed it works on XAMPP in Windows hosts properly now like that: fontDir: "file:///C:/xampp/htdocs/craft4/" I'm sorry for the long response time, but I must check this config in my client site because the client told me about the changed variable after running the composer update, and also updated recently to craft 4.x and it works on some site on his backup with Craft 3.x after running especially updates of MPDF (only composer update), which are highly recommended. Also on Craft 4.x with some Google Fonts TTF also I run his config on Windows hosts with plugin 0.x and 1.x versions after updating only MPDF package, and there were some security updates in all branches, so passing paths work now differently.

arentsen commented 1 year ago

Hi, thanks for your response. I have a multi-site on Craft and am stilling running Craft 3 (latest version). I have still not been able to solve this issue and had to temporarily stop using the plugin.... It would be great to be able to use it again!

cooltronicpl commented 1 year ago

Is everything working fine when the absolute path is passed to a variable? We think that was caused by MPDF on which PDF Generator is built because the issue is also on old versions of our plugin when we update only MPDF package (it is updated so) also on 3.x or 4.x. We think this can be, also itself from PHP, because there were some changes about paths some time ago in all PHP versions as security updates.

arentsen commented 1 year ago

Where would I have to change the fontDir variable to the absolute path? In a config file, or in the plugin files itself? And where would that be? Thanks

cooltronicpl commented 1 year ago

In variable fontDir in array with options like fontDir: "/var/www/config", also in this folder must be a TTF font. Example:

{% set pdfOptions = {
    fontDir: "/var/www/config"
} %}
{{craft.documentHelper.pdf("_pdf/document.twig", "file",  'pdf/' ~ entry.id ~ '.pdf' ,entry, pdfOptions)}}" 
arentsen commented 1 year ago

Everything seems to be working fine in my local environment! Thanks a lot