doukai1226 2017-06-04 01:11
浏览 93

FPDF /如何正确显示

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);
  • the $pdf->Output(); is generating the illegible code the readfile
  • echo and file_get_contents throw errors
  • the $pdf->Output(... gives me an error that says Incorrect Output Destination (see attached screenshot)

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");

    ?>
  • 写回答

1条回答 默认 最新

  • donglun2010 2017-06-11 10:34
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line