【发布时间】:2012-05-23 06:24:40
【问题描述】:
我想用 PHP 修改 PDF 文档。我找到了库FPDF 和FPDI,它们允许创建和修改PDF 文件。这是我非常简单的代码:
<?php
require_once('include/fpdf.php');
require_once('include/fpdi.php');
// initiate FPDI
$pdf = new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('input.pdf');
// import page 1
$page1 = $pdf->importPage(1);
// insert the page
$pdf->useTemplate($page1);
// now write some text above the imported page
$pdf->AddFont('calibri');
$pdf->SetFont('calibri','',11);
$pdf->Write(0, "This is just a simple text");
header("Content-Type: application/pdf");
$pdf->Output();
效果很好,但我看到插入的文本添加了对系统字体的引用,而不是已经嵌入的字体。我怎样才能简单地重复使用嵌入的字体?
如果这些库无法做到这一点,请随时将我指向第三个免费库。
我知道我可以只使用已经使用过的字符,但这在我的特殊情况下没有问题。我检查了所有可能的字符都以正确的大小写敏感度使用。
【问题讨论】:
标签: php pdf fpdf embedded-fonts fpdi