user3434928
user3434928

Reputation: 29

FPDF / How to make display correctly

I'm using the fpdf library to output a pdf from html. The .pdf is being created because I can email it to myself and it arrives in the correct format but if I want to download the .pdf as an option without emailing, the output is illegible. The output appears in a browser window(see attached screen shot) and I'm unsure how to fix this issue.

I've also attached a screenshot of how we have our report options set up. 1. HTML 2. PDF 3. Download 4. Email -- the HTML and Email options work, the PDF and Download options do not. I'm focusing on the Download option in this question.

This is the output code that I've tried to test out but no luck

//$pdf->Output("D","D:/example2.pdf");
//$content = $pdf->Output("","S");
//$pdf->Output(); //Outputs on browser screen

//Outputs on browser screen
$pdf->Output();
//echo file_get_contents($pdf);
//readfile($pdf);

Need guidance -- thanks for any help. enter image description here

enter image description here

enter image description here

here is the full code:

 <?php

    $m_header = '<link href="shared/report.css" rel=stylesheet type="text/css">';
    $m_body_tag = ' scroll=no';
    require_once($DOCUMENT_ROOT."inc/top-2.inc.php");

    $i_get_sid = isset($_GET["sid"]) ? (int)$_GET["sid"] : $i_sid;

    $i_get_pass = isset($_GET["a"]) ? $_GET["a"] : $_SESSION['r_pass'];
    $i_get_pass = addslashes($i_get_pass);

    $i_pdf_file_url = 'report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'&b=/report.pdf';

    echo '<table cellpadding=0 cellspacing=0 border=0 width="100%">';
    echo '<tr vAlign=top><td height=7><img src="images/1x1.gif" width=1 height=7></td></tr>';
    echo '<tr height=28 style="background: url(images/bookm-bg.gif) repeat-x"><td width="100%"><nobr>';
    echo '<img src="images/1x1.gif" width=5 height=1><a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'"><img src="images/bookm-42.gif" width=67 height=28 border=0></a><img src="images/bookm-s1.gif" width=10 height=28 border=0><img src="images/bookm-51.gif" width=65 height=28 border=0>&nbsp;<a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'&b=/report.pdf"><img src="images/button-downloadpdf.gif" width=80 height=28 border=0></a>&nbsp;&nbsp;<a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'&b=email"><img src="images/button-emailpdf.gif" width=80 height=28 border=0></a>';
    echo '</nobr></td><td><nobr><font style="font-size: 10px;"><a href="javascript:window.close();">Close Window</a>&nbsp;</font></nobr></td></tr></table>';



(This is what I added as a workaround)echo '<p><a href="'.$i_pdf_file_url.'" name="plugin" width=100% height=100% fullscreen=yes style="position: absolute;">Click Here to open the PDF</p>';

(This is what should display the PDF in the browser but wont' work)
echo '<p><embed type="application/pdf" src="'.$i_pdf_file_url.'" name="plugin" width=100% height=100% fullscreen=yes style="position: absolute;"></p>';


    require_once($DOCUMENT_ROOT."inc/btm-2.inc.php");

    ?>

Upvotes: 1

Views: 1982

Answers (1)

mx0
mx0

Reputation: 7113

From documentation:

Destination where to send the document. It can be one of the following:

  • I: send the file inline to the browser. The PDF viewer is used if available.
  • D: send to the browser and force a file download with the name given by name.
  • F: save to a local file with the name given by name (may include a path).
  • S: return the document as a string.

The default value is I.

If you want to force download with given name, create a link that points to your pdf script and use this:

$pdf->Output("__name__","F");

If you want to display pdf for preview use this:

$pdf->Output("__name__","I");

and in your html inside PDF tab use iframe to embed pdf:

<iframe src="pdf_preview.php" frameborder="0"></iframe>

There are other ways to do this, but this should be the easest.

Upvotes: 1

Related Questions