Try to show pdf file using PHP and fpdf

前端 未结 5 800
灰色年华
灰色年华 2021-01-07 11:19

Background: Its\' a e learning website, when user in the learning stage, it will show content for reading at first 3 pages, and after that it will need user

相关标签:
5条回答
  • 2021-01-07 11:32

    Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;

    Yii::$app->response->headers->add('Content-Type', 'application/pdf');

        $pdf = new FPDF();
    
        $pdf->AliasNbPages();
        $pdf->AddPage();
        $pdf->SetFont('Arial', 'B', 15);
        $pdf->Cell(40, 10, 'Hello World');
        $pdf->Output();
    
    0 讨论(0)
  • 2021-01-07 11:35

    To show fpdf in borwser pass second parameter 'I'

     $filed = $pdf->Output('abc.pdf', 'I');
    
    0 讨论(0)
  • 2021-01-07 11:37

    FPDF allows you a few options in outputting PDFs. You can force the download, save the file to a filesystem, or you can display them on the page, but what you can't do is generate a PDF and show it inline as Jasper mentioned. Here's what you'll do:

    Create a new file (maybe, show_pdf.php):

        require("../fpdf.php");
    
        $pdf = new FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'Hello World!');
        if (preg_match("/MSIE/i", $_SERVER["HTTP_USER_AGENT"])){
            header("Content-type: application/PDF");
        } else {
            header("Content-type: application/PDF");
            header("Content-Type: application/pdf");
        }
        $pdf->Output();
    

    You may need to pass in specific data parameters via $_GET to make this work right as you expand this code.

    To show it on the page, you'll do something like this:

    else if ($cur_page == $no_of_paginations){
    ?>
    <iframe src="show_pdf.php?id=asdfasdf"></iframe>
    <?php
    }
    
    0 讨论(0)
  • 2021-01-07 11:40

    It looks like you're trying to display the PDF inline. To do this you should create an IFRAME with a source that points to your PDF creation script. That way the browser can choose whether or not it can display the PDF, if it can't then the file will be downloadable.

    Main point: the browser doesn't know how to interpret what you're giving it.

    0 讨论(0)
  • 2021-01-07 11:41

    Use a object, $('#fact').html('

    Usted no tiene instalado un pugin para .pdf en este navegador.
    Usted puede usar Este link para descargar el archivo PDF.

    ');

    0 讨论(0)
提交回复
热议问题