我已经玩了几天的fpdf,很不错:) 但我现在正试图编写一些更先进的代码: 与AddLink和SetLink的简单链接是可以的,但如果我尝试在foreach循环中执行相同的操作:
//Page2:
$index=0;
foreach ($InfosList as $infos) {
$index+=1;
$stringC=$infos['name'].", ".$infos['firstname'];
${"link_".$index}=$pdf->AddLink();//dynamic varnames
$pdf->Write(pdf::$linespacing,$StringC,${"link_".$index});
}
//Page3s:
foreach ($InfosList as $infos) {
$pdf->AddPage("P","A4");
$pdf->SetLink(${"link_".$index});
...
}
我收到了错误:
注意:未定义的偏移量:在第1524行的... / lib / vendor / fpdf181 / fpdf.php中为0:
$annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
整个fpdf功能:
protected function _putpage($n)
{
$this->_newobj();
$this->_put('<</Type /Page');
$this->_put('/Parent 1 0 R');
if(isset($this->PageInfo[$n]['size']))
$this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
if(isset($this->PageInfo[$n]['rotation']))
$this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
$this->_put('/Resources 2 0 R');
if(isset($this->PageLinks[$n]))
{
// Links
$annots = '/Annots [';
foreach($this->PageLinks[$n] as $pl)
{
$rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
$annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
if(is_string($pl[4]))
$annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
else
{
$l = $this->links[$pl[4]];
if(isset($this->PageInfo[$l[0]]['size']))
$h = $this->PageInfo[$l[0]]['size'][1];
else
$h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k;
$annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
}
}
$this->_put($annots.']');
}
if($this->WithAlpha)
$this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
$this->_put('/Contents '.($this->n+1).' 0 R>>');
$this->_put('endobj');
// Page content
if(!empty($this->AliasNbPages))
$this->pages[$n] = str_replace($this->AliasNbPages,$this->page,$this->pages[$n]);
$this->_putstreamobject($this->pages[$n]);
}
我能做什么? 提前致谢
答案 0 :(得分:1)
$ index未定义第3页,现在很明显......
परेटो- श्रेष्�