jeudi 25 août 2016

failed to load pdf from mysql using fpdf

$sql = "SELECT doc FROM file_loc where file_id='1'";

while($results = mysql_query("$sql") or die("Invalid query: " . mysql_error());
{
    // set the header for the image
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename = "' .$results . '"');
    header('Content-Transfer-Encoding: binary');

    if (isset($results))
    {
        $pdf = new FPDI();

        // get the page count
        $pageCount = $pdf->setSourceFile($results);

        // iterate through all pages
        for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
            // import a page
            $templateId = $pdf->importPage($pageNo);

            // get the size of the imported page
            $size = $pdf->getTemplateSize($templateId);

             // create a page (landscape or portrait depending on the imported page size)
            if ($size['w'] > $size['h']) {
                $pdf->AddPage('L', array($size['w'], $size['h']));
            } else {
                $pdf->AddPage('P', array($size['w'], $size['h']));
            }

            // use the imported page
            $pdf->useTemplate($templateId);

            if ($size['w'] > $size['h']) {
                $pdf->SetFont('Helvetica');
                $pdf->SetXY(500, 189);
                $pdf->Write(0, 'A complete document imported with FPDI landscape');
            } else {
                $pdf->SetFont('Helvetica');
                $pdf->SetXY(5, 260);
                $pdf->Write(0, 'A complete document imported with FPDI portrait');
            }
      }

      // Output the new PDF
      $pdf->Output('newpdf.pdf', 'D');
}

using these codes the pdf is not displaying in my browser error message (failed to load pdf). when i use comment the fpdi section my pdf display normally and then i uncomment the fpdi section it gives message i am new to fpdf and fpdi libraries please help!!




Aucun commentaire:

Enregistrer un commentaire