TCPDF - 页面底部的空白 | 页面底部的空白
本文介绍了TCPDF - 页面底部的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述 我正在使用 TCPDF 生成 pdf.第一个 PDF 最终生成了一个空白页,但我通过删除第 2 页来修复它.问题是,没有为整页设置 PDF 背景颜色.pdf 页面底部的高度空间大约有 100px 长,没有背景颜色.我需要浅蓝色的页面背景颜色,从上到下都在那里.我的文档没有页眉或页脚.代码如下:
SetMargins(0, 0, 0);//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);$pdf->SetFooterMargin(0);//设置自动分页符//$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);//设置图像比例因子//$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);//设置一些与语言相关的字符串(可选)if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {require_once(dirname(__FILE__).'/lang/eng.php');$pdf->setLanguageArray($l);}//---------------------------------------------------------//设置字体$pdf->SetFont('helvetica', '', 9);//添加一个页面$pdf->AddPage();$pdf->setPageMark();$html = '<table height="800" style="background-color: rgb(232,239,242);width:100%" cellspacing="0" cellpadding="0"><tr><td colspan="3" align="center"><img src="images/Logopdf.png" width="545" border="0"/><img src="images/star.png" width="859" height="43"/></td></tr><tr><td colspan="3"><div style="margin:0 auto; width:100%;"><div style="float:left; margin:0px 0px 0px 70px; border:none;"> <img src="'.$img1.'" width="415" height="518" align="left"/> <img src="'.$img2.'" width="415" height="518" align="left"/><br><div style="margin-top:35%;"><div> nbsp; <img src="images/star.png" width="859" height="43" style="margin-top:50px;"/></div></div></div>
</td></tr><tr><td colspan="3"><div style="margin:0 auto; width:100%;"><div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56); "> & nbsp; nbsp; nbsp; nbsp; nbsp; <span class="topname" style="color: rgb(82, 59, 56); font-weight: bold;text-transform:uppercase;"><font size="+8">'.strtoupper($unique_profile['name']).'</font></span></div><div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);"> nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; <span style="color: rgb(82, 59,56);"><font size="+6">D.O.B : '.$unique_profile['生日'].'</font></span></div><div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);"> nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; <span style="color: rgb(82, 59,56);"><font size="+6">HEIGHT : '.$unique_profile['height'].'CMS</font></span></div><div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);"> nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; <span style="color: rgb(82, 59,56);">><div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);"> nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; <span style="color: rgb(82, 59,56);"><font size="+6">AGE : '.$final_year.'</font></span></div><div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);"> nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; <span style="color: rgb(82, 59,56);"><font size="+6">头发 : '.$unique_profile["hair_color"].'</font></span></div>
<div style="float:left; margin:20px 0px 0px 0px;"> nbsp; nbsp; nbsp; nbsp; <span style="color: rgb(82, 59,56);">><font size="+6">TEL 01883 744488 [email protected] </font></span></div><div style="float:left; margin:200px 0px 0px 0px;"> nbsp; nbsp; nbsp; nbsp;
<div> nbsp; nbsp; nbsp; nbsp;
</td></tr><tr><td style="width:20%"></td><td style="width:40%"><表><tr><td colspan="2"></td></tr><tr><td style="width:20%"></td><td style="width:40%"></td><td style="width:30%"></td></tr></td></tr>
';$pdf->writeHTML($html,true, true, false);//重置指向最后一页的指针$pdf->lastPage();$pdf->deletePage(2);//---------------------------------------------------------//关闭并输出PDF文档$pdf->Output('my_document.pdf', 'D');//==============================================================+//文件结束//==============================================================+?>
请建议我如何为整个 pdf 文件的第 1 页设置浅蓝色背景.底部不应有空白.
解决方案
您可以尝试在当前调用 AddPage()
后立即添加这两行:
$pdf->SetFillColor( 232, 239, 242 );$pdf-> Rect( 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight(), 'F' );
这理论上意味着您可以去掉背景颜色样式声明(实际上,您可能必须 去掉那个声明).
I am generating a pdf using TCPDF. First PDF was being generated a blank page in the end, but i fixed it by deleting page 2. Noe the problem is, the PDF background color is not being set for full page. There is about 100px long in height space at bottom of pdf page which does not have a background color. I need the page background color which is light blue, to be there from top to bottom. My document does not have header or footer. Here is the code:
<?php
require_once('tcpdf/tcpdf.php');
// create new PDF document
$pagelayout = array(430,330); // or array($height, $width)
//define ('PDF_MARGIN_TOP', 19);
//new TCPDF('p', 'pt', $pageLayout, true, 'UTF-8', false);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $pagelayout, true, 'UTF-8', false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(0, 0, 0);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(0);
// set auto page breaks
//$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
//$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 9);
// add a page
$pdf->AddPage();
$pdf->setPageMark();
$html = '<body>
<table height="800" style="background-color: rgb(232,239,242);width:100%" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" align="center">
<img src="images/Logopdf.png" width="545" border="0" />
<img src="images/star.png" width="859" height="43" />
</td>
</tr>
<tr>
<td colspan="3">
<div style="margin:0 auto; width:100%;">
<div style="float:left; margin:0px 0px 0px 70px; border:none;">
<img src="'.$img1.'" width="415" height="518" align="left" /> <img src="'.$img2.'" width="415" height="518" align="left"/><br><div style="margin-top:35%;"><div> <img src="images/star.png" width="859" height="43" style="margin-top:50px;" /></div>
</div></div>
</div>
</td>
</tr>
<tr>
<td colspan="3">
<div style="margin:0 auto; width:100%;">
<div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56); ">
<span class="topname" style="color: rgb(82, 59, 56); font-weight: bold;text-transform:uppercase;"><font size="+8"> '.strtoupper($unique_profile['name']).'</font></span></div>
<div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);">
<span style="color: rgb(82, 59, 56);"><font size="+6"> D.O.B :
'.$unique_profile['birthday'].'</font></span></div>
<div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);">
<span style="color: rgb(82, 59, 56);"><font size="+6">HEIGHT : '.$unique_profile['height'].'CMS</font></span></div>
<div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);">
<span style="color: rgb(82, 59, 56);"><font size="+5">SHOE SIZE : '.$unique_profile['shoe_no'].'</font></span></div>
<div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);">
<span style="color: rgb(82, 59, 56);"><font size="+6">AGE : '.$final_year.'</font></span></div>
<div style="float:left; margin:20px 0px 0px 0px; width:100%; color: rgb(82, 59, 56);">
<span style="color: rgb(82, 59, 56);"><font size="+6">HAIR : '.$unique_profile["hair_color"].'</font></span></div>
</div>
<div style="float:left; margin:20px 0px 0px 0px;"> <span style="color: rgb(82, 59, 56);"><font size="+6">TEL 01883 744488 [email protected] </font></span></div>
<div style="float:left; margin:200px 0px 0px 0px;">
</div>
<div>
</div>
</td>
</tr>
<tr>
<td style="width:20%"></td>
<td style="width:40%">
<table >
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td style="width:20%"></td>
<td style="width:40%">
</td>
<td style="width:30%"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>';
$pdf->writeHTML($html,true, true, false);
// reset pointer to the last page
$pdf->lastPage();
$pdf->deletePage(2);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('my_document.pdf', 'D');
//============================================================+
// END OF FILE
//============================================================+
?>
Please suggest how can I have a light blue background for whole of page 1 of pdf file. There should be no white space at the bottom.
解决方案
You could try adding these two lines right after the current call to AddPage()
:
$pdf->SetFillColor( 232, 239, 242 );
$pdf->Rect( 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight(), 'F' );
This theoretically means you could get rid of the background-color style declaration (indeed, you might have to get rid of that declaration).
这篇关于TCPDF - 页面底部的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-23 08:15