- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 fpdf 库创建 pdf 表结构时遇到问题。当特定单元格的任何数据具有长字符串时,单元格数据将与其他单元格数据重叠。 自动调整 fpdf 中的单元格宽度...请帮助我...
我的代码:
<?php
require("fpdf/fpdf.php");
//Connect to your database
$mysqli = new mysqli('localhost', 'root', '', 'mus');
/*
* This is the "official" OO way to do it,
*/
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
//Create new pdf file
$pdf=new FPDF();
//Open file
$pdf->Open();
//Disable automatic page break
$pdf->SetAutoPageBreak(false);
//Add first page
$pdf->AddPage();
//set initial y axis position per page
$y_axis_initial = 25;
//print column titles for the actual page
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetY($y_axis_initial);
$pdf->SetX(5);
$pdf->Cell(10, 6, 'CODE', 1, 0, 'L', 1);
$pdf->Cell(40, 6, 'NAME', 1, 0, 'L', 1);
$pdf->Cell(40, 6, 'PRICE', 1, 0, 'L', 1);
$row_height = 6;
$y_axis = $y_axis_initial + $row_height;
//Select the Products you want to show in your PDF file
$sql = 'SELECT WaiterPckey, WaiterName, WaiterShortName FROM `waitermaster`';
$result= $mysqli->query($sql);
//initialize counter
$i = 0;
//Set maximum rows per page
$max = 25;
//Set Row Height
;
while($row = $result->fetch_row())
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY($y_axis_initial);
$pdf->SetX(4);
$pdf->Cell(10, 6, 'CODE', 1, 0, 'L', 1);
$pdf->Cell(40, 6, 'NAME', 1, 0, 'L', 1);
$pdf->Cell(40, 6, 'PRICE', 1, 0, 'L', 1);
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$code = $row[0];
$price = $row[1];
$name = $row[2];
$pdf->SetY($y_axis);
$pdf->SetX(5);
$pdf->Cell(10, 6, $code, 1, 0, 'L', 1);
$pdf->Cell(40, 6, $name, 1, 0, 'L', 1);
$pdf->Cell(40, 6, $price, 1, 0, 'L', 1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
//Create file
$pdf->Output();
?>
?>
最佳答案
使用 string 单元格宽度
$string = fullname($USER);
$cellWidth = $pdf->GetStringWidth($string);
$pdf->Cell($cellWidth + 5, 0, $string, 0, 0, 'C', true);
关于php - 如何使用php和mysql自动调整fpdf中的单元格宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25603371/
我有一个从帖子表单生成的 pdf (fpdf)。我希望 pdf 在新选项卡和/或窗口中打开,提示用户保存 pdf。我猜我需要将输出保存为字符串 $data=$pdf->Output("OfficeFo
我正在使用 Python 3.8.5、conda 4.10.3 和 FPDF2 2.3.1 当我尝试导入包时,出现以下错误: 输入: from fpdf import FPDF 响应: -------
在我的应用程序中,PDF 在网页中打开,在下面的示例中,当用户单击 Logo.png 时,它被重定向到同一页面中的 FPDF 站点,但我想在新窗口中打开链接,而不是在同一个窗口中打开,因此用户打开了
我使用了 fpdf 库并根据 fpdf 的官方文档使用它。 我想在我的文件中使用标题但不能使用它,下面是我的代码。请纠正我的错误,为什么标题没有出现.. 这是我的代码: SetFont('Arial'
所以我想用 php 修改一个 pdf 模板。 我环顾四周,发现大多数人都使用 FPDI,于是我试了一下。 所以我做的是 include('pdf/fpdf.php'); include('pdf/fp
对于我的项目,我必须生成一个 PDF 文件。Stackoverflow 告诉我使用 FPDF。所以,我按照教程进行操作,但它似乎不起作用。 public function makePdf(Reques
我无法在关于同一主题的几篇文章中找到我的问题的答案,这就是为什么我将在这里提出更具体的问题。 我的问题是关于 wkhtmltopdf 和 fpdf。我需要其中之一来创建 1 页发票(真正的基本设计)和
为了生成 PDF 发票,我使用 fpdf lib 并将重复文本存储在 mySQL 数据库中。 当我将此文本存储在一个简单文件中时,我需要将其保存为 Latin1 编码,因为 fpdf 使用 Latin
好吧,我正在开发漫画(日本漫画)下载器。日本漫画可以在线获取,但你只能阅读,如果你想下载它们,你必须通过右键单击blah blah blah开始保存图像文件... 所以,我正在开发一个替代漫画下载器,
我有一个 PDF 文件,我想用 FDI/FPDF 添加一个新页面 Fatal error: Uncaught Exception: FPDF error: Incorrect output desti
我们如何以相同的高度显示具有不同内容量的 fpdf 多单元格 最佳答案 很好的问题。 我通过遍历行中的每个数据单元格来解决它,这些数据单元格将是多单元格并确定 最大高度所有这些细胞。这发生在您创建行中
我已经四处搜寻,发现这个问题非常普遍,但似乎找不到正确和直接的答案。我正在使用FPDF,并且我想使用MultiCell()生成表,因为我需要它的换行属性。尝试使用Cell(),但无法读取换行符。 $c
我一直在尝试让 php 发送一封附有 PDF 的电子邮件,我到处寻找并发现了这篇文章 Email PDF Attachment with PHP Using FPDF . 我尝试了解决方案,但仍然没有
谁能向我解释一下 FPDF 中的这个函数是如何工作的?使用以下代码,我似乎无法从中获得任何颜色: function Header() { // Logo $th
我正在从 html 表单创建 PDF 页面,所以我的 php 看起来像这样(例如): $pdf->Cell(0,0,$_POST['teacher_name'],0,2,'C'); 我可以定义该变量
我写了下面的代码来创建一个多单元格的表 $this->Cell(25, 25, "SR.No.", 'LTRB', 0, 'L', true); $this->Cell(60, 25, "CH
下面代码中的变量“输出”是几段文本,我正在尝试使用 FPDF 将其全部写入 pdf。但是,它只写入一行。我如何让它包含换行符。例如,文本的多个位置都有“\n”,但它被忽略了。谢谢。 dummytext
我需要创建具有背景颜色的单元格,但我使用的是示例: $pdf->SetFillColor(135,206,235); $pdf->Rect(9, 52, 190, 7, 'F'); 这个例子的问题是,
我正在使用 FPDI 和 FPDF 在现有 PDF 之上叠加新文本。它使用 useTemplate() 方法来实现这一点。 我遇到的问题 - 它只将模板应用于第一页。如果文本很长,它将换行到第二页,使
通过使用 FPDF (multiCell),我无法为一个简单的单词应用不同的标签。 举个例子: Sample 最后,它仅以下划线样式(最新的)以 PDF 形式显示。有没有可能将它们结合起来? 最佳答
我是一名优秀的程序员,十分优秀!