PHP 中的 tcpdf wordpress 错误,即使我按照 tcpdf 示例 1by1

tcpdf wordpress error in PHP even tho i followed the tcpdf example 1by1

我创建了一个插件,当您按下发送时,表单中的数据应该被翻译成 pdf 并保存在一个文件夹中以备备份。

我正在使用 tcpdf api,下载了库并将其放在我的插件文件夹中。当我尝试使用来自 tcpdf 站点的 givin textexample 对其进行测试时,它只是抛出了这些错误:

"Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /www/htdocs/w00e68de/msp.rfid-dresden.de/wp-content/plugins/wp-markenbuero/tcpdf/tcpdf.php on line 17778

Warning: fopen(): remote host file access not supported, file://example_002.pdf in /www/htdocs/w00e68de/msp.rfid-dresden.de/wp-content/plugins/wp-markenbuero/tcpdf/include/tcpdf_static.php on line 1854

Warning: fopen(file://example_002.pdf): failed to open stream: no suitable wrapper could be found in /www/htdocs/w00e68de/msp.rfid-dresden.de/wp-content/plugins/wp-markenbuero/tcpdf/include/tcpdf_static.php on line 1854 TCPDF ERROR: Unable to create output file: example_002.pdf"

// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', 'BI', 20);
// add a page
$pdf->AddPage();
// set some text to print
$txt = <<<EOD
TCPDF Example 002
Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
EOD;
// print a block of text using Write()
$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_002.pdf', 'F');
}
?>

这有两个部分,所以我将在两个部分之间进行回答:

文件协议警告/无法生成 PDF:

F模式下调用Output保存到本地文件时不能使用相对文件路径。您必须提供完整的文件路径。以下是一些示例:

//Generates output file in the same folder as current script.
$pdf->Output(dirname(__FILE__).'/example_002.pdf', 'F');

//Save to the document root.
$pdf->Output($_SERVER['DOCUMENT_ROOT'].'/example_002.pdf', 'F');

继续目标切换警告:

此警告是 PHP 7.3 incompatibility warning with whichever version of the TCPDF library you are using. The master branch from the github repo 似乎不会引发此警告,因此请尝试使用该版本的库。