【问题标题】:Printing Textarea element on PDF without being overflow在 PDF 上打印 Textarea 元素而不会溢出
【发布时间】:2015-07-09 10:07:11
【问题描述】:

我在 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 中。提前谢谢你

【问题讨论】:

    标签: php html pdf fpdf


    【解决方案1】:

    使用 MultiCell 而不是 Cell。 正如它所说,“此方法允许打印带有换行符的文本。

    例子:

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

    Full example here

    MultiCell documentation here

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 2012-09-14
      相关资源
      最近更新 更多