Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - Generating line break in FPDF

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

Problem newLine

Thanks!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...