I am doing a basic system that the staff uploads a pdf file with some description and this data stored in database MySQL.

The admin will view this pdf and click on approval if everything is ok.

An image will be inserted in pdf file with approve logo.

I use fpdf and fpdi class to do this, I manage to do this if PDF file stored on the actual path as shown in the code below.

```
<?php

use setasign\Fpdi\Fpdi;

require_once('fpdf/fpdf.php');
require_once('fpdi2/src/autoload.php');

// initiate FPDI
$pdf = new Fpdi();
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile('PdfDocument.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at position 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx, 10, 10, 100);

// now write some text above the imported page
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');

$pdf->Output();

```

BUT when I try to use $pdf->setSourceFile($string) or other that actual file for example (PDF $content from string (database) or URL) I cannot manage to do that.

```
    // set the source file
//$pageCount = $pdf->setSourceFile("http://localhost/pdf/getpicture.php?fid=2");

$stream = fopen('data:text/plain,' . urlencode("http://localhost/pdf/getPDF.php?fid=2"), 'rb');
//$reader = new SetaPDF_Core_Reader_Stream($stream);
$pageCount = $pdf->setSourceFile($stream);

```

My question is how can I import PDF from MySQL string to be edited by fpdf and fpdi or any other free PDF classes.

Note: I try to use stream\_wrapper\_register with no luck so far. as in this link
<https://www.setasign.com/support/faq/miscellaneous/using-a-pdf-from-a-php-variable-instead-of-a-file/>

Please help me with a simple example as I am not really familiar with PDF classes.

Thank you.