Closed farahalrabee2 closed 4 years ago
Hello all,
i have this code in my model : ` $pdf = new Pdf([ 'tempPath' => Yii::getAlias('@backend') . '/web/custom/temp/dir/path', 'mode' => '', 'filename' => $filename, 'format' => Pdf::FORMAT_A4, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'cssInline' => 'body{font-family:Cairo;}', 'defaultFont'=>"Cairo" ]); $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; $pdf->options = array_merge($pdf->options , [ 'fontDir' => array_merge($fontDirs, [ Yii::$app->basePath.'/../backend/web/font/ar/']), // make sure you refer the right physical path 'fontdata' => array_merge($fontData, [ 'cairo' => [ 'R' => 'cairo-v4-arabic_latin-regular.ttf', 'I' => 'cairo-v4-arabic_latin-700.ttf', 'useOTL' => 0xFF, 'useKashida' => 75, ] ]), 'default_font' => 'cairo', ]);`
Everything is going well but when i try to generate the PDF i faced this PHP warning : ksort() expects parameter 1 to be array, null given. in the OTL.php file during implementing the _getClassDefinitionTable function , $GlyphByClass returns null while it should at least return an empty array : private function _getClassDefinitionTable($offset) { if (isset($this->LuDataCache[$this->fontkey][$offset])) { $GlyphByClass = $this->LuDataCache[$this->fontkey][$offset]; } else { $this->seek($offset); $ClassFormat = $this->read_ushort(); $GlyphClass = []; // $GlyphByClass = array(0=>array()); // NB This forces an index[0] if ($ClassFormat == 1) { $StartGlyph = $this->read_ushort(); $GlyphCount = $this->read_ushort(); for ($i = 0; $i < $GlyphCount; $i++) { $GlyphClass[$i]['startGlyphID'] = $StartGlyph + $i; $GlyphClass[$i]['endGlyphID'] = $StartGlyph + $i; $GlyphClass[$i]['class'] = $this->read_ushort(); for ($g = $GlyphClass[$i]['startGlyphID']; $g <= $GlyphClass[$i]['endGlyphID']; $g++) { $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g); } } } elseif ($ClassFormat == 2) { $tableCount = $this->read_ushort(); for ($i = 0; $i < $tableCount; $i++) { $GlyphClass[$i]['startGlyphID'] = $this->read_ushort(); $GlyphClass[$i]['endGlyphID'] = $this->read_ushort(); $GlyphClass[$i]['class'] = $this->read_ushort(); for ($g = $GlyphClass[$i]['startGlyphID']; $g <= $GlyphClass[$i]['endGlyphID']; $g++) { $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g); } } } ksort($GlyphByClass); $this->LuDataCache[$this->fontkey][$offset] = $GlyphByClass; } return $GlyphByClass; }
private function _getClassDefinitionTable($offset) { if (isset($this->LuDataCache[$this->fontkey][$offset])) { $GlyphByClass = $this->LuDataCache[$this->fontkey][$offset]; } else { $this->seek($offset); $ClassFormat = $this->read_ushort(); $GlyphClass = []; // $GlyphByClass = array(0=>array()); // NB This forces an index[0] if ($ClassFormat == 1) { $StartGlyph = $this->read_ushort(); $GlyphCount = $this->read_ushort(); for ($i = 0; $i < $GlyphCount; $i++) { $GlyphClass[$i]['startGlyphID'] = $StartGlyph + $i; $GlyphClass[$i]['endGlyphID'] = $StartGlyph + $i; $GlyphClass[$i]['class'] = $this->read_ushort(); for ($g = $GlyphClass[$i]['startGlyphID']; $g <= $GlyphClass[$i]['endGlyphID']; $g++) { $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g); } } } elseif ($ClassFormat == 2) { $tableCount = $this->read_ushort(); for ($i = 0; $i < $tableCount; $i++) { $GlyphClass[$i]['startGlyphID'] = $this->read_ushort(); $GlyphClass[$i]['endGlyphID'] = $this->read_ushort(); $GlyphClass[$i]['class'] = $this->read_ushort(); for ($g = $GlyphClass[$i]['startGlyphID']; $g <= $GlyphClass[$i]['endGlyphID']; $g++) { $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g); } } } ksort($GlyphByClass); $this->LuDataCache[$this->fontkey][$offset] = $GlyphByClass; } return $GlyphByClass; }
i solved the problem by setting $GlyphByClass = []; in OTL.php.
anyone can help ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello all,
i have this code in my model : ` $pdf = new Pdf([ 'tempPath' => Yii::getAlias('@backend') . '/web/custom/temp/dir/path', 'mode' => '', 'filename' => $filename, 'format' => Pdf::FORMAT_A4, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'cssInline' => 'body{font-family:Cairo;}', 'defaultFont'=>"Cairo" ]); $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir'];
Everything is going well but when i try to generate the PDF i faced this PHP warning : ksort() expects parameter 1 to be array, null given. in the OTL.php file during implementing the _getClassDefinitionTable function , $GlyphByClass returns null while it should at least return an empty array :
private function _getClassDefinitionTable($offset) { if (isset($this->LuDataCache[$this->fontkey][$offset])) { $GlyphByClass = $this->LuDataCache[$this->fontkey][$offset]; } else { $this->seek($offset); $ClassFormat = $this->read_ushort(); $GlyphClass = []; // $GlyphByClass = array(0=>array()); // NB This forces an index[0] if ($ClassFormat == 1) { $StartGlyph = $this->read_ushort(); $GlyphCount = $this->read_ushort(); for ($i = 0; $i < $GlyphCount; $i++) { $GlyphClass[$i]['startGlyphID'] = $StartGlyph + $i; $GlyphClass[$i]['endGlyphID'] = $StartGlyph + $i; $GlyphClass[$i]['class'] = $this->read_ushort(); for ($g = $GlyphClass[$i]['startGlyphID']; $g <= $GlyphClass[$i]['endGlyphID']; $g++) { $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g); } } } elseif ($ClassFormat == 2) { $tableCount = $this->read_ushort(); for ($i = 0; $i < $tableCount; $i++) { $GlyphClass[$i]['startGlyphID'] = $this->read_ushort(); $GlyphClass[$i]['endGlyphID'] = $this->read_ushort(); $GlyphClass[$i]['class'] = $this->read_ushort(); for ($g = $GlyphClass[$i]['startGlyphID']; $g <= $GlyphClass[$i]['endGlyphID']; $g++) { $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g); } } } ksort($GlyphByClass); $this->LuDataCache[$this->fontkey][$offset] = $GlyphByClass; } return $GlyphByClass; }
i solved the problem by setting $GlyphByClass = []; in OTL.php.
anyone can help ?