【发布时间】:2019-10-09 02:23:22
【问题描述】:
我正在尝试在 laravel 中编辑 pdf。我在控制器中创建了以下函数,其中有 use FPDI 和 use FPDF
static function getHigherPDF() {
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile('/pdf/higher.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 100);
$pdf->Output();
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');
return $pdf;
}
我不断收到以下错误,我不知道为什么,如果我将带有 http:// 等的完整路径放入 pdf,我什至会收到错误。当我转到该文件时,pdf 在我的浏览器中打开。如果文件 url 是有效的 url,我找不到任何关于为什么会发生这种情况的信息
有什么想法吗?
{message: "Cannot open /pdf/higher.pdf !", exception: "InvalidArgumentException",...}
exception: "InvalidArgumentException"
file: "/home/vagrant/code/brainskills-at-work/vendor/setasign/fpdi/pdf_parser.php"
message: "Cannot open /pdf/higher.pdf !"
【问题讨论】:
-
通过表明
$pdf->setSourceFile('/pdf/higher.pdf');您引用的是绝对路由,您必须使用相对路由。你的 pdf 在哪里? -
它位于
http://www.sample.com/pdf/higher.pdf -
我的意思是,在你的文件系统中,你的 laravel 项目中有什么文件夹?
storage/app/public? -
嗯,文件夹结构中的路径是root/public/pdf/higher(不在存储中)
标签: php laravel pdf-generation fpdf fpdi