php将页面转换为带有id的pdf加载

时间:2015-12-14 07:27:57

标签: php mysql mpdf

我有来自MySQL DB的动态加载,我的页面网址为http://localhost/far/contractview?ID=137。当我尝试将此页面转换为PDF时,我遇到了一些错误,而且我不知道如何处理,只需点击一下按钮就可以将此页面转换为PDF格式。

我在下面提供了我的代码。我正在使用mpdf

<?php 
require("mpdf60/mpdf.php");
$mpdf=new mPDF('application/pdf','Letter-L','','',15,10,16,10,10,10);//A4 page in portrait for landscape add -L.
$mpdf->debug = true;
//$mpdf->allow_output_buffering = true;
//$mpdf->SetHeader('|Your Header here|');
//$mpdf->setFooter('{PAGENO}');// Giving page number to your footer.
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetDisplayMode('fullpage');
// Buffer the following html with PHP so we can store it to a variable later
ob_start();
?>
<?php 
//include "contractview.php";
include_once "users.php";
 //This is your php page ?>
<?php 
$html = ob_get_contents();
ob_end_clean();
// send the captured HTML from the output buffer to the mPDF class for processing
$mpdf->WriteHTML($html);
//$mpdf->SetProtection(array(), 'user', 'password'); uncomment to protect your pdf page with password.
$mpdf->Output();
exit;
?>

提前致谢。

1 个答案:

答案 0 :(得分:0)

  1. 首先从php的官方网站下载FPDF。
  2. http://www.fpdf.org/en/dl.php?v=17&f=zip

    2.将其输入Web服务器文件夹。

    3.使用require将其与php文件连接。

    创建-pdf.php

    <?php
    require("fpdf17/fpdf.php");
    
    $pdf=new FPDF();
    //var_dump(get_class_methods($pdf));
    $pdf->AddPage();
    
    //------------------------
    $pdf->Image("hello.jpg");
    $pdf->SetFont("arial","B","20");
    
    $pdf->Cell(0,20,"hello world",1,1,"C");
    $pdf->SetFont("arial","I","10");
    
    $pdf->Cell(0,30,"Second line Italic",1,1,"C");
    $pdf->SetFont("arial","B","20");
    
    $pdf->Cell(0,40,"thired line",1,1,"C");
    $pdf->Output();
    ?>
    

    查看此链接https://topdf.org/html-code http://php999.blogspot.in/2014/01/pdf-generation-in-php.html