how to generate pdf using dompdf php

Share:

 how to generate pdf using dompdf php?




step one: open you vs code and create a folder and then create a file index.php 

step  2: if you have already installed composer the open terminal and write this command  (composer require dompdf/dompdf )


step 3: copy the full code and paste it into your index.php page .

if you have any problems to understand please comment in the comment box.
thank you 


<?php
$html='<!DOCTYPE html>
<html>
<head>
<style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: center;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;

}
center{
    background-color: #819ff3;
    color: white;
    padding: 10px;
}
</style>
</head>
<body>
<center>
    <h1><img src="mobile.jpg" width="50px"></h1>
    <h2>Dhaka, Bangladesh </h2>
</center>

<table>
  <tr style="background-color: #819ff3;">

    <th>Product Name</th>
    <th>Date</th>
    <th>Iteam</th>
    <th>Price</th>
    <th>Vat</th>
    <th>Total</th>
  </tr>
  <tr>
 
    <td>I Phone 13 Max Pro</td>
    <td>12-06-22</td>
    <td>1</td>
    <td>100000 tk</td>
    <td>20000 tk</td>
    <td>120000 tk</td>

  </tr>

  <tr>
 
    <td>I Phone 12 Max Pro</td>
    <td>12-06-22</td>
    <td>1</td>
    <td>90000 tk</td>
    <td>15000 tk</td>
    <td>105000 tk</td>

  </tr>

  <tr>
 
    <td>Samsung Glaxy Note 10</td>
    <td>12-06-22</td>
    <td>1</td>
    <td>100000 tk</td>
    <td>15000 tk</td>
    <td>1015000 tk</td>

  </tr>

  <tr>
 
    <td>I Phone 12 Max Pro</td>
    <td>12-06-22</td>
    <td>1</td>
    <td>90000 tk</td>
    <td>15000 tk</td>
    <td>105000 tk</td>

  </tr>

  <tr>
 
    <td>I Phone 12 Max Pro</td>
    <td>12-06-22</td>
    <td>1</td>
    <td>90000 tk</td>
    <td>15000 tk</td>
    <td>105000 tk</td>

  </tr>
 
</table>

<div style="margin: 0px 20px;">
<h3 style="    float: right;
background-color: #ff0000;
color: white;
padding: 10px;">SubTotal : 5050000 tk</h3>

</div>


</body>
</html>

';

include_once("vendor/autoload.php");
use Dompdf\Dompdf;

$dompdf = new Dompdf([
  "chroot"=>__DIR__
]);

$dompdf->loadHtml($html);
$dompdf->setPaper('A4','landscape');
$dompdf->render();
$dompdf->stream("invoice",array("Attachment"=>0));

?>

Post a Comment

No comments