我使用FPDI库将多个pdf文件合并为一个,
遵循本文档https://manuals.setasign.com/fpdi-manual/v2/the-fpdi-class/
我试过如下,
use \setasign\Fpdi\Fpdi;
use \setasign\Fpdi\PdfParser\StreamReader;
function merge()
{
$file = fopen('https://path/to/s3/file','rb');
$pdf = new Fpdi();
$pdf->AddPage();
$pdf->setSourceFile(new StreamReader($file));
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 100);
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');
$pdf->Output();
}
当试图在streamReader中传递url时,我得到的是给定的流是不可查找的。
如何将s3文件传递给流读取器并合并它。
发布于 2018-12-12 10:12:59
HTTP流包装器不支持查找。
您必须将桶下载到临时文件或变量中。一个简单的file_get_contents()
应该这样做:
$fileContent = file_get_contents('https://path/to/s3/file','rb');
// ...
$pdf->setSourceFile(StreamReader::createByString($fileContent));
发布于 2020-11-06 08:51:09
对于那些试图从同一服务器加载文件的人(不适用于本例,但可以帮助其他人解决此错误):将http://example.com/path/file.pdf更改为本地路径,如/home/user/public_html/ path /file.pdf
https://stackoverflow.com/questions/53737157
复制相似问题