Php TCPDF Y位置正在重置
我正在使用TCPDF库构建PDF以显示调查结果。我可以选择创建要添加到调查中的自定义标题,该标题可以是任何内容,从图像到文本,可以是任何大小/长度 我的问题是在自动破解时,下一页的Y位置被重置并与页眉一起运行 我可以通过捕获当前Y位置并将其设置在“AddPage()”函数之后来更改第一页。我的问题是发生的自动分页中断,我找不到任何方法来检查是否发生了这种情况并触发一些事情发生 我找到了“checkpagebreak”,但这不适用于在多单元格文本块中出现分页符的情况。我检查了TCPDF的“自定义页眉”示例,但它似乎使用了静态大小的页眉边距,我需要找到一种方法使该值动态 我正在使用以下代码Php TCPDF Y位置正在重置,php,tcpdf,Php,Tcpdf,我正在使用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');
}
//**************************************************************************************
//工艺选择
// **************************************************************************************
函数RunReport()
{
//使所有全局变量在此可用
foreach($arraykey=>$arrayvalue的全局值)
{
如果($arraykey!=“全球”)
{
全球$$arraykey;
}
}
一次需要_('tcpdf/tcpdf.php');
类PDF扩展了tcpdf
{
函数头()
{
//这是从数据库中提取的,但填写时仅显示我正在处理的当前数据***
//$this->S1LDESC=“测试应用程序
”;
如果(修剪($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=新pdf(“P”,pdf单位,pdf页面格式,真,'UTF-8',假);
$pdf->SelComp=$SelComp;
$pdf->SelSchool=$SelSchool;
//设置自动分页符
$pdf->SetAutoPageBreak(true,pdf\u MARGIN\u BOTTOM);
$pdf->setFontSubsetting(假);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
//$pdf->SetY($pdf->HeadY);
$selstring=“获取数据的SQL”;
if(!($result=db2_exec($db2conn,$selstring,array('CURSOR'=>db2_SCROLLABLE)))
{
回声($selstring.“
”);
db2_close($db2conn);
die(“Error RunReport.db2_stmt_Error()。”:“.db2_stmt_errormsg()。”
“$selstring2);
}
while($row=db2\u fetch\u assoc($result))
{
//使文件字段名在HTML中可用
foreach(数组_键($row)作为$key)
{
$escapedField=$key;
$$escapedField=$row[$key];
}
$pdf->SetFont('Times','B',11);
if($HldGroup$S2GROUP)
{
$HldGroup=$S2GROUP;
如果(修剪($S5GROUP)“*无”)
{
//写入组数据
$pdf->MultiCell(0,5,trim($S5GROUP),0'L',0,1','',true);
如果(修剪($S5GRPDESC)”)
{
$pdf->MultiCell(0,5,trim($S5GRPDESC),0'L',0,1','',true);
}
}
}
如果($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);
如果($S2QUESTTYP“ND”)
{
$pdf->MultiCell(0,5,trim($S2QUESTION),0'L',0,1','',true);
}
其他的
{
}
$pdf->MultiCell(0,5,”,0,'L',0,1,,'',true);
}
}
//打印带有学生姓名和报告姓名的文件???
$pdf->Output($SurvName.pdf,'I');
}
其结果如下:
第1页:
第2页:
通常,页眉自定义包括Y的定位,以便在文本开始之前在页眉下方留出空间。我通常使用
$this->SetY($this->GetY()+5)代码>。看起来您正在尝试在PDF创建期间执行此操作,而不是让header函数执行。@Dave我在一次测试期间尝试过此操作,但仍然导致了相同的问题,似乎页眉中设置的Y位置会被忽略,并且在超出页眉功能时会被重置。如果发生这种情况,则必须是代码中的某个内容在执行此操作。每次在AutoPageBreak
函数AddPage()中设置的底部边距下方绘制某个内容时
函数被调用,该函数依次调用Header()
函数。您不需要调用SetY()
只需在标题()的末尾执行$this->Ln()
,我尝试使用$this->Ln()代替SetY,结果仍然相同。使用writehtmlcell会弄乱什么吗?如果我去掉这一行,一切都会按预期进行,但这不是一个选项,因为我需要它来处理writehtmlcell。通常,标题自定义会包括一个Y定位,以便在文本开始之前在标题下留出空间。我通常使用$this->SetY($this->GetY()+5)代码>。看起来您正在尝试在PDF创建期间执行此操作,而不是让header函数执行。@Dave我在一次测试期间尝试过此操作,但仍然导致了相同的问题,似乎头中设置的Y位置被忽略,并且在头函数之外时被重置。如果发生这种情况,则必须是代码中的某个部分在执行此操作。每次