我需要上传两个图像文件,并将其添加到现有的PDF文件中。我已经阅读了关于FPDF的文章,基于此,我遵循这个帖子link。如果有人可以发布一个简单的工作示例/链接,这对像我这样的搜索者以及一些也会采用相同路线寻找一些有用答案的人有所帮助。使用PHP插入现有PDF文件中的图像文件
回答
对于FPDF,似乎有一个名为FPDI的扩展名。下面是有关如何修改现有的PDF博客文章:http://pranavom.wordpress.com/2011/03/15/modify-pdf-using-fpdffpdi-library/
您可以将使用FPDI像这样的图像:
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile("MySource");
$template = $pdf->importPage(1);
$pdf->useTemplate($template);
$pdf->Image('MyImage.jpg', $x, $y, $width, $height);
$pdf->Output($outputPath, "F");
嗨托尼,我跟着你提到的例子,我可以用图像创建一个pdf,但即使我的原始pdf只包含一个页面,创建的PDF有一个第一页,其中是空白的,在第二页,我得到了我想要的内容。任何想法如何消除这一点,并获得第一页所需的变化。如果你能解决这个问题,我也会接受你的回答。谢谢 – 125369 2012-03-06 15:42:05
不确定,尝试删除第一个'$ pdf-> AddPage();'但这是另一个问题。 – tonymarschall 2012-03-06 15:45:24
感谢托尼指出,答案接受:)只是一个更基本的问题,是有可能增加/减少图像尺寸或图像尺寸是标准的。 – 125369 2012-03-06 15:50:30
我使用PHP,FPDF生成从FDF文件的PDF和然后在PDF中插入一个qrcode图形。我一直在遇到麻烦,因为我的空pdf已经内置了表单字段,并在其他程序中插入了图形删除了我的表单字段。我终于弄明白了。希望这可以帮助那些正在为之奋斗的人。
我的殡仪馆工作,如果任何一个变种的名称把你扔出这个代码不抛光其被切断,从吨的不同来源的粘贴;)
我使用以下库http://www.fpdf.org/和http://phpqrcode.sourceforge.net/
for($count=0;$count<$doc_list_length;$count++){
//create FDF file
$id = rand(11111,99999);
$filename = $populated_pdf_path . $casenumber.$doc_list[$count].".fdf";
$file = fopen($filename,"w");
$filecontents = "%FDF-1.2". PHP_EOL;
$filecontents .= "%âãÏÓ" . PHP_EOL;
$filecontents .= "1 0 obj" . PHP_EOL;
$filecontents .= "<<" .PHP_EOL;
$filecontents .= "/FDF << /Fields [ ";
$filecontents .= "<</T(name)/V($name)>>";
$filecontents .= "] " . PHP_EOL;
$filecontents .= "/F (empty_pdf/$doc_list[$count].pdf) ";
$filecontents .= "/ID [ <$id>" . PHP_EOL;
$filecontents .= "] >> " . PHP_EOL;
$filecontents .= ">> ". PHP_EOL;
$filecontents .= "endobj" . PHP_EOL;
$filecontents .= "trailer" . PHP_EOL;
$filecontents .= "<<" . PHP_EOL;
$filecontents .= "/Root 1 0 R" . PHP_EOL . PHP_EOL;
$filecontents .= ">>" . PHP_EOL;
$filecontents .= "%%EOF";
fwrite($file, $filecontents);
fclose($file);
//insert image on this document only
//generate qrcode
if($doc_list[$count] == "checklist"){
$qrCodeFileName = $cemetery."qrcode.png";
if(!file_exists($populated_pdf_path.$qrCodeFileName)){
include('include/phpqrcode/qrlib.php');
$codeContents = "http://www.asuperduperwebaddress.com";
QRcode::png($codeContents, $populated_pdf_path.$qrCodeFileName);
}
if(!file_exists($populated_pdf_path.$cemetery."qrcode.pdf")){
//make pdf with image
require_once('include/fpdf.php');
$image = $populated_pdf_path.$qrCodeFileName;
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Image($image, 183, 250, 25, 25, 'PNG');
$pdf->Output($populated_pdf_path.$cemetery."qrcode.pdf");
}
//setup file paths for pdf output
$tempFile = $populated_pdf_path . $casenumber.$doc_list[$count]."temp.pdf";
$pdfExampleFile = $populated_pdf_path . $casenumber.$doc_list[$count].".pdf";
$pdfFile = $empty_pdf_path . $doc_list[$count] . ".pdf";
if($doc_list[$count] == "checklist")
$fdfFile = $filename;
$fdfTemplateFile = $filename;
//fill pdf
$command = "pdftk $pdfFile fill_form $fdfTemplateFile output $tempFile 2> fill_form.log";
passthru($command);
//stamp pdf with qrcode
$command = "pdftk " . $tempFile . " stamp " . $populated_pdf_path.$cemetery . "qrcode.pdf output " . $pdfExampleFile;
passthru($command);
}
else{
//setup file paths for pdf output
$pdfExampleFile = $populated_pdf_path . $casenumber.$doc_list[$count].".pdf";
$pdfFile = $empty_pdf_path . $doc_list[$count] . ".pdf";
if($doc_list[$count] == "checklist")
$fdfFile = $filename;
$fdfTemplateFile = $filename;
//fill pdf
$command = "pdftk $pdfFile fill_form $fdfTemplateFile output $pdfExampleFile 2> fill_form.log";
passthru($command);
}
}
谢谢。我必须做出一个改变,$ pdf-> Output调用需要一个dest参数。我用: $ pdf->输出(“F”,$ filename); – NoelHunter 2017-04-13 13:20:30
- 1. PDF:在现有PDF文件中插入一行文字
- 2. 如何使用iTextsharp将文件插入到包含文件夹的现有PDF文件夹的文件夹中
- 3. 使用itext将图像文件插入PDF时找不到文件
- 4. 使用PHP在PDF文件中插入文本而无需额外的软件
- 5. 使用Microsoft.Dynamics.BusinessConnectorNet插入pdf文件
- 6. 插入文本的PDF文件使用PHP,但没有Zend框架
- 7. 从文件夹和子文件夹插入图像php
- 8. 使用ExcelWriter()将图像插入Excel文件PHP
- 9. 使用PHP将图像插入RTF文件
- 10. 使用lotus.domino在Notes文档中插入图像/文件
- 11. 使用图像生成PDF文件
- 12. 使用PDF文件作为图像
- 13. 在PDFBOX中创建PDF文件(从现有的pdf文件)
- 14. 允许用户创建PDF或图像文件的Flash插件
- 15. 插入数字签名到现有的PDF文件
- 16. 什么是插入JavaScript到现有的PDF文件(通过API)
- 17. 下载图像文件并替换现有的图像文件
- 18. 在ASP文件中插入图像
- 19. 如何使用itextpdf将图像附加到android中的现有pdf文件
- 20. php插入文件
- 21. 使用Python将文本文件插入现有的xlsx
- 22. 保存base64编码的图像插入文件中的PHP
- 23. 使用FPDF在PDF中插入图像
- 24. 使用ITextSharp在PDF中插入图像
- 25. 将PDF插入PDF(不合并文件)
- 26. 如何使用PHP为现有的PDF文件添加水印?
- 27. 将现有文件插入intellij IDE中的文件夹
- 28. 在文件中插入PHP
- 29. 使用PHP变量将HTML文件写入PDF文件?
- 30. 如何使用ImageMagick将PDF文件转换为图像文件
将图像添加到现有的PDF - 这应该出现在现有的页面还是新的?如果前者,请记住,您真的只能渲染现有内容afaik的顶部 - 如果您想用插入的图片重新排列文档,则需要从头开始重新渲染。 – halfer 2012-03-06 15:17:27
图片应该在现有网页上显示的信息 – 125369 2012-03-06 15:20:29
太好了,@ tonymarschall的答案应该会让你感到满意。 – halfer 2012-03-06 15:23:09