Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
851 views
in Technique[技术] by (71.8m points)

pdf - Placing two MultiCells next to each other using FPDF in PHP

I trying to create a custom table using FPDF Cell/MultiCell.

My 1st cell is a MultiCell that has two lines of text. The next cell should then just be placed right next to it.

Problem : no matter what I do to the next cell, it is always on the next line of the page instead of being placed right next to the 1st cell - and it's driving me crazy.

Here is my code:

require_once 'config.php';
require 'fpdf.php';

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->MultiCell(150,10,'Certificate of foreign Currency usage in respect of materials and components in terms of the notes to rebate item ',1);
$pdf->SetFont('Arial','',10);
$pdf->MultiCell(40,10,'DA190',1);
$pdf->Output();

The cell containing the text "DA190" should be placed next to the previous cell, but is being positioned underneath the previous cell.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Before printing your first multicell, record the cursor position:

$x=$this->GetX();
$y=$this->GetY();

add your multicell using $this->Multicell($w,5,'Content');

Reset the cursor position to the start height (y) and the start horizontal + the width of the 1st multicell:

$this->SetXY($x+$w,$y);

Add your next multicell and repeat as necessary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...