Dear All I'm facing a problem with this code which is basically my page tables from Database and I want to download this page as a PDF format but I can not I don't know what the issue I spent days solving this and nothing changed, I try the DOMPDF but its output ??? my code pretty long but most of it table display from the database, I will appreciate you help.
<?php
require('db2.php');
// require_once 'dompdf/autoload.inc.php';
// use Dompdf\Dompdf;
?>
<!DOCTYPE html>
<html lang="ar">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<!-- <script src="scriptPDF.js"></script> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<title> Invoice Details </title>
<link rel="stylesheet" href="style.css">
<style>
body{
background-color: white;
}
.header-company{
text-align: right ;
height: 20px;
color: black;
text-align: justify;
text-justify: inter-word;
}
header img{
position: relative;
align-items : center;
top: 1%;
left: 9%;
right: 20%;
}
.billTo-css{
display: inline;
}
.billTo-css #billE{
float:left;
bottom: 30px;
}
.billTo-css #billAR{
float:right;
}
</style>
</head>
<body>
<!-- // $dompdf = new Dompdf();
// $html = file_get_contents('InvoiceDetails.php');
// $dompdf->loadHtml($html);
// $dompdf->setPaper('A4', 'landscape');
// $dompdf->render();
// //output the generated PDF
// ob_end_clean();
// $dompdf->stream("",array("Attachment" => false));
// exit(0); -->
<?php
if(isset($_GET ['SearchByInvoiceID']))
{
$id= $_GET ['SearchByInvoiceID'];
$stmt= "Select top 1* from [Portal].[fn_GetInvoicesBySerial]($id)";
$query_run = sqlsrv_query($conn,$stmt);
while( $row = sqlsrv_fetch_array( $query_run ))
{
?>
<form method="get" action="InvoiceDetails.php" accept-charset="UTF-8">
<header>
<center>
<!-- <div class="header-QR"> -->
<h2> TAX Invoice </h2> </center>
<center> <img src=<?php echo $row ['QRLink']; ?> </center>
<div class="header-company">
<h3 align="right"> <?php echo $row ['CompanyNameA'];?> </h3>
<h3 align="right"> <?php echo $row ['CompanyNameE']; ?> </h3>
<p align="right"> CR No: <?php echo $row ['CRNo']; ?> </p>
<p align="right"> VAT ID:<?php echo $row ['VATID']; ?> </p>
<p align="right"> Group VAT ID <?php echo $row ['GroupVATID']; ?> </p>
<p align="right"> Tel: <?php echo $row ['Tel']; ?> </p>
<p align="right"> Email: <?php echo $row ['email']; ?> </p>
</form>
<br>
<br>
</div>
</header>
<br>
<?php
if( $query_run === false ) {
print( print_r( sqlsrv_errors() ) );
}
?>
<?php
}
}
?>
<!-- <div class="table-css"> -->
<!-- <tr>
<th> Department </th>
<th>Type </th>
<th>Branch </th>
<th> Branch CR No</th>
<th>Salesman </th>
<th> Account# </th>
<th> Application ID </th>
<th>Invoicen Timestamp </th>
<th>Issued By </th>
<th>Print By </th>
</tr> -->
<?php
if(isset($_GET ['SearchByInvoiceID']))
{
$id= $_GET ['SearchByInvoiceID'];
$stmt= "Select top 1* from [Portal].[fn_GetInvoicesBySerial]($id)";
$query_run = sqlsrv_query($conn,$stmt);
while( $row = sqlsrv_fetch_array( $query_run )) {
?>
<br>
<br>
<div class="row">
<div class="column">
<table>
<tr>
<tr>
<th> Department </th>
<td> <?php echo $row ['DepartmentCode']; ?> <th> القسم </th> </td> </tr>
<tr>
<th>Type </th>
<td> <?php echo $row ['InvoiceType']; ?> </td> <th> النوع </th> </tr>
<tr>
<th>Branch </th>
<td> <?php echo $row ['Branch']; ?> </td> <th> الفرع </th> </tr>
<tr>
<th> Branch CR No</th>
<td> <?php echo $row ['BranchCRNo']; ?> </td> <th> س ت للفرع </th> </tr>
<tr>
<th>Salesman </th>
<td> <?php echo $row ['Salesman']; ?> </td> <th> أسم البائع </th> </tr>
</tr>
</table>
</div>
<div class="column">
<table>
<tr>
<tr>
<th> Account # </th>
<td> <?php echo $row ['AccountNo']; ?> </td> <th> #فاتورة </th> </tr>
<tr>
<th> Application ID </th>
<td> <?php echo $row ['ApplicationID']; ?> </td> <th> # مرجع </th> </tr>
<tr>
<th>Invoicen Timestamp </th>
<td> <?php echo $row ['InvoiceTimeStamp']->format('Y-m-d H:i:s'); ?> </td> <th> طلب الشراء </th></tr>
<tr>
<th>Issued By </th>
<td> <?php echo $row ['Issuedby']; ?> </td><th> تاريخ الأستحقاق </th> </tr>
<tr>
<th>Print By </th>
<td> <?php echo $row ['Printedby']; ?> </td> <th> رقم سند القبض </th></tr>
</tr>
</table>
</div>
</div>
<?php
if( $query_run === false ) {
print( print_r( sqlsrv_errors() ) );
}
?>
<?php
}
}
?>
<br>
<!-- <div class="table-css">
<h3> Bill To </h3>
<hr>
<table>
<tr>
<th>Customer ID </th>
<th> Customer Name:</th>
<th>Address: </th>
<th>Email </th>
<th>VAT ID: </th>
<th>VAT Group ID </th>
<th>Contact </th>
</tr>
</div> -->
<?php
if(isset($_GET ['SearchByInvoiceID']))
{
$id= $_GET ['SearchByInvoiceID'];
$stmt= "Select top 1* from [Portal].[fn_GetInvoicesBySerial]($id)";
$query_run = sqlsrv_query($conn,$stmt);
while( $row = sqlsrv_fetch_array( $query_run )) {
?>
<!-- <div class="billTo-css">
<div id="billE">
<h3> Bill To </h3> </div> <br>
<div id="billAR">
<h3> صادرة الى </h3> </div>
<br>
</div> -->
<br>
<div class="row">
<div class="column">
<table>
<h3> Bill to </h3>
<tr>
<tr>
<th>Customer ID </th>
<td> <?php echo $row ['CustomerID']; ?> </td> <th> رقم العميل </th> </tr>
<tr>
<th> Customer Name:</th>
<td> <?php echo $row ['CustomerName']; ?> </td> <th> اسم العميل </th> </tr>
<tr>
<th>Address: </th>
<td> <?php echo $row ['CustomerAddress']; ?> </td> <th> العنوان </th></tr>
<tr>
<th>Email </th>
<td> <?php echo $row ['CustomerEmail']; ?> </td><th> بريد الكتروني </th> </tr>
</table>
</div>
<div class="column">
<table>
<h3> صادرة الى </h3>
<tr>
<tr>
<th>VAT ID: </th>
<td> <?php echo $row ['CustomerVATID']; ?> </td> <th> رقم الضريبي </th> </tr>
<tr>
<th>VAT Group ID </th>
<td> <?php echo $row ['CustomerVATGroupID']; ?> </td> <th> رقم ضريبي عام </th> </tr>
<tr>
<th>ID/CR No</th>
<td> <?php echo $row ['CRNo']; ?> </td> <th> هوية/سجل تجاري </th> </tr>
<tr>
<th>Contact </th>
<td> <?php echo $row ['CustomerTel']; ?> </td> <th> هاتف تواصل </th> </tr>
</tr>
</table>
</div>
</div>
<hr size ="1">
<?php
if( $query_run === false ) {
print( print_r( sqlsrv_errors() ) );
}
?>
<?php
}
}
?>
<hr size ="1">
<div class="table-css">
<hr>
<table border="1">
<tr>
<th>Line Description <br>
وصف الصنف </th>
<th>Qunatity <br>
عدد </th>
<th> Unit Price <br>
سعر الوحدة </th>
<th>SubTotal <br>
الإجمالي </th>
<th>Discount <br>
خصم </th>
<th>Net <br>
بعد الخصم </th>
<th>VAT Rate <br>
ضريبة </th>
<th>VAT Amount <br>
ضريبة </th>
<th>Total Plus VAT <br>
الضريبة+الصافي </th>
</tr>
</div>
<br>
<?php
if(isset($_GET ['SearchByInvoiceID']))
{
$id= $_GET ['SearchByInvoiceID'];
$stmt= " select top 1 * from [Portal].[fn_GetInvoicesDetails] ($id)";
$query_run = sqlsrv_query($conn,$stmt);
while( $row = sqlsrv_fetch_array( $query_run)) {
?>
<tr>
<td> <?php echo $row ['LineDescription']; ?> </td>
<td> <?php echo $row ['Qunatity']; ?> </td>
<td> <?php echo $row ['UnitPrice']; ?> </td>
<td> <?php echo $row ['SubTotal']; ?> </td>
<td> <?php echo $row ['Discount']; ?> </td>
<td> <?php echo $row ['Net']; ?> </td>
<td> <?php echo $row ['VATRate']; ?> </td>
<td> <?php echo $row ['VATAmount']; ?> </td>
<td> <?php echo $row ['TotalPlusVAT']; ?> </td>
</tr>
<?php
if( $query_run === false ) {
print( print_r( sqlsrv_errors() ) );
}
?>
<?php
}
}
?>
</table>
<br>
<!-- <div class="table-css">
<table>
<tr>
<th> VAT Summary</th>
<th>SR </th>
<th>Totals </th>
<th>SR</th>
</tr>
</div> -->
<?php
if(isset($_GET ['SearchByInvoiceID']))
{
$id= $_GET ['SearchByInvoiceID'];
$stmt= "Select top 1* from [Portal].[fn_GetInvoicesBySerial]($id)";
$query_run = sqlsrv_query($conn,$stmt);
while( $row = sqlsrv_fetch_array( $query_run )) {
?>
<div class="row">
<div class="column">
<table>
<tr>
<tr>
<h3> VAT Summary </h3>
<h3> ملخص ضريبي </h3>
<th> Taxable Amount BeforeVAT</th>
<td> <?php echo $row ['TaxableAmountBeforeVAT']; ?> </td> <th> القيمة الخاضعة للضريبة </th> </tr>
<tr>
<th>VAT </th>
<td> <?php echo $row ['TotalVAT']; ?> </td> <th> ضريبة </th> </tr>
<tr>
<th>Taxable Amount Plus VAT </th>
<td> <?php echo $row ['TaxableAmountPlusVAT']; ?> </td> <th> القيمة الخاضعة+الضريبة </th> </tr>
<tr>
<th>Non Taxable Amount </th>
<td> <?php echo $row ['NonTaxableAmount']; ?> </td> <th> قيمة غير خاضعة للضريبة </th> </tr>
<tr>
<th>
<br> <br> </th>
<td> </td> </tr>
</tr>
</table>
</div>
<div class="column">
<table>
<tr>
<tr>
<h3> Totals </h3>
<h3> الأجماليات </h3>
<th>Sub Total Before Discount </th>
<td> <?php echo $row ['SubTotalBeforeDiscount']; ?> </td> <th> الأجمالي </th> </tr>
<tr>
<th> Total Discount</th>
<td> <?php echo $row ['TotalDiscount']; ?> </td> <th> الخصم </th> </tr>
<tr>
<th>Total After Discount </th>
<td> <?php echo $row ['SubTotalAfterDiscount']; ?> </td> <th> بعد الخصم </th> </tr>
<tr>
<th>VAT </th>
<td> <?php echo $row ['TotalVAT']; ?> </td> <th> ضريبة </th> </tr>
<tr>
<th>Total Plus VAT </th>
<td> <?php echo $row ['TotalPlusVAT']; ?> </td> <th> الصافي+الضريبة </th> </tr>
</tr>
</table>
</div>
</div>
<?php
if( $query_run === false ) {
print( print_r( sqlsrv_errors() ) );
}
?>
<?php
}
}
?>
</table>
<!-- Additional Notes part-->
<?php
if(isset($_GET ['SearchByInvoiceID']))
{
$id= $_GET ['SearchByInvoiceID'];
$stmt= "Select top 1* from [Portal].[fn_GetInvoicesBySerial]($id)";
$query_run = sqlsrv_query($conn,$stmt);
while( $row = sqlsrv_fetch_array( $query_run )) {
?>
<h2> ملاحظات اضافية</h2>
<h2> Additional Notes </h2>
<?php echo $row ['AdditionalNotes']; ?>
<?php
if( $query_run === false ) {
print( print_r( sqlsrv_errors() ) );
}
?>
<?php
}
}
?>
<div id="InvoiceDetails-PDF">
<td align="center">
<a href="javascript:generatePDF()">Dowload PDF</a>
</td>
</div>
<script>
function generatePDF() {
var doc = new jsPDF(); //create jsPDF object
doc.fromHTML(document.getElementById("InvoiceDetails-PDF"), // page element which you want to print as PDF
15,
15,
{
'width': 170 //set width
},
function(a)
{
doc.save("HTML2PDF.pdf"); // save file name as HTML2PDF.pdf
});
}
</script>
</body>
</html>