在 FPDF 中生成换行符
Generating line break in FPDF
我有一个文本表单,其数据以 PDF 格式显示。
我的问题是,当变量中的 PDF 接收到的值超过 65 个字符时,不是换行,而是在同一行中继续覆盖另一个元素。
我曾尝试应用 implode、wordwrap 方法,但 none 帮助我将字符串剪切为 65 个字符。
我尝试生成任何条件来检查字符串的长度是否超过 65 个字符以换行 (<br
>)。但它对我没有用。
$pdf_observations = $_GET['pdf_observations'];
$pdf->SetXY(29.6, 85.6);
$pdf->Write(0, "{$pdf_observations}");
谢谢!!
您可以使用文档中解密的 MultiCell
方法
This method allows printing text with line breaks. They can be
automatic (as soon as the text reaches the right border of the cell)
or explicit (via the \n character). As many cells as necessary are
output, one below the other. Text can be aligned, centered or
justified. The cell block can be framed and the background painted.
这个方法可以接受一些参数
MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])
您可以在手册部分的 http://www.fpdf.org 中找到更多信息。
在你的情况下,你可以将它与行
一起使用
//example parameters - use anything that suit your things
$width = 100;
$lineHeight = 4;
$pdf->MultiCell($width, $lineHeight, "{$pdf_observations}");
在此示例中,如果您的字符串不适合提供的宽度,则当每行都提供了高度时,字符串的其余部分将换行。
我有一个文本表单,其数据以 PDF 格式显示。
我的问题是,当变量中的 PDF 接收到的值超过 65 个字符时,不是换行,而是在同一行中继续覆盖另一个元素。
我曾尝试应用 implode、wordwrap 方法,但 none 帮助我将字符串剪切为 65 个字符。
我尝试生成任何条件来检查字符串的长度是否超过 65 个字符以换行 (<br
>)。但它对我没有用。
$pdf_observations = $_GET['pdf_observations'];
$pdf->SetXY(29.6, 85.6);
$pdf->Write(0, "{$pdf_observations}");
谢谢!!
您可以使用文档中解密的 MultiCell
方法
This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other. Text can be aligned, centered or justified. The cell block can be framed and the background painted.
这个方法可以接受一些参数
MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])
您可以在手册部分的 http://www.fpdf.org 中找到更多信息。
在你的情况下,你可以将它与行
一起使用//example parameters - use anything that suit your things
$width = 100;
$lineHeight = 4;
$pdf->MultiCell($width, $lineHeight, "{$pdf_observations}");
在此示例中,如果您的字符串不适合提供的宽度,则当每行都提供了高度时,字符串的其余部分将换行。