【问题标题】:PHP FPDI Try to add text in Hebrew language to pdf file but i got problem in utfPHP FPDI 尝试将希伯来语文本添加到 pdf 文件,但我在 utf 中遇到问题
【发布时间】:2020-06-28 14:16:05
【问题描述】:

我为 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.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');   

我阅读了一些有类似问题的帖子,但我无法弄清楚我到底需要做什么。 谢谢

【问题讨论】:

  • 您需要找到支持希伯来语的字体并使用fPDF函数AddFont来使用它。 Arial 字体将不起作用。有关 UTF-8 支持的更多信息,请参阅landing page for fPDF

标签: php fpdf fpdi


【解决方案1】:

我找到了解决方案,首先我下载了​​希伯来字体,然后将文件放在字体文件夹中:

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

【讨论】:

    猜你喜欢
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多