为什么显示TCPDF?将Word文件中的文本转换为Č时

时间:2019-01-19 19:54:35

标签: php utf-8 tcpdf phpword

我有一个带有克罗地亚语字母(č,ć,đ,š,ž)的docx文件,并希望使用带有TCPDF的PHPWord库将其转换为pdf。结果文件可以识别š和ž,但对于其他文件则只有?。 我试图更改字体和编码,但没有成功。 这是我的转换代码:

    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);

我的tcpdf.php看起来像:

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);

}

0 个答案:

没有答案