Generating line break in FPDF

荒凉一梦 提交于 2019-11-28 09:51:16

问题


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

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.

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

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}");

Thanks!!


回答1:


You can use a MultiCell method descrypted in documentation as

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.

This method can take some argument

MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])

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.



来源:https://stackoverflow.com/questions/38490454/generating-line-break-in-fpdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!