[英]Getting 'Cannot open pdf' error with a correct source url when using FPDI
我正在嘗試在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;
}
我一直收到以下錯誤,但我不知道為什么,如果我將pdf的http://等完整路徑放入,我什至會收到錯誤。 當我轉到該文件時,會在瀏覽器中打開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 !"
您應該使用laravel生成器為公共路徑引用文件:
$pdf->setSourceFile(public_path('/pdf/higher.pdf'));
這將在文件系統上生成該文件的絕對路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.