简体   繁体   English

从php生成的HTML表生成PDF

[英]Generating PDF from php generated HTML table

Anyone can help me generating pdf using MPDF for the following code. 任何人都可以帮助我使用MPDF为以下代码生成pdf。

<table width="360" height="161" border="1" class="tablestyle">
<tr>
<td height="36" colspan="5" bgcolor="#ECE9D8"><div align="center" class="style6">ACADEMIC PERFORMANCE - <br />
UNIT TEST</div></td>
</tr>
<tr>
<td width="89"><div align="center" class="style3 style8">SUBJECTS</div></td>
<td width="73"><div align="center" class="style9">No. Of Tests</div></td>
<td width="82"><div align="center" class="style9">Mark Obtained</div></td>
<td width="82"><div align="center" class="style9">Full Mark</div></td>
<td width="88"><div align="center" class="style9">12.5% of <br />Mark Scored</div></td>
</tr>
<?php do { ?>
<tr>
<td><span class="style7">&nbsp;<?php echo $row_dep['Subject'];?></span></td>
<td><div align="center"><?php echo $row_dep['times'];?></div></td>
<td><div align="center"><?php echo $row_dep['score'];?></div></td>
<td><div align="center"><?php echo $row_dep['fm'];?></div></td>
<td><div align="center"><?php echo  number_format($row_dep['score']/$row_dep['fm']*12.5,2); ?></div></td>
</tr>
<?php } while ($row_dep = mysql_fetch_assoc($dep)); ?>
<tr>
<td bgcolor="#ECE9D8"><div align="center"><strong>Total</strong></div></td>
<td bgcolor="#ECE9D8"><div align="center"><?php echo $row_exe['ex'];?></div></td>
<td bgcolor="#ECE9D8"><div align="center"><?php echo $row_unit['utotal'];?></div></td>
<td bgcolor="#ECE9D8"><div align="center"><?php echo $row_unfm['ufm'];?></div></td>
<td bgcolor="#ECE9D8"><div align="center"><strong><?php echo number_format($row_unit['utotal']/$row_unfm['ufm']*12.5,2); ?></strong></div></td>
</tr>
<tr>
<td colspan="2"><div align="right"><strong>Grade:</strong></div></td>
<td><div align="center"><strong><?php 
$div=$row_unit['utotal']/$row_unfm['ufm']*100;
if  ($div>=90)
{
echo "A1";
}
    elseif($div>=80)
{
echo "A2"; 
}
elseif($div>=70)
{
    echo "B1"; 
}
elseif($div>=60)
{
    echo "B2"; 
}
elseif($div>=50)
{
    echo "C1"; 
}
elseif($div>=40)
{
echo "C2"; 
}
elseif($div>=33)
{
echo "D"; 
}
elseif($div>=21)
{
echo "<font color=red>E1</font>"; 
}            
else
{
    echo "<font color=red>E2</font>"; 
}
?></strong></div></td>
<td><strong><div align="center">Percentage</strong></div></td>
<td><strong><div align="center">
<?php
echo number_format($row_unit['utotal']/$row_unfm['ufm']*100,2);
?>%
</strong></div></td>
</tr>
</table>

I want to put the above table inside $html , I have been trying with some samples given in the MPDF manual but could not figure out how to output. 我想把上面的表放在$html ,我一直在尝试MPDF手册中给出的一些样本但是无法弄清楚如何输出。 For example, for printing <?php echo $row_dep['Name_of_Student'];?> in $HMTL I know that I can use '.$row_dep['Name_of_Student'].' 例如,要在$HMTL打印<?php echo $row_dep['Name_of_Student'];?> ,我知道我可以使用'.$row_dep['Name_of_Student'].' but when it comes to generating rows as I have here in between <?php do { ?> and <?php } while ($row_dep = mysql_fetch_assoc($dep)); ?> 但是当涉及到生成行时,我在这里<?php do { ?><?php } while ($row_dep = mysql_fetch_assoc($dep)); ?> <?php } while ($row_dep = mysql_fetch_assoc($dep)); ?> I don't know and could not produce the desired output. <?php } while ($row_dep = mysql_fetch_assoc($dep)); ?>我不知道也无法产生所需的输出。

Here is how this can be done... 以下是如何做到这一点......

<?php 
include("mpdf.php");

ini_set('memory_limit','3000M');//extending php memory
$mpdf=new mPDF('win-1252','A4-L','','',15,10,16,10,10,10);//A4 size page in landscape orientation
$mpdf->SetHeader('Put your header here');
$mpdf->setFooter('{PAGENO}');
$mpdf->useOnlyCoreFonts = true;    // false is default
//$mpdf->SetWatermarkText("any text");
//$mpdf->showWatermarkText = true;
//$mpdf->watermark_font = 'DejaVuSansCondensed';
//$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetWatermarkImage('logo.png');
$mpdf->showWatermarkImage = true;


// Buffer the following html with PHP so we can store it to a variable later
ob_start();
?>
<?php include "yourphp.php";//The php page you want to convert to pdf
 // asasas?>

<?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(), 'mawiahl', 'password');//for password protecting your pdf

$mpdf->Output();
exit;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM