我想使用FPDF将页面分成两列。我正在使用下面的代码,它在两个cloumn中创建了pdf,但问题是列之间的差距有点大。我想减少列之间的差距。
我的代码在这里
class PDF extends FPDF
{
protected $col = 0; // Current column
protected $y0; // Ordinate of column start
function Header()
{
}
function Footer()
{
}
function SetCol($col)
{
// Set position at a given column
$this->col = $col;
$x = 10+$col*50;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
if($this->col<2)
{
// Go to next column
$this->SetCol($this->col+2);
// Set ordinate to top
$this->SetY($this->y0);
// Keep on page
return false;
}
else
{
// Go back to first column
$this->SetCol(0);
// Page break
return true;
}
}
function ChapterBody($file)
{
$txt = file_get_contents($file);
$this->SetFont('Times','',12);
$this->MultiCell(100, 7, $txt);
$this->Ln();
$this->SetCol(0);
}
function PrintChapter($num, $title, $file)
{
// Add chapter
$this->AddPage();
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->Output();
在下图中,您可以看到
答案 0 :(得分:0)
您正在跳至第三列。请参阅下面的每页两列:
function AcceptPageBreak()
{
if($this->col<1)
{
// Go to next column
$this->SetCol($this->col+1);
// Set ordinate to top
$this->SetY($this->y0);
// Keep on page
return false;
}
else
{
// Go back to first column
$this->SetCol(0);
// Page break
return true;
}
}