PHP FPDI试图将希伯来语文本添加到pdf文件中,但我在utf中遇到了问题
我使用php的FPDI库,并尝试将文本添加到pdf文件中。 这是工作,但当我把课文改成希伯来文时,我得到了PHP FPDI试图将希伯来语文本添加到pdf文件中,但我在utf中遇到了问题,php,fpdf,fpdi,Php,Fpdf,Fpdi,我使用php的FPDI库,并尝试将文本添加到pdf文件中。 这是工作,但当我把课文改成希伯来文时,我得到了 ×•× ̈×– הצלח×a×TM להוס×TM×£ × ̃×§×¡× ̃ 这是我的代码: <?php use setasign\Fpdi\Fpdi; use \setasign\Fpdi\PdfParser\StreamReader; require_once('fpdf/fpdf.php'); require_once('fpdi/src/autoload.p
×•× ̈×– הצלח×a×TM להוס×TM×£ × ̃×§×¡× ̃
这是我的代码:
<?php
use setasign\Fpdi\Fpdi;
use \setasign\Fpdi\PdfParser\StreamReader;
require_once('fpdf/fpdf.php');
require_once('fpdi/src/autoload.php');
$rawPostBody = file_get_contents('php://input');
$signatures = (array)json_decode($rawPostBody);
$fileURL = $signatures['filURL'];
$signaturesData = $signatures['signatures'];
// Initial Fpdi
$pdf = new Fpdi();
// Load external pdf file with StreamReader (We Use StreamReader Only for External file)
$fileContent = file_get_contents($fileURL,'rb');
$pdf->setSourceFile(StreamReader::createByString($fileContent));
// Get number of pages.
$pageCount = $pdf->setSourceFile(StreamReader::createByString($fileContent));
// Illiterate and create pdf pages.
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
$tplId = $pdf->importPage($pageNumber);
$s = $pdf->getTemplatesize($tplId);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',10);
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L', array($s['w'], $s['h'])); // This gets it the right dimensions
$pdf->useTemplate($tplId, null, null, null, null, true);
foreach ($signaturesData as $signa) {
if($signa->page == $pageNumber) {
$pdf->SetXY(number_format($signa->positionX), number_format($signa->positionY * 0.264583));
$pdf->Write(0, "שלום שלום");
}
}
}
$pdf->Output('pdf-with-value.pdf', 'D');
我找到了解决方案,首先下载希伯来文字体,然后将文件放入字体文件夹,然后:
$pdf->AddFont('Rubik-Light', '', 'Rubik-Light.php');
$pdf->SetFont('Rubik-Light', '', 15);
$value = iconv('UTF-8', 'windows-1255', html_entity_decode('עובד פיקס'));
$value = strrev($value);
$pdf->Write(0, $value);
您需要找到一种支持希伯来语的字体,并使用fPDF函数AddFont
。Arial字体不起作用。有关UTF-8支持的更多信息,请参阅。