FPDF file is not showing in some browser when the output is view type ,

37 Views Asked by At

In most of the browsers the iframe tag shows the pdf file based on the data i submit on select option , in the fpdf file code page i used the output as 'I' to show , but it download automatically

<iframe   src="../admin/customer_ledger_report.php?sel_customer=<?php echo $_REQUEST['sel_customer'];?>&financial_id=<?php echo $_REQUEST['financial_id'];?>&sel_company=<?php echo $_REQUEST['sel_company'];?> " width="100%" style="min-height: 768px;overflow-y: scroll;"></iframe>

<script>
 $(function () {
        $('#jvalidate').submit(function (e) {
            e.preventDefault();

            // Get the selected values
            var financial_id = $('#financial_id').val();
            var sel_company = $('#sel_company').val();
            var sel_customer = $('#sel_customer').val();

            // Construct the URL for the iframe
            var iframeUrl = "../admin/customer_ledger_report.php?sel_customer=" + sel_customer + "&financial_id=" + financial_id + "&sel_company=" + sel_company;

            // Set the iframe source
            $('#pdf-iframe iframe').attr('src', iframeUrl);
            if (financial_id && sel_company && sel_customer) {
            // Show the iframe
            $('#pdf-iframe').show();
            displayPieChart(sel_company, sel_customer, financial_id);
            }

            return false;
        });
    });
</script>

In the customer_ledger_report.php file i used

<?php 

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="output.pdf"');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');

require('session.php');
require('pdf-generate/fpdf.php');
extract($_REQUEST);

$pdf->Ln();
       $pdf->Output('output.pdf', 'I');
$pdf->Close();

what i am excepting is that the pdf need to be support all type of browser to show the pdf file instead of auto downloading

1

There are 1 best solutions below

0
CarlosH. On

From what I remember FPDF is the base to the most complete library TCPDF. On TCPDF, I do not need to setup any headers when I do the output. It just output to the client. It goes like this:

//default initial variables
$d=(object)['orientation'=>'P', 'unit'=>'pt', 'format'=>'LETTER', 'unicode'=>true, 'encoding'=>'UTF-8', 'diskcache'=>false, 'pdfa'=>false];
$pdf=new TCPDF($d->orientation,$d->unit,$d->format,$d->unicode,$d->encoding,$d->diskcache,$d->pdfa);
$pdf->AddPage('P', [612,792], true);
$pdf->Cell(600, 0, 'Test text', 0, 1, 'C', 0, '', 1);
//Close and output PDF document
$pdf->Output('output.pdf', 'I');
exit(0);

This is a simplified version as there a more required setting for the PDF (creator, author, title, subject, display mode, ...). Adding a page and a line of text should be enough to generate a PDF.

A detail, TCPDF do not need to Close the PDF as it will do it automatically when Output is called.

After checking the status an documentation for FPDF, it looks like this library is abandoned and no more updates. Also the documentation mention that the Output function signature is this:

function Output($dest='', $name='', $isUTF8=false)

So that means, if you are using the original FPDF then the parameters are in different position.

However, it looks like there is another version from SetaSign which is a drop-in replacement of FPDF with TCPDF.