-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Font file path is not configured correctly for tcpdf #137
Comments
I think I did not yet understand the issue, but I try to explain what I believe is the current behaviour. The path So TCPDF will find its own fonts, as we do not overwrite pdfviewhelpers/Classes/Model/BasePDF.php Lines 293 to 314 in 32c6bcd
Does our approach with overwriting the font file path in |
We have a class CustomPdf that extends \Bithost\Pdfviewhelpers\Model\BasePDF and added two custom fonts:
In the CustomPdf we create a header: public function basePdfHeader() {
$this->SetFont('univers');
$slogan = '<div style="font-weight:bold;">Bold</div>';
$this->writeHTMLCell(0, 0, 31.5, $this->y, $slogan, 0, 0, false, true, 'L', true);
} The writeHTMLCell tries to load the bold variant of the font but cannot find it since it searches in the K_PATH_FONTS path and not the custom path. This was working in version 2.1.0 and if you change the font path back to the folder in the extension it also works again. If we add the bold font Maybe the solution would be to call SetFont for all custom fonts. |
I see, there is an issue with After a short analysis I think we would have to add the following to /**
* Overwrite AddFont in order to automatically provide paths to custom fonts
*
* @inheritdoc
*/
public function AddFont($family, $style='', $fontfile='', $subset='default')
{
if (empty($fontfile) && isset($this->customFontFilePaths[$family])) {
$fontfile = $this->customFontFilePaths[$family];
}
return parent::AddFont($family, $style, $fontfile, $subset);
}
/**
* @param $fontName
* @param $fontFilePath
*/
public function addCustomFontFilePath($fontName, $fontFilePath)
{
$this->fontlist[] = $fontName;
$this->customFontFilePaths[$fontName] = $fontFilePath;
} In order to make it work with the HTML ViewHelper. Can you verify whether this solves your issue? |
BTW..maybe it would be more convenient to use the <pdf:header>
<pdf:html>
<div style="font-weight:bold; font-style: univers;">Bold</div>
</pdf:html>
</pdf:header> |
Unless you have a bit more stuff going on than what is posted above. :) |
I added the suggested fix and it prevents the exception 👍 |
That's true of course :) |
Perfect, thanks for reporting and testing! I will create a new release today. |
I just released |
\TCPDF_FONTS::_getfontpath
assumes the font path to be set viaK_PATH_FONTS
or falls back to the location of the TCPDF libarary location.BasePDF
class must set this constant accordingly.The function is used indirectly within
\TCPDF::AddFont
.The big problem is that you can't use custom fonts together with default fonts as this constant can only hold 1 path.
The text was updated successfully, but these errors were encountered: