【问题标题】:FPDI & TCPDF problems?FPDI 和 TCPDF 问题?
【发布时间】:2013-11-23 14:57:02
【问题描述】:

我在让 FPDI 和 TTCPDF php 类一起工作时遇到了一个相当奇怪的问题。

FPDI:http://www.setasign.com/products/fpdi/about/

TCPPDF:http://www.tcpdf.org/

通过阅读甚至查看给出的一些示例,这些应该可以协同工作没有问题...

但是..我遇到了一些冲突(或其他事情)

此链接显示了一种同时使用 TPDF 和 TCPDF 类的相当简单直接的方法:

setasign.com/products/fpdi/demos/tcpdf-demo/

我正在使用 WAMP.. 和 PHP 5.4.12 版在本地运行/测试它

<?php
// just require TCPDF instead of FPDF
//require_once 'fpdf/fpdf.php'; //old
require_once('tcpdf/tcpdf.php');
require_once('fpdi/fpdi.php');

class PDF extends FPDI{
}
// initiate FPDI
$pdf = new FPDI();

// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile("SRS_blank.pdf");
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 210mm (width of A4)
$pdf->useTemplate($tplIdx, 0, 0, 210, 297);

// now write some text above the imported page

//position table at bottom
$pdf->SetXY(0, 200);
//set table font
$pdf->SetFont('Helvetica');
//set table color
$pdf->SetTextColor(255, 0, 0);
//table html
$html = '<table border="1" cellspacing="2" cellpadding="2">
    <tr>
        <td width="70" rowspan="6">Company Name</td>

    </tr>
    <tr>
       <td rowspan="6"><img src="images/SRS_logo.jpg"></td>
    </tr>
    <tr>
        <td>Name</td>
        <td>Address</td>
        <td>City/State/Zip</td>
        <td>phone/fax</td>
        <td>email</td>
        <td>URL</td>
    </tr>
</table>';
// output the HTML table to pdf overlay
$pdf->writeHTML($html, true, false, true, false, '');

$pdf->Output();
?>

这是我在尝试使用 TCPDF(它有更强大的显示内容选项)时遇到的错误

严格标准:FPDF::_putstream() 的声明应与在线 C:\wamp\www\projects\PDF_generation\FPDI\fpdi2tcpdf_bridge.php 中的 TCPDF::_putstream($s, $n = 0) 兼容167

还有这个:

严格的标准:FPDF_TPL::SetFont() 的声明应该与 TCPDF::SetFont($family, $style = '', $size = NULL, $fontfile = '', $subset = 'default', $out = true) 在 C:\wamp\www\projects\PDF_generation\FPDI\fpdf_tpl.php 第 460 行

我不知道如何获得一个体面的开发环境来测试和使用这两个类?

有什么想法吗?感谢所有建议。

谢谢!

【问题讨论】:

  • 您是否尝试过:ini_set('display_errors', '0');和错误报告(E_ALL | E_STRICT);
  • 我会..但不确定如何?我如何在我当前的设置中实现它?这是我需要在我的 php.ini 文件中做的事情吗?
  • Yoa 可以在 php 脚本的开头插入这两行。
  • 这似乎有助于抑制那些警告信息。谢谢!!!
  • 没问题,我是来帮忙的 ;)

标签: php pdf pdf-generation tcpdf fpdi


【解决方案1】:

在 FPDI 和 TCPDF 的最新版本中,不应再出现此严格警告。我不知道他们最终开始正确重载 TCPDF 函数时是哪个版本的 FPDI,但似乎 PHP、FPDI 和 TCPDF 的以下混合不再生成这些警告...

PHP 版本:5.5.10

FPDI 版本:1.5.2 - http://www.setasign.com/products/fpdi/downloads/

TCPPDF 版本:6.0.089 - http://sourceforge.net/projects/tcpdf/files/

【讨论】:

  • 天哪.. 3+(几乎 4)岁的帖子现在.. 仍然需要把你的手指放在里面并调整/编辑......等等..等等。 (干得好)(翻白眼)
【解决方案2】:

当重载函数需要指定所有参数时(也有默认值)

在文件 fpdi2tcpdf_bridge.php 第 31 行设置函数声明

function _putstream($s) {

function _putstream($s, $n=0) {

在第 275 行的 file fpdf_tpl.php 中设置函数声明

public function SetFont($family, $style = '', $size = 0) {

public function SetFont($family, $style = '', $size = 0, $fontfile = '', $subset = 'default', $out = true) {

【讨论】:

  • 亲爱的朋友,答案很好。此答案必须选为正确答案。
猜你喜欢
  • 1970-01-01
  • 2015-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
  • 1970-01-01
  • 2015-03-27
相关资源
最近更新 更多