我正在使用 TCPDF 库构建 PDF 以显示调查结果。我可以选择创建一个自定义标题以添加到调查中,它可以是从图像到文本的任何内容,可以是任何大小/长度。
我的问题是在自动中断时,下一页的 Y 位置被重置并与标题一起运行。
我可以通过捕获当前 Y 位置并在“AddPage()”函数之后设置它来更改第一页。我的问题出在发生的自动分页符上,无论如何我都找不到检查是否发生这种情况并触发某些事情发生。
我找到了“checkpagebreak”,但这不适用于在多单元文本块期间发生分页符时。我检查了 TCPDF 的“自定义标题”示例,但它似乎使用静态大小的标题边距,我需要找到一种方法使该值动态化。
我正在使用以下代码
// **************************************************************************************
// Process Selection
// **************************************************************************************
function RunReport()
{
// Make all global variables available here
foreach($GLOBALS as $arraykey=>$arrayvalue)
{
if ($arraykey != "GLOBALS")
{
global $$arraykey;
}
}
require_once('tcpdf/tcpdf.php');
class PDF extends tcpdf
{
function Header()
{
//This is pulled from a database but is filled in only to show the current data I am working with***
// $this->S1LDESC = "<center>Test Application<br><img src=\"link/to/image\" width='208'; height='80'></img></center>";
if(trim($this->S1LDESC) <> "")
{
$this->SetFont('Times','',11);
$this->Cell(0, .5, "" , 0,1,'C', 0);
$newX = $this->GetX();
$newY = $this->GetY();
$this->writeHTMLCell(0, .5, $newX, $newY, trim($this->S1LDESC) , 0,1,0, true, 'C', true);
}
$this->SetFont('Times','B',11);
$this->Cell(0, .5, "" , 0,1,'C', 0);
$this->Cell(0, .5, trim($this->S1DESC), 0, 1, 'C', 0, '', 0, false, 'M', 'M');
$this->HeadY = $this->GetY();
$this->SetY($this->GetY() + 5);
}
}
$pdf = new PDF("P", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SelComp = $SelComp;
$pdf->SelSchool = $SelSchool;
// set auto page breaks
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setFontSubsetting(false);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
//$pdf->SetY($pdf->HeadY);
$selstring = "SQL To Grab DATA";
if (!($result = db2_exec($db2conn, $selstring, array('CURSOR' => DB2_SCROLLABLE))))
{
echo($selstring."<BR>");
db2_close($db2conn);
die("<b>Error RunReport ". db2_stmt_error().":" . db2_stmt_errormsg()."</b><br>" . $selstring2);
}
while($row = db2_fetch_assoc($result))
{
// make the file field names available in HTML
foreach(array_keys($row) as $key)
{
$escapedField = $key;
$$escapedField = $row[$key];
}
$pdf->SetFont('Times','B',11);
if($HldGroup <> $S2GROUP)
{
$HldGroup = $S2GROUP;
if(trim($S5GROUP) <> "*None")
{
//Write Group data
$pdf->MultiCell(0, 5, trim($S5GROUP), 0, 'L', 0, 1, '', '', true);
if(trim($S5GRPDESC) <> "")
{
$pdf->MultiCell(0, 5, trim($S5GRPDESC), 0, 'L', 0, 1, '', '', true);
}
}
}
if($S2QUESTTYP <> "HD")
{
$pdf->Cell(5, 0, "", 0,0,'C', 0);
$pdf->MultiCell(0, 5, trim($S2QUESTION), 0, 'L', 0, 1, '', '', true);
$pdf->SetFont('Times','',11);
if($S2QUESTTYP <> "ND")
{
$pdf->MultiCell(0, 5, trim($S2QUESTION), 0, 'L', 0, 1, '', '', true);
}
else
{
}
$pdf->MultiCell(0, 5, "", 0, 'L', 0, 1, '', '', true);
}
}
//Print file with Student name and report name???
$pdf->Output("$SurvName.pdf", 'I');
}

