doubushi0031 2012-05-23 06:24
浏览 269
已采纳

修改PDF并重用嵌入字体

I want to modify a PDF document with PHP. I found the libs FPDF and FPDI which allows to create and modify PDF files. Here is my very simple code:

<?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();

That works very well, but I see that the inserted text adds something like a reference to the system font instead of the already embedded font. How can I simply reuse the embedded font?

If that is not possible with that libs feel free to point me to a third free lib.


I know that I can just use characters which are already used, but this is no problem in my special case. I have checked that all possible characters are used in the right case sensitivity.

  • 写回答

2条回答 默认 最新

  • douweng7233 2012-07-05 20:03
    关注

    I bet your embedded font from the imported PDF page is not called calibri. (Lower-case only spelling of fontnames in PDFs is very rare.)

    And I also bet, that the PDF will not have Calibri embedded as a full set. It's rather likely that it is a subset only. And as a subset, the fontname will be composed of a random 6 letter uppercase prefix + the original font name, like this:

     AXBTZV+Calibri
    

    You have to find that exact name and try with this. (However, I'm not sure if how your PHP library works, if it can do that at all, and if it would handle the modification of the PDF text writing code in the correct way. Gimme the PDF and I most likely can do it in a Text Editor, though...)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效