在PDF上打印Textarea元素而不会溢出

时间:2015-07-09 10:07:11

标签: php html pdf fpdf

我正在使用HTML和PHP帮助生成PDF。但是textarea中的文字越来越多了。仅在一行中打印的文本。 我的HTML代码是

  
<html>
<head>
<title>registration form</title>
</head>

<h2 ALIGN="CENTER">Registration form</h2>

<form action="pro1.php" method="post">
<table border="0" align="center">
	<tbody>

		<tr>
			<td><label for="id">Id: </label></td>
			<td><input id="id" maxlength="50" name="name" type="text" /></td>
		</tr>

		<tr>
			<td><label for="name">Name: </label></td>
			<td><input id="name" maxlength="50" name="name" type="text" /></td>
		</tr>

		<tr>
			<td><label for="course">Course: </label></td>
			<td><input id="course" maxlength="50" name="course" type="text" /></td>
		</tr>

		<tr>
			<td><label for="branch">Branch: </label></td>
			<td><input id="branch" maxlength="50" name="branch" type="text" /></td>
		</tr>

		<tr>
			<td><label for="rolln0">Rollno: </label></td>
			<td><input id="rollno" maxlength="50" name="rollno" type="text" /></td>
		</tr>

		<tr>
			<td><label for="email">Email_Address:</label></td>
			<td><input id="email" maxlength="50" name="email" type="text" /></td>
		</tr>

		<tr>
			<td><label for="username">User_Name:</label></td>
			<td><input id="username" maxlength="50" name="username" type="text" /></td>
		</tr>

		<tr>
			<td><label for="aboutus">About Us:</label></td>
			<td valign="middle" align="center"><textarea  wrap="wrap" rows ="1" cols ="1" name = "aboutus"></textarea></td>
		</tr>

		<tr>
			<td><label for="password">Password:</label></td>
			<td><input id="password" maxlength="50" name="password"
				type="password" /></td>
		</tr>

		<tr>
			<td align="right"><input name="Submit" type="Submit" value="Add" /></td>
		</tr>

	</tbody>
</table>
</form>
</html>

我的PHP代码是     

        require('fpdf/fpdf.php');
        $pdf = new FPDF();
        //var_dump(get_class_methods($pdf));
        $pdf -> AddPage();

        $pdf->SetFont("Arial","B",16);
        $pdf->Cell(0,10,"Welcome {$pro_name}",1,1);
        $pdf->Cell(50,10,"Name: ",1,0);
        $pdf->Cell(50,10,$pro_name,1,1);
        $pdf->Cell(50,10,"Branch: ",1,0);
        $pdf->Cell(50,10,$pro_branch,1,1);
        $pdf->Cell(50,10,"Roll No: ",1,0);
        $pdf->Cell(50,10,$pro_rollno,1,1);
        $pdf->Cell(50,10,"Email: ",1,0);
        $pdf->Cell(50,10,$pro_email,1,1);
        $pdf->Cell(50,10,"About Us: ",1,0);
        $pdf->Cell(50,10,$pro_aboutus,1,1);

        $pdf->output();
    }
?>

请帮帮我,告诉我该怎么做才能让我的文字区域打印在a4内。谢谢你提前

1 个答案:

答案 0 :(得分:0)

使用 MultiCell 而不是 Cell 。 正如它所说,&#34; 此方法允许使用换行符打印文本。&#34;

示例:

$this->MultiCell(60,5,$txt);

Full example here

<强> MultiCell documentation here