title: retrieve pdf blob from database
body: <p>Well I need to store a content of pdf to database and retrieve it.
  I'm using fpdf to construct content of my pdf.
  When I'm using $pdf->Output("","I"); or $pdf->Output("","D"); , I can see the content and save into my database.
  My code is that:
            class FPDF extends tFPDF
                                  {</p>
  
  <pre><code>                                function Header()
                              {
                                  $hoje = date("d/m/y");
                                  $this-&gt;Cell(10,10,"$hoje",0,'L');
                                  $this-&gt;Image('./images/logo.png',170,10,30);
  
                                  $this-&gt;SetFont('Arial','',9);
  
                                  $this-&gt;Cell(70);
  
                                  $this-&gt;Cell(30,10,'Nome da empresa',0,'C');
  
                                  $this-&gt;Ln(15);
                              }
  
                                  function NomeComprador($nomeUser,$apelido,$nomeCategoria)
                                  {
  
                                      $this-&gt;SetFont('DejaVu','',10);
  
                                      $this-&gt;Cell(0,4,"Nome do Utilizador: $nomeUser" . " $apelido",0,1,'C');
                                      $this-&gt;Cell(-1);
                                      $this-&gt;Cell(0,5,"Categoria: $nomeCategoria",0,1,'C');
  
                                      $this-&gt;Ln(4);
                                  }
  
                                  function informacaoImagem($nomeImagem,$titulo,$descricao,$poupa,$desconto,$quantidade){
  
                                  $this-&gt;nomeImagem = $nomeImagem;
                                  $total = $quantidade * $poupa;
                                  $this-&gt;Image('./images/paginaPrincipal/' . $this-&gt;nomeImagem,30,50,50);
                                  $this-&gt;Cell(125,30,"Nome do Voucher: $titulo",0,1,'R');
                                  $this-&gt;Cell(120.5,-15,"Descrição: $descricao",0,1,'R');
                                  $this-&gt;SetFont('DejaVu','B',22);
                                  $this-&gt;Cell(180,40,"$total" . " €",0,1,'C');
                                  $this-&gt;SetFont('DejaVu','',11);
                                  $this-&gt;Cell(250,-45,"Desconto: $desconto" . '%',0,1,'C');                               
                                  }
  
                                  function informacaoOferta($menus,$descricoes){
  
                                      foreach ($menus as $key =&gt; $value) {
                                              foreach ($descricoes as $key2 =&gt; $value2){
                                                  if($key == 0 &amp;&amp; $key2 == 0){
                                                      $valor = strip_tags($value2);
                                                      $this-&gt;SetFont('DejaVu', 'B', 14);
                                                      $this-&gt;Cell(125,100,"$value:",0,1,'L');
                                                      $this-&gt;SetFont('DejaVu','','11');
                                                      $this-&gt;Write(5,$this-&gt;Cell(125,-75,"$valor"));
                                                      $this-&gt;Ln(10);
                                              }elseif ($key == 1 &amp;&amp; $key2 == 1){
                                                  $valorFinal = strip_tags($value2);
                                                  $this-&gt;SetFont('DejaVu','B',13);
                                                  $this-&gt;Cell(125,-30,"$value:",0,1,'L');
                                                  $this-&gt;SetFont('DejaVu','','11');
                                                  $this-&gt;Write(5,"$valorFinal");
                                                  $this-&gt;Ln(50);
                                              }elseif($key == 2 &amp;&amp; $key2 == 2){
                                                  $valor3 = strip_tags($value2);
                                                  $this-&gt;SetFont('DejaVu','B',13);
                                                  $this-&gt;Cell(125,-50,"$value:",0,1,'L');
                                                  $this-&gt;SetFont('DejaVu','','11');
                                                  $this-&gt;Write(7,"$valor3");
                                                  $this-&gt;Ln(30);
                                              }elseif($key == 3 &amp;&amp; $key2 == 3){
                                                  $valor4 = strip_tags($value2);
                                                  $this-&gt;SetFont('DejaVu','B',13);
                                                  $this-&gt;Cell(125,-10,"$value:",0,1,'L');
                                                  $this-&gt;SetFont('DejaVu','','11');
                                                  $this-&gt;Write(3,"$valor4");
                                                  $this-&gt;Ln(40);
                                              }elseif($key == 4 &amp;&amp; $key2 == 4){
                                                  $valor5 = strip_tags($value2);
                                                  $this-&gt;SetFont('DejaVu','B',13);
                                                  $this-&gt;Cell(125,20,"$value:",0,1,'L');
                                                  $this-&gt;SetFont('DejaVu','','11');
                                                  $this-&gt;Write(0,"$valor5");
                                                  $this-&gt;Ln(20);
                                              }
                                          }                           
                                      }
                                  }
  
                                  function EAN13($x, $y, $barcode, $h=16, $w=.35)
                                      {
                                          $this-&gt;Barcode($x,$y,$barcode,$h,$w,13);
                                      }
  
                                      function UPC_A($x, $y, $barcode, $h=16, $w=.35)
                                      {
                                          $this-&gt;Barcode($x,$y,$barcode,$h,$w,12);
                                      }
  
                                      function GetCheckDigit($barcode)
                                      {
  
                                          $sum=0;
                                          for($i=1;$i&lt;=11;$i+=2)
                                              $sum+=3*$barcode[$i];
                                          for($i=0;$i&lt;=10;$i+=2)
                                              $sum+=$barcode[$i];
                                          $r=$sum%10;
                                          if($r&gt;0)
                                              $r=10-$r;
                                          return $r;
                                      }
  
                                      function TestCheckDigit($barcode)
                                      {
  
                                          $sum=0;
                                          for($i=1;$i&lt;=11;$i+=2)
                                              $sum+=3*$barcode[$i];
                                          for($i=0;$i&lt;=10;$i+=2)
                                              $sum+=$barcode[$i];
                                          return ($sum+$barcode[12])%10==0;
                                      }
  
                                      function Barcode($x, $y, $barcode, $h, $w, $len)
                                      {
  
                                          $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
                                          if($len==12)
                                              $barcode='0'.$barcode;
  
                                          if(strlen($barcode)==12)
                                              $barcode.=$this-&gt;GetCheckDigit($barcode);
                                          elseif(!$this-&gt;TestCheckDigit($barcode))
                                              $this-&gt;Error('Incorrect check digit');
  
                                          $codes=array(
                                              'A'=&gt;array(
                                                  '0'=&gt;'0001101','1'=&gt;'0011001','2'=&gt;'0010011','3'=&gt;'0111101','4'=&gt;'0100011',
                                                  '5'=&gt;'0110001','6'=&gt;'0101111','7'=&gt;'0111011','8'=&gt;'0110111','9'=&gt;'0001011'),
                                              'B'=&gt;array(
                                                  '0'=&gt;'0100111','1'=&gt;'0110011','2'=&gt;'0011011','3'=&gt;'0100001','4'=&gt;'0011101',
                                                  '5'=&gt;'0111001','6'=&gt;'0000101','7'=&gt;'0010001','8'=&gt;'0001001','9'=&gt;'0010111'),
                                              'C'=&gt;array(
                                                  '0'=&gt;'1110010','1'=&gt;'1100110','2'=&gt;'1101100','3'=&gt;'1000010','4'=&gt;'1011100',
                                                  '5'=&gt;'1001110','6'=&gt;'1010000','7'=&gt;'1000100','8'=&gt;'1001000','9'=&gt;'1110100')
                                              );
                                          $parities=array(
                                              '0'=&gt;array('A','A','A','A','A','A'),
                                              '1'=&gt;array('A','A','B','A','B','B'),
                                              '2'=&gt;array('A','A','B','B','A','B'),
                                              '3'=&gt;array('A','A','B','B','B','A'),
                                              '4'=&gt;array('A','B','A','A','B','B'),
                                              '5'=&gt;array('A','B','B','A','A','B'),
                                              '6'=&gt;array('A','B','B','B','A','A'),
                                              '7'=&gt;array('A','B','A','B','A','B'),
                                              '8'=&gt;array('A','B','A','B','B','A'),
                                              '9'=&gt;array('A','B','B','A','B','A')
                                              );
                                          $code='101';
                                          $p=$parities[$barcode[0]];
                                          for($i=1;$i&lt;=6;$i++)
                                              $code.=$codes[$p[$i-1]][$barcode[$i]];
                                          $code.='01010';
                                          for($i=7;$i&lt;=12;$i++)
                                              $code.=$codes['C'][$barcode[$i]];
                                          $code.='101';
  
                                          for($i=0;$i&lt;strlen($code);$i++)
                                          {
                                              if($code[$i]=='1')
                                                  $this-&gt;Rect($x+$i*$w,$y,$w,$h,'F');
                                          }
  
                                          $this-&gt;SetFont('Arial','',12);
                                          $this-&gt;Text($x,$y+$h+11/$this-&gt;k,substr($barcode,-$len));
                                      }
  
                                  function PrintComprador($nomeUser,$apelido,$nomeCategoria,$titulo,$nomeImagem,$descricao,$poupa,$desconto,$quantidade)
                                  {
                                      $this-&gt;AddPage();
                                      $this-&gt;NomeComprador($nomeUser,$apelido,$nomeCategoria);
                                      $this-&gt;informacaoImagem($nomeImagem,$titulo,$descricao,$poupa,$desconto,$quantidade);
  
                                  }
  
                                  function PrintOferta($menus,$descricoes)
                                  {
                                      $this-&gt;informacaoOferta($menus,$descricoes);
                                  }
  
                                      function Footer()
                                      {
  
                                      $this-&gt;SetY(-15);
  
                                      $this-&gt;SetFont('DejaVu', '', 8);
  
                                      $this-&gt;Cell(0,10,'Página '.$this-&gt;PageNo().'/{nb}',0,0,'C');
                                      }
                                  }   
                                  $pdf = new FPDF();
                                  $pdf-&gt;AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
                                  $pdf-&gt;AddFont('DejaVu', 'B', 'DejaVuSansCondensed-Bold.ttf', true);
                                  $pdf-&gt;SetFont('DejaVu', '', 14);
                                  $pdf-&gt;AliasNbPages();
                                  for($i = 0; $i &lt; $quantidade; $i++){
                                      $pdf-&gt;PrintComprador($nomeUser,$apelido,$nomeCategoria,$titulo,$nomeImagem,$descricao,$poupa,$desconto,$quantidade);
                                      $random = substr(number_format(time() * rand(),0,'',''),0,12);
                                      $pdf-&gt;EAN13(40,20,$random);
                                      $pdf-&gt;PrintOferta($menus,$descricoes);
                                      $pdf-&gt;Write(40,"Para descobrir a localização, descubra ");
                                      $pdf-&gt;SetFont('','U');
                                      $link = $pdf-&gt;AddLink();
                                      $pdf-&gt;Write(40,'aqui',$hiperlink);
                                      $pdf-&gt;SetFont('DejaVu', 'B', 12);
                                      $pdf-&gt;Ln(2);
                                      $pdf-&gt;Write(70,"Procedimento:");
                                      $pdf-&gt;Ln(2);
                                      $pdf-&gt;SetFont('DejaVu', '', 11);
                                      $pdf-&gt;Write(90,"1- Imprimir o cupão.");
                                      $pdf-&gt;Ln(2);
                                      $pdf-&gt;SetFont('DejaVu', '', 11);
                                      $pdf-&gt;Write(110,"2- Leia atentamente as condições e os detalhes da compra.");
                                      $pdf-&gt;Ln(2);
                                      $pdf-&gt;SetFont('DejaVu', '', 11);
                                      $pdf-&gt;Write(130,"3- Apresentação do cupão no estabelecimento previsto.");
  
                                  }
                                  $file = $pdf-&gt;Output("","S");
  
  
                   $query = "INSERT INTO historico         (nomeUser,email,nomeVoucher,categoria,quantidade,preco,confirmacao,filePDF,idUser) VALUES (?,?,?,?,?,?,?,?,?)";
                      $stmt = $mybd-&gt;prepare($query) or die("Erro na base de dados");
                      $ficheiro = addslashes($file);
                      $stmt-&gt;bind_param("ssssiissi",$nomeUser,$email,$titulo,$nomeCategoria,$quantidade,$total,$confirmacao,$ficheiro,$idUser);
                      $stmt-&gt;execute();               
                      $stmt-&gt;close(); 
  </code></pre>
  
  <p>When I want to retrieve it, I can't show my content and the adobe tell me "Fail to loading pdf"
  I'm using the following code to read content from database:</p>
  
  <pre><code>         $query = "select nomeUser,email,nomeVoucher,categoria,preco,confirmacao,filePDF
                              from historico
                              Where confirmacao = 'a confirmar'
  
                              LIMIT $start, $per_page"; 
                    $stmt = $mybd-&gt;prepare($query);   
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($nomeUser,$email,$nomeVoucher, $categoria, $preco, $confirmacao,$filePDF);
               while ($stmt-&gt;fetch()) {
          if($confirmacao == "a confirmar"){
              echo("&lt;tbody &gt;");           
              echo("&lt;tr&gt;
                      &lt;td&gt;$nomeUser&lt;/td&gt;");
                echo "&lt;td&gt;$email&lt;/td&gt;";
                echo("&lt;td&gt;$nomeVoucher&lt;/td&gt;");
                echo("&lt;td&gt;$categoria&lt;/td&gt;");
                echo("&lt;td&gt;$preco €&lt;/td&gt;");
                echo("&lt;td&gt;$confirmacao&lt;/td&gt;");
                  header('Content-Type: application/pdf');
                  header('Accept-Ranges: bytes');
                  header('Content-Transfer-Encoding: binary');
                  header("Content-Disposition: inline; filename=" . $nomeVoucher .'.pdf');
                  echo $row['data'];
                  die();
                echo"&lt;input type='hidden' name='mail' value='0' /&gt;";
                echo "&lt;th&gt;&lt;input type='checkbox' name='mail' value='1'&gt;&lt;/th&gt;";
                echo("&lt;/tr&gt;");
                echo("&lt;/tbody&gt;");
              }
          }
  </code></pre>
  
  <p>I can't found any answer to my problem.
  Anyone can help me.
  Thanks</p>