phpcodeigniterpdffpdi

Given stream is not seekable In FPDI


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.


Solution

  • 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));