1

I have docx file with some Croatian letters (č,ć,đ,š,ž) and want to convert it to pdf using PHPWord library with TCPDF. Result file recognize š and ž but for others there is only ?. I tried to change fonts and encoding but without success. Here is my code for conversion:

    require_once 'vendor\autoload.php';
    require_once 'vendor\phpoffice\phpword\bootstrap.php';

    include_once 'tcpdf/tcpdf.php';
    include_once 'tcpdf/examples/lang/hrv.php';

    \PhpOffice\PhpWord\Settings::setPdfRendererPath('tcpdf');
    \PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');

    $striped_content = '';
    $content = '';

    $temp = \PhpOffice\PhpWord\IOFactory::load("helloWorld.docx");
    $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
    $xmlWriter->save('test.pdf',FALSE);

And my tcpdf.php look like:

public function save($filename = null)
{
    $fileHandle = parent::prepareForSave($filename);

    //  PDF settings
    $paperSize = 'A4';
    $orientation = 'P';


    // Create PDF
    $pdf = new \TCPDF($orientation, 'pt', $paperSize, true, 'UTF-8', false);

   // set some language dependent data:
    $lg = Array();
    $lg['a_meta_charset'] = 'UTF-8';
    $lg['a_meta_dir'] = 'ltr';
    $lg['a_meta_language'] = 'hr';
    $lg['w_page'] = 'page';

    // set some language-dependent strings (optional)
    $pdf->setLanguageArray($lg);
    $pdf->setFontSubsetting(false);
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    $pdf->SetFont('freeserif', '', 11, '', true);
    $pdf->AddPage();
  //  $pdf->SetFont($this->getFont());
    $pdf->writeHTML($this->getContent());

    // Write document properties
    $phpWord = $this->getPhpWord();

    $docProps = $phpWord->getDocInfo();
    $pdf->SetTitle($docProps->getTitle());
    $pdf->SetAuthor($docProps->getCreator());
    $pdf->SetSubject($docProps->getSubject());
    $pdf->SetKeywords($docProps->getKeywords());
    $pdf->SetCreator($docProps->getCreator());

    //  Write to file
    fwrite($fileHandle, $pdf->Output($filename, 'S'));

    parent::restoreStateAfterSave($fileHandle);

}
miken32
  • 42,008
  • 16
  • 111
  • 154
iki93
  • 21
  • 6
  • Possible duplicate of [TCPDF UTF-8. Lithuanian symbols not showing up](https://stackoverflow.com/questions/5333702/tcpdf-utf-8-lithuanian-symbols-not-showing-up) – miken32 Jan 19 '19 at 20:35
  • Still have problem. I tried all suggestions from https://stackoverflow.com/questions/5333702/tcpdf-utf-8-lithuanian-symbols-not-showing-up but nothing works. – iki93 Jan 20 '19 at 12:20

0 Answers0