簡體   English   中英

帶有 tcpdf 的 fpdi 新添加的文本未顯示在 pdf 中

[英]fpdi with tcpdf new added text not showing in the pdf

在此處輸入圖像描述 我正在嘗試使用 fpdi 和 tcpdf 庫在現有的 pdf 中添加文本。 但 pdf 上沒有顯示文字。 如果我搜索 pdf 文本可以突出顯示,但它隱藏在 pdf 上。 我也嘗試過 z-index 但仍然沒有出現。

請看下面是我的代碼。

$pdf = new FPDI();
$pageCount = $pdf->setSourceFile('102215_2019_unlocked.pdf');
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
//$pdf->setPrintHeader(false);


// create a page (landscape or portrait depending on the imported page size)
if ($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
// Font size 1/3 Height if it landscape
$fontsize = $size['h'] / 3;
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));

// Font size 1/3 Width if it portrait
$fontsize = $size['w'] / 3;
}

$html = '<h1 style="z-index:-1;color:black;">[![HTML Example][1]][1]</h1>';

// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');

$pdf->useTemplate($templateId);

// $pdf->SetAlpha(1);
}

$pdf->output();

好的,我終於自己找到了答案。

usetemplate function 需要放在文本和我的圖像應用之前。

像這樣

$pdf->useTemplate($templateId);

$pdf->StartTransform();

$pdf->Image('logo.png', 175, 5, 35, 0, 'PNG','https://franchimp.com');

$pdf->SetFont('Helvetica', 'B', 70);
$pdf->SetTextColor(31, 156, 239);
$pdf->SetAlpha(0.5);  
$pdf->SetXY(20, 180);
$pdf->Rotate(35);
$pdf->Write(0, 'franchimp.com');
$pdf->StopTransform();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM