JezK
Edit File: pdf2.php
<?php // Include autoloader require_once '../../dompdf/autoload.inc.php'; include('adminObject.php'); use Dompdf\Dompdf; use Dompdf\Options; use Dompdf\FontMetrics; //Getting image $path=file_get_contents("https://detailingedition.com/admin/images/logo.png"); $type=pathinfo($path, PATHINFO_EXTENSION); $imagedata=base64_encode($path); $base64Data = 'data:image/' . $type . ';base64,' . base64_encode($imagedata); // Set options to enable embedded PHP $options = new Options(); $options->set('isPhpEnabled', 'true'); // Instantiate dompdf class $dompdf = new Dompdf($options); $allotmentId = $_GET['allotmentId']; $data = $admin->getAllotmentDetails($allotmentId); $grandTotal = $data['amount']; $details = unserialize($data['details']); $invoiceId = $data['id']; $userId = $data['user_id']; $userDetails = $admin->userDeatils($userId); $userName = $userDetails['user_name']; $userEmail = $userDetails['email']; $userAddress = $userDetails['address']; $userMobile = $userDetails['phone']; $names = array(); $costs = array(); $quantities = array(); $createdDate = $data['created_date']; $dateTime = new DateTime($createdDate); $date = $dateTime->format('d F Y'); $type = $data['type']; $typeOfService = ''; $total = ''; if ($type == 1) { $name = $details['packageName']; $typeOfService = 'Package Name:' . $name; $names = json_decode($details['serviceNames']); $total = $grandTotal; } else if ($type == 2) { $typeOfService = 'Service :'; $names = json_decode($details['servicesNames']); $costs = json_decode($details['servicesCosts']); $total = array_sum($costs); $coupon = $details['couponId']; $couponAmount = $details['couponAmount']; } else { $typeOfService = 'Product :'; $names = $details['productNames']; $costs = $details['productCosts']; $total = array_sum($costs); $quantities = $details['productQuantity']; $coupon = $details['couponId']; $couponAmount = $details['couponAmount']; } $html = '<body style="font-family:Montserrat; margin: 0; padding: 20px;"> <h1 style="text-align: center;">Invoice</h1> <table style="width:100%; padding:1rem"> <tr> <td> <h2>Invoice to:</h2> </td> <td></td> </tr> <tr> <td style="color: #24394D;"> <p><span style=" color: #24394d85">Name: </span>' . $userName . '</p> <p><span style=" color: #24394d85">Email: </span>' . $userEmail . '</p> <p><span style=" color: #24394d85">Phone Number: </span>' . $userMobile . '</p> <p><span style=" color: #24394d85">Address: </span>' . $userAddress . '</p> </td> <td style="text-align:right;color: #24394D;"> <p><label style=" color: #24394d85">Invoice: </label>#' . $invoiceId . '</p> <p><label style=" color: #24394d85">Date:</label> ' . $date . '</p> </td> </tr> </table> <div style="border-top:1px dashed"> <table style="width: 100%; padding:1rem"> <tr> <td> <h2>' . $typeOfService . '</h2> </td> <td></td> </tr>'; if ($type == 3) { for ($i = 0; $i < count($names); $i++) { $html .= '<tr> <td style="line-height:2"> ' . $names[$i] . ' (' . $quantities[$i] . ') </td> <td style="line-height:2;text-align:right">Rs. ' . $costs[$i] . '</td> </tr>'; } } else if ($type == 2) { for ($i = 0; $i < count($names); $i++) { $html .= '<tr> <td style="line-height:2"> ' . $names[$i] . '</td> <td style="line-height:2;text-align:right">Rs. ' . $costs[$i] . '</td> </tr>'; } } else { for ($i = 0; $i < count($names); $i++) { $html .= '<tr> <td style="line-height:2"> ' . $names[$i] . '</td> </tr>'; } } $html .= '</table> </div> <div style="border-top:1px dashed"> <p style="text-align:right">Sub Total Amount : Rs ' . $total . '</p> <p style="text-align:right">Total tax: Rs ' . $total . '</p>'; if ($type != 1) { $html .= '<p style="text-align:right">Coupon: Rs ' . $couponAmount . '</p>'; } $html .= '<p style="text-align:right"><b>Grand total: Rs ' . $grandTotal . '</b></p> </div> </body>'; $dompdf->loadHtml($html); // (Optional) Setup the paper size and orientation $dompdf->setPaper('A4', 'portrait'); // Render the HTML as PDF $dompdf->render(); // Instantiate canvas instance $canvas = $dompdf->getCanvas(); // Instantiate font metrics class $fontMetrics = new FontMetrics($canvas, $options); // Get height and width of page $w = $canvas->get_width(); $h = $canvas->get_height(); // Get font family file $font = $fontMetrics->getFont('times'); // Specify watermark text $text = ""; // Get height and width of text $txtHeight = $fontMetrics->getFontHeight($font, 75); $textWidth = $fontMetrics->getTextWidth($text, $font, 75); // Set text opacity $canvas->set_opacity(.2); // Specify horizontal and vertical position $x = (($w - $textWidth) / 2); $y = (($h - $txtHeight) / 3); // Writes text at the specified x and y coordinates //$canvas->text($x, $y, $text, $font, 75); //$canvas->text($x, $y, $text, $font, 75, array(255, 0, 0)); $canvas->text($x, $y, $text, $font, 75, array(255, 0, 0), '', '', 20); // Specify watermark image $imageURL = 'https://bu1is.krify.com/detailing_edition_web/admin/images/logo.png'; $imgWidth = 156; $imgHeight = 156; // Specify horizontal and vertical position $x = (($w-$imgWidth)-10); $y = (($h-$imgHeight)-20); // Add an image to the pdf $canvas->image($imageURL, $x, $y, $imgWidth, $imgHeight); // Output the generated PDF (1 = download and 0 = preview) $dompdf->stream('Invoice.pdf', array("Attachment" => 1));