在FPDF中生成换行符 [英] Generating line break in FPDF

查看:375
本文介绍了在FPDF中生成换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本表单,其数据以PDF显示.

I have a text form, whose data is displayed in a PDF.

我的问题是,当PDF变量中接收的值超过65个字符时,而不是换行,请在同一行上继续覆盖另一个元素.

My problem is that when the value received by the PDF in variable exceeds 65 characters, instead of a line break, continue in the same line overlaying another element.

我曾尝试使用内爆,自动换行的方法,但没有一个方法帮助我将字符串切成65个字符.

I have tried to apply the methods implode, wordwrap, but none has helped me to cut the string to reach 65 characters.

我试图生成任何条件来检查字符串的长度是否超过65个字符,使之换行(>).但这都没有为我服务.

I tried to generate any condition to check if the length of the string exceeds 65 characters make a line break (<br>). But neither it has served me.

$pdf_observations = $_GET['pdf_observations'];

$pdf->SetXY(29.6, 85.6);
$pdf->Write(0, "{$pdf_observations}");

谢谢!

推荐答案

您可以使用文档中解密的MultiCell方法为

You can use a MultiCell method descrypted in documentation as

此方法允许打印带有换行符的文本.他们可以 自动(文本到达单元格的右边界后) 或显式(通过\ n字符).尽可能多的单元格 输出,一个低于另一个.文本可以对齐,居中或 有道理.单元框可以装裱,背景可以绘制.

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 上找到更多信息.

More information you can find on the http://www.fpdf.org in manual section.

在您的情况下,您可以将其与线路一起使用

In your case you can use it with line

//example parameters - use anything that suit your things
$width = 100;
$lineHeight = 4;

$pdf->MultiCell($width, $lineHeight, "{$pdf_observations}");

在此示例中,如果您的字符串无法适应所提供的宽度,则当每一行都提供高度时,其余字符串将被制动到新行中.

In this example if your string can't fit to provided width then the rest of the string will be brake into new line when every line have provided height.

这篇关于在FPDF中生成换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆