I am using FPDI library to merge multiple pdf files into one,
followed this documentaion https://manuals.setasign.com/fpdi-manual/v2/the-fpdi-class/
I have tried like below,
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();
}
When tried to pass url in streamReader I am getting Given stream is not seekable.
How can I pass s3 file to stream reader and merge it.
An HTTP stream wrapper does not support seeking.
You have to download the bucket to a temporary file or variable. A simple file_get_contents()
should do it:
$fileContent = file_get_contents('https://path/to/s3/file');
// ...
$pdf->setSourceFile(StreamReader::createByString($fileContent));
For those who try to load the file from the same server (not apply to this case but could help others solve this error): change http://example.com/path/file.pdf to a local path like this /home/user/public_html/path/file.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With