gpt4 book ai didi

php - 如何在 TCPDF 中支持 UTF-8?

转载 作者:行者123 更新时间:2023-12-03 21:34:26 25 4
gpt4 key购买 nike

我已经使用 UTF-8 字符制作了一个 pdf。但是,在 tcpdf 中不能使用 utf-8。

代码:

<?php
require_once('tcpdf/tcpdf_import.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 008');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// add a page
$pdf->AddPage();

// get esternal file content
$utf8text = "私、本書に署名する目的は、法律で認められている最大範囲において、SNUBA ガイド、";

// set color for text
$pdf->SetTextColor(0, 63, 127);

//Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0)

// write the text
$pdf->Write(5, $utf8text, '', 0, '', false, 0, false, false, 0);


// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_008.pdf', 'I');
?>

输出:
????????????????????????????????SNUBA ????

我必须创建一个pdf。 Pdf 正在工作,但不支持其他 utf-8 字符。如何使用 tcpdf 制作支持 utf-8 的 pdf?

最佳答案

我认为您使用了错误的字体。
我遇到了同样的问题,然后我将字体从“helvetica”更改为“dejavusans”并开始工作。

关于php - 如何在 TCPDF 中支持 UTF-8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37947426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com