我有一個表格,我想轉換爲pdf。我想用FPDF做 我的HTML代碼如下:運行php腳本將html轉換爲pdf
page.html中
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<header>
<h1 align='center'>Welcome </h1>
</header>
<section align = 'center'>
<h2> Register </h2>
<form action = "form.php" method = "post"
<p>
<label>First Name :</label>
<input type="text" name = "first_name" />
</p>
<p>
<label>Last Name :</label>
<input type="text" name="last_name" />
</p>
<p>
<label>Gender :</label>
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</p>
<p>
<label>Date of Birth :</label>
<input type="date" name="dob" />
</p>
<label>Mobile :</label>
<input type="text" name="mobile" />
</p>
<p>
<label>Email :</label>
<input type="text" name="email" />
</p>
<input type="submit" value="Register" name="submit" />
</form>
</section>
</body>
</html>
我創建了一個PHP腳本的形式轉換爲PDF一旦註冊按鈕被點擊PHP的是:
form.php的:
<?php
if(!empty($_POST['submit']))
{
$f_name=$_POST['first_name'];
$l_name=$_POST['last_name'];
$gender=$_POST['gender'];
$dob=$_POST['dob'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
require("fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B",16);
$pdf->Cell(10,10,"welcome {$f_name}",1,0,C);
$pdf->Cell(50,10,"Name :",1,0);
$pdf->Cell(50,10,"$l_name",1,0);
$pdf->Cell(50,10,"gender :",1,0);
$pdf->Cell(50,10,"$gender",1,1);
$pdf->Cell(50,10,"Mobile :",1,0);
$pdf->Cell(50,10,"$mobile",1,1);
$pdf->Cell(50,10,"Email :",1,0);
$pdf->Cell(50,10,"$email",1,1);
$pdf->output();
}
?>
我在XAMPP上運行它,並在htdocs中創建了一個名爲demo的文件夾(html文件,php文件和fpdf文件夾在那裏),但是當我在瀏覽器上運行html文件並單擊註冊時,它僅顯示php代碼php的文件,而不是生成PDF
的文件是在XAMPP文件htdoc文件夾演示這樣的:
當我運行page.html即可(請點擊註冊):
這表明我:
爲什麼不產生一個PDF?
是您的註冊文件'.php'擴展名或'.html'? – andre3wap
什麼是註冊文件?下面的代碼是我所編碼的 – compcrk
好的。我看到了編輯。 – andre3wap