Answers for "php display to pdf using mpdf"

PHP
0

php display to pdf using mpdf

<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<?php
if(isset($_POST['submit'])){
    //collect form data
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];

    //check for a valid email address
    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        $error = 'Please enter a valid email address';
	echo $error;
    }
    //if no errors carry on
    if(!isset($error)){
        //create HTML of the post data
        $body = '<h1>Data from form</h1>'
		.'<p>Name: '.$name.'</p>'
		.'<p>Email: '.$email.'</p>'
		.'<p>Phone: '.$phone.'</p>';

        require_once __DIR__ . '/vendor/autoload.php';
	$mpdf = new \Mpdf\Mpdf();

        $mpdf->WriteHTML($body);

	$mpdf->SetDisplayMode('fullpage');
	$mpdf->list_indent_first_level = 0; 

	//call watermark content and image
	$mpdf->SetWatermarkText('etutorialspoint');
	$mpdf->showWatermarkText = true;
	$mpdf->watermarkTextAlpha = 0.1;

	//output in browser
	$mpdf->Output();	
    }
}
?> 
</head>
<body>
<form action="" method="post">
  <div class="form-group">
    <label for="name">Name:
    <input type="text" class="form-control" id="name" placeholder="Enter name" name="name" required>
  </div>
  <div class="form-group">
    <label for="email">Email:
    <input type="text" class="form-control" id="email" placeholder="Enter email" name="email" required>
  </div>
  <div class="form-group">
    <label for="phone">Phone:
    <input type="text" class="form-control" id="phone" placeholder="Enter phone" name="phone" required>	
  </div>
  <button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
</body>
</html>
Posted by: Guest on October-07-2021

Browse Popular Code Answers by Language