Search code examples
phppdffpdf

FPDFI - setSourceFile as string and not file


I am using FPDFI to manipulate an existing PDF. I get this PDF back in the form of a base64 encoding string from an external API. I then create a PDF and then use the following code to manipulate it:

$pdf = new FPDI();
$sourceFileName = 'label.pdf';
$pdf->setSourceFile($sourceFileName);

Is it possible to bypass the process of creating the file and just send the base64 decoded string straight into setSourceFile, e.g:

$pdf = new FPDI();
$pdf->setSourceString(base64_encode($labelString));

I can't find anything in the docs.

EDIT:

I seem to have been able to solve this by using the tempnam() function in PHP:

$tmpfname = tempnam("/tmp", "ABC");

$handle = fopen($tmpfname, "w");
fwrite($handle, $label);
fclose($handle);

And then referring to $tmpfname as $sourceFileName


Solution

  • You can also use a stream wrapper instead.