php - 如何在 $pdf->cell() 中回显 cod39 值或将其存储在变量中并在表格中打印结果?
问题描述
我正在尝试在 FPDF 中打印一个有 4 列的表,并且从 MySQL 检索到许多行。
我的两列应使用code39
FPDF 打印条形码中的值。问题是它不允许我code39
在单元格中打印结果。我只能通过将位置添加到$i
并将其添加到code39
. 即使一页打印正确,它也会不同步。
如果您检查输出,您将看到我遇到的问题。
foreach ($result as $row) {
$pdf->Code39(12,47+$i,'%'.$row['activity'].' START',1,10);
$pdf->Code39(209,47+$i,'%'.$row['activity'].' END',1,10);
$pdf->Cell($width_cell[0],20,'',1,0,'c',false); // First column of row 1
$pdf->Cell($width_cell[1],20,$row['activity'],1,0,'c',false); // Second column of row 1
$pdf->Cell($width_cell[2],20,$row['a_description'],1,0,'c',false); // Third column of row 1
$pdf->Cell($width_cell[3],20,'',1,1,'c',false); // Fourth column of row 1
$i=$i+20;
}
输出:
解决方案
在编写一个应该包含条形码的单元格之前,使用文档中当前光标位置作为坐标来绘制条形码
foreach ($result as $row) {
$pdf->Code39($pdf->GetX(), $pdf->GetY(), '%'.$row['activity'].' START',1,10);
$pdf->Cell($width_cell[0],20,'',1,0,'c',false); // First column of row 1
$pdf->Cell($width_cell[1],20,$row['activity'],1,0,'c',false); // Second column of row 1
$pdf->Cell($width_cell[2],20,$row['a_description'],1,0,'c',false); // Third column of row 1
$pdf->Code39($pdf->GetX(), $pdf->GetY(), '%'.$row['activity'].' END',1,10);
$pdf->Cell($width_cell[3],20,'',1,1,'c',false); // Fourth column of row 1
}
我没有测试过这个。您可能必须在 GetX 和 GetY 上添加或减去偏移量,以使其看起来不错。
推荐阅读
- mysql - MySQL 语法检查
- reactjs - React — 简化数据存储而不是 Redux,优缺点是什么?
- go - 谷歌可以使用 Go 数据存储层次结构树过滤子级
- php - 从 AJAX 调用下载文件而不将其保存到网络服务器
- c# - 如何使用 rest Sharp 传递 x-APi-key
- android - 运行时更改状态栏灯状态
- if-statement - Google 表格中的 IF 语句
- mongodb - 使用区块链时,您真的需要 AWS 或 MongoDB 等数据库服务吗?
- html - 获取 CSS 缩放变换以更改垂直滚动条?
- python - 如何用 df1 替换 df 列名