答案 0 :(得分:3)
由于您希望条形码可视地在单元格内写入名称,因此您需要进行一些定位。单元格和条形码方法更新当前位置。如果您编写条形码,然后将位置重置为条形码调用之前的位置,然后写入名称单元格,它应该位于名称单元格内的某处。
//I'll provide the cell width in write1DBarcode to center the barcode.
$style['cellfitalign'] = 'C';
foreach ($pages as $pk => $p) {
// add a page
$pdf->AddPage();
foreach ($p as $lk => $l) {
foreach ($l as $ck => $c) {
//Get current write position.
$x = $pdf->GetX();
$y = $pdf->GetY();
// The width is set to the the same as the cell containing the name.
// The Y position is also adjusted slightly.
$pdf->write1DBarcode($c->id, 'C128B', '', $y-8.5, 105, 18, 0.4, $style, 'M');
//Reset X,Y so wrapping cell wraps around the barcode's cell.
$pdf->SetXY($x,$y);
$pdf->Cell(105, 51, $c->nome, 1, 0, 'C', FALSE, '', 0, FALSE, 'C', 'B');
}
$pdf->Ln();
}
}
这是我现在得到的结果: