Laravel PDF bangla font not supported - laravel

In my Laravel 6 web application bangla is working working fine. But when I am printing report bangla font doesn't show. See screenshot.
My Print page code is :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Daily Purchase Reprt pdf</title>
<style>
{
font-family: 'Baloo Da 2', cursive;
}
</style>
</head>
<body>
<table width="100%">
<tbody>
<tr>
<td width="60%" style="text-align: center; font-size: 25px;"> <strong style="text-align: center;">Kopotakkho Enterprise</strong> </td> <br>
</tr>
</tbody>
</table>
<table width="100%">
<tbody>
<tr>
<td width="30%" style="float: left;"> </td>
<td width="40%" style="text-align: justify;"> 123, Kakrail Road , Moubon Super Market(2nd Floor), Shantinagar, Dhaka - 1217</td>
<td width="30%" style="float: right;"></td>
</tr>
</tbody>
</table>
<h3 style="text-align: center; text-decoration: underline;">Daily Purchase Report ({{ date('d-m-Y', strtotime($start_date)) }} - {{ date('d-m-Y', strtotime($end_date)) }})</h3>
<table width="100%">
<tbody>
</tbody>
</table>
<br>
<table width="100%" border="1">
<thead>
<tr>
<th width="5%">S/N</th>
<th width="10%">Prch. No</th>
<th width="10%">Date</th>
<th width="5%">Category</th>
<th width="10%">Product</th>
<th width="10%">Qty</th>
<th width="15%">Unit Price</th>
<th width="15%">Total Price</th>
</tr>
</thead>
<tbody>
#php
$sum_total = '0';
#endphp
#foreach($allData as $key => $purchase)
<tr>
<td style="text-align:center;">{{ $key+1 }}</td>
<td style="text-align:center;">{{ $purchase->purchase_no }}</td>
<td style="text-align:center;">{{ date('d-m-Y', strtotime($purchase->date)) }}</td>
<td style="text-align:center;">{{ $purchase['category']['cat_name'] }}</td>
<td style="text-align:center;">{{ $purchase['product']['product_name'] }}</td>
<td style="text-align:center;">
{{ $purchase->buying_qty }}
{{ $purchase['product']['unit']['unit_name'] }}
</td>
<td style="text-align:center;">{{ $purchase->unit_price }}</td>
<td style="text-align:center;">{{ $purchase->buying_price }}</td>
#php
$sum_total += $purchase->buying_price;
#endphp
</tr>
#endforeach
<tr>
<td colspan="7" style="text-align:right;"> Grand Total  </td>
<td style="text-align:center;">{{$sum_total}}</td>
</tr>
</table>
#php
$date = new DateTime('now', new DateTimezone('Asia/Dhaka'));
#endphp
<i>Printing time : {{ $date->format('F j, Y, g:i a')}}</i>
<hr>
<br><br>
<table>
<tr>
<td width="30%" style="float:left;">Customer Signature</td>
<td width="40%"></td>
<td width="30%" style="float:right; padding-left: 70px;"><span style=" padding-left: 50px; text-align: center;">Author Signature</span></td>
</tr>
</table>
</body>
</html>
I have used "niklasravnsborg/laravel-pdf": "^4.0" package for printing.
In my pdf.php file code is :
<?php
return [
'mode' => 'utf-8',
'format' => 'A4',
'author' => '',
'subject' => '',
'keywords' => '',
'creator' => 'Laravel Pdf',
'display_mode' => 'fullpage',
'tempDir' => base_path('../temp/')
];
return [
// ...
'font_path' => base_path('public/admin/Baloo_Da_2/'),
'font_data' => [
'BalooDa2' => [
'R' => 'BalooDa2-Regular.ttf', // regular font
'B' => 'BalooDa2-Bold.ttf', // optional: bold font
'useOTL' => 0xFF, // required for complicated langs like Persian, Arabic and Chinese
'useKashida' => 75, // required for complicated langs like Persian, Arabic and Chinese
]
// ...add as many as you want.
]
// ...
];
BUT bangla not showing. Please help. thanks

You need to embed bangla font to your project. In config/pdf.php file please add bangla font. Following this procedure.
'font_path' => base_path('resources/fonts/'),
'font_data' => [
'solaimanlipi' => [
'R' => 'SolaimanLipi.ttf', // regular font
'B' => 'SolaimanLipi.ttf', // optional: bold font
'I' => 'SolaimanLipi.ttf', // optional: italic font
'BI' => 'SolaimanLipi.ttf', // optional: bold-italic font
'useOTL' => 0xFF,
'useKashida' => 75,
]
]
And download "SolaimanLipi" font and place it to your resources/fonts folder.

Related

Laravel Blade Shows Special Characters

I am working on a project where I need to create the PDF from the view. but in the blade file the "ß ß ß ß ß ß" characters, as I checked my codes there are no tags which contain these characters. can any one help me to fix this issue? I have added the blade file code. Please have a look.
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
</head>
<body>
#if (count($data['data']) > 0)
<table class="table table-condensed">
<tr>
<td><img src="{{public_path().'/theme/frontend/images/logo.png'}}"alt="kpvlogo"></td>
<td colspan="8" style="text-align: center; font-size:24px; font-weight: bold;">Weekly Ranking</td>
<td colspan="6" >Week Ending {{$data['end']}}</td>
</tr>
<tr>
<thead>
<th style="font-weight: bold;">Store</th>
<th style="font-weight: bold;">Net Sales</th>
<th style="font-weight: bold;">+/- Last Year %</th>
<th style="font-weight: bold;">Cust.Count +/- %</th>
<th style="font-weight: bold;">Labour %</th>
<th style="font-weight: bold;">Food %</th>
<th style="font-weight: bold;">Cash %</th>
<th style="font-weight: bold;">GSS</th>
<th style="font-weight: bold;">Complaints</th>
<th style="font-weight: bold;">Speed of Service</th>
<th style="font-weight: bold;">Training</th>
<th style="font-weight: bold;">Rank</th>
</thead>
</tr>
<tbody>
#foreach ($data['data']['grid'] as $item)
<tr>
<td>{{$item['store']}}</td>
<td class="text-right">{{$item['net_sales']}}</td>
<td class="text-right">{{$item['last_year']}}</td>
<td class="text-right">{{$item['customer_count']}}</td>
<td class="text-right">{{$item['labour']}}</td>ß
<td class="text-right">{{$item['food']}}</td>
<td class="text-right">{{$item['cash']}}</td>
<td class="text-right">{{$item['gss']}}</td>
<td class="text-right">{{$item['complaints']}}</td>
<td class="text-right">{{$item['speed_of_service']}}</td>
<td class="text-right">{{$item['training']}}</td>
<td class="text-right">{{$item['rank']}}</td>
</tr>
#endforeach
<tr>
<td colspan="12" class="text-center">Top Performer of the Week</td>
</tr>
<tr>
<td colspan="12" class="text-center">Congratulations to the team from <b>{{$data['data']['top']['store']}}</b> for achieving the overall best results this week.</td>
</tr>
<tr>
<td colspan="12" class="text-center">Thank You!</td>
</tr>
</tbody>
</table>
#endif
{{-- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script>
var body_text = $('body').text();
var match = body_text.match('ß');
console.log(match);
</script> --}}
</body>
</html>
It would help if you can identify where in the blade file the special characters appear. Seeing that none of the ß ß ß ß ß ß characters can be found in your blade, this suggests that what's causing it is somewhere in your database. I recommend you inspect the data and the database column of the $item where the characters are seen and you may find the cause.

foreach loop inside html table design in laravel

I have an array of data to display using table in html .but the foreach loop which i m using is not giving the desired format .
Below is the array data
$data = Array
(
[0] => Array
(
[id] => 10
[asset_name] => Mini Paver
[qty] => 3
[est_start_date] => 02/05/2017
[days] => 2
[comments] => Comment 2
[bundle_name] => 1XRoller 1XPaver
)
[1] => Array
(
[id] => 11
[asset_name] => Roller
[qty] => 2
[est_start_date] => 03/07/2018
[days] => 4
[comments] => Comment 2
[bundle_name] => 1XRoller 1XPaver
)
)
my view html code :
#foreach($data as $value)
<table class="" style="width: 100%;border:1px solid #ccc">
<thead>
<tr>
<th colspan="4"> <p><?php echo $value['bundle_name'];?> </p></th>
</tr>
<tr>
<th style="text-align: center">id</th>
<th style="width:5%;text-align: center">Asset Category</th>
<th style="width:5%;text-align: center">Days</th>
<th style="width:5%;text-align: center">Qty</th>
</tr>
</thead>
<tbody>
<tr>
<th style="text-align: center"><?php echo $value['id'];?> </th>
<th style="width:5%;text-align: center"><?php echo $value['asset_name'];?></th>
<th style="width:5%;text-align: center"><?php echo $value['days'];?></th>
<th style="width:5%;text-align: center"><?php echo $value['qty'];?></th>
</tr>
</tbody>
</table>
#endforeach
By using above for each loop i m getting the below html format like bundle name is repeating .
But i need the output should be like as below :
that means i want the bundle name shluld come only one time and the rest of details should display as in rows .
How do i do that ? any suggestions please ?
Thank you .
Please try the below code,
I have assumed the below points,
1. Your bundle_name will change(that is you will have various bundle_name). This code will work even if you have single bundle_name.
2. You will sort the result by bundle_name.
3. You need bundle title & table header for each bundle_name(again, this code will work even if you have single bundle_name).
4. bundle_name will never have a value false.
#php ($bundle_name = false)
#foreach($data as $value)
#if($bundle_name != $value['bundle_name'])
#if($bundle_name != false)
</tbody>
</table>
#endif
#php ($bundle_name = $value['bundle_name'])
<table class="" style="width: 100%;border:1px solid #ccc">
<thead>
<tr>
<th colspan="4"> <p> {{ $bundle_name }} </p></th>
</tr>
<tr>
<th style="text-align: center">id</th>
<th style="width:5%;text-align: center">Asset Category</th>
<th style="width:5%;text-align: center">Days</th>
<th style="width:5%;text-align: center">Qty</th>
</tr>
</thead>
<tbody>
#endif
<tr>
<th style="text-align: center">{{ $value['id'] }} </th>
<th style="width:5%;text-align: center">{{ $value['asset_name'] }}</th>
<th style="width:5%;text-align: center">{{ $value['days'] }}</th>
<th style="width:5%;text-align: center">{{ $value['qty'] }}</th>
</tr>
#endforeach
</tbody>
</table>

Kendo Window won't load data from model

#model Example.Model1ViewModel
#if (Model != null && Model.TableSix != null)
{
<table>
<thead>
<tr>
<td style="width:60%"></td>
<td style="width:20%">Outstanding Amount</td>
</tr>
</thead>
<tbody>
<tr>
<td>Total</td>
<td class="Total cursor">#Html.DisplayFor(x => x.TableSix.Total)</td>
</tr>
<tr>
<td>One</td>
<td>#Html.DisplayFor(x => x.TableSix.One)</td>
</tr>
<tr>
<td>Two</td>
<td>#Html.DisplayFor(x => x.TableSix.Two)</td>
</tr>
</tbody>
</table>
}
<div style="display: none">
#(Html.Kendo().Window()
.Name("RemainingAssetsDrillDown")
.Modal(true)
.Title("Item Drill Down")
.Actions(actions => actions.Close())
.Content(#<text>
<div>
<table>
<tbody>
<tr>
<td>One</td>
<td>#Html.DisplayFor(x => x.TableSix.One)</td>
</tr>
</tbody>
</table>
</div>
</text>)
</div>
)
$(".Total").click(function () {
$("#MVC").load('#Url.Action("PartList", "Report")');
var win = $("#DrillDown").data("kendoWindow");
win.center().open();
});
<style type="text/css">
.cursor {
cursor: pointer;
}
</style>
So, the problem is that #Html.DisplayFor(x => x.TableSix.One) fetches the correct value from the view model in the first table, but in the table under kendo window I get the value as 0.
Any idea how I can get #Html.DisplayFor(x => x.TableSix.One) to display the value from the view model into the table that is under kendo window?
Thanks in advance. :)

MVC3 ASP Replace null value with empty space on the view

I have the following view which returns some text if the POnumber is null.
What I think I need to have instead of the if(Model.Invoice.PONumber == null) is a check mechanism ( maybe multiple if statements ) that will check the fields LineNumber, Description, UnitOfMeasure, QtyOrdered and if any of them is null it will replace it with N/A or empty space but it will still allow the user to see the rest of information available.
Do you have any sugestions? I am new to MVC and any help will be apreciated.
Thank you in advance for your time and help,Bobby
<div class="contentWrapper2">
<div class="content2">
<div class="clr lfl w100">
<h1>Invoice Detail</h1>
<div class="return-btn">
<a class="btn btnStyleC btn-back-invoice" href="#Url.Action("InvoiceHistory", "Account")">
Back to Invoice List</a>
</div>
</div>
#if (Model.ErpError.Length > 0)
{
<div class="clr lfl w100 error">
#Html.Raw(Model.ErpError)
</div>
}
else
{
if(Model.Invoice.PONumber == null)
{
<div class="lfl w100 clr messaging">
<p>No information available at the moment for current invoice.
Please call our sales department for further assistance.
</p>
</div>
}
else
{
<div class="clr lfl w100">
<div class="order-number-date">
<table>
<tr>
<th class="col-1">
<h3>Invoice #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.InvoiceNumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>Invoice Date:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.InvoiceDate.ToShortDateString()</h3>
</td>
</tr>
</table>
</div>
<div class="order-number-date">
<table>
<tr>
<th class="col-1">
<h3>Order #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.OrderNumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>PO #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.PONumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>Due Date:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.DueDate.ToShortDateString()</h3>
</td>
</tr>
</table>
</div>
</div>
<div class="clr lfl w100">
<div class="bill-ship">
<table>
<tr>
<th>
<h4>Billing Information</h4>
</th>
</tr>
<tr>
<td>#Model.Invoice.BTDisplayName
</td>
</tr>
<tr>
<td>
<#Html.Raw(Model.Invoice.BTAddress1)
</td>
</tr>
#if (!string.IsNullOrEmpty(Model.Invoice.BTAddress2))
{
<tr>
<td>#Html.Raw(Model.Invoice.BTAddress2)
</td>
</tr>
}
<tr>
<td>#Html.CityCommaStateZip(Model.Invoice.BTCity, Model.Invoice.BTState, Model.Invoice.BTZip)</td>
</tr>
<tr>
<td>#Model.Invoice.BTCountry
</td>
</tr>
<tr>
<td>#Model.Invoice.BTPhone1</td>
</tr>
<tr>
<td>#Model.Invoice.BTEmail
</td>
</tr>
</table>
</div>
</div>
if (Model.Invoice.InvoiceLines.Count > 0)
{
<div class="clr lfl w100 line-item-detail">
<table class="info-tbl">
<tr>
<th class="vid-item">Item #</th>
<th class="vid-desc">Description</th>
<th class="vid-um">
U/M
</th>
<th class="vid-qty">
Qty
</th>
<th class="vid-ship">
Ship Date
</th>
#if (Model.ShowPackslip)
{
<th class="vid-pack">Pack Slip</th>
}
<th class="vid-unit">Unit Price</th>
<th class="vid-ext">Ext Price</th>
</tr>
#foreach (var invoiceLine in Model.Invoice.InvoiceLines)
{
<tr>
<td class="vid-line">#invoiceLine.LineNumber</td>
<td class="vid-desc">#invoiceLine.Description</td>
<td class="vid-um">#invoiceLine.UnitOfMeasure</td>
<td class="vid-qty">#invoiceLine.QtyOrdered</td>
<td class="vid-ship">
#if (invoiceLine.ShipDate.ToShortDateString() == "1/1/0001")
{
}
else
{
#invoiceLine.ShipDate.ToShortDateString()
}
</td>
#if (Model.ShowPackslip)
{
<td class="vid-pack">
#invoiceLine.PackSlip
</td>
}
<td class="vid-unit">#invoiceLine.UnitPrice.ToCurrency()
</td>
<td class="vid-ext">#invoiceLine.ExtendedPrice.ToCurrency()
</td>
</tr>
}
</table>
</div>
}
<div class="clr lfl w100">
<table class="tbl-total">
<tr class="subtotal">
<th class="col-1">Subtotal</th>
<td class="col-2">#Model.Invoice.OrderSubTotal.ToCurrency()
</td>
</tr>
#if (Model.Invoice.DollarOffOrder > 0)
{
<tr>
<th class="col-1">Order Discount</th>
<td class="col-2">#Model.Invoice.DollarOffOrder.ToCurrency()</td>
</tr>
}
#if (Model.Invoice.ShippingAndHandling > 0)
{
<tr>
<th class="col-1">Shipping</th>
<td class="col-2">#Model.Invoice.ShippingAndHandling.ToCurrency()
</td>
</tr>
}
#if (Model.Invoice.MiscCharges > 0)
{
<tr>
<th class="col-1">Misc. Charges</th>
<td class="col-2">#Model.Invoice.MiscCharges.ToCurrency()</td>
</tr>
}
<tr>
<th class="col-1">Sales Tax</th>
<td class="col-2">#Model.Invoice.TotalTax.ToCurrency()</td>
</tr>
<tr>
<th class="col-1">Invoice Total</th>
<td class="col-2">#Model.Invoice.InvoiceTotal.ToCurrency()</td>
</tr>
</table>
</div>
<div class="clr lfl w100">
<a class="btn btnStyleB btn-print" href="javascript:window.print();">Print</a>
</div>
}
}
</div>
</div>
You could create a template called for example "nullcheck.cshtml" like:
#if (ViewBag.ValueToCheck == null) {
<div class="lfl w100 clr messaging">
<p>
No information available at the moment for #(ViewBag.Field).
Please call our sales department for further assistance.
</p>
</div>
}
else {
#Html.Partial(ViewBag.TargetTemplate, Model)
}
Then you call it from your main view:
#{
ViewBag.TargetTemplate = "okModel";
ViewBag.Field = "P.O.Number";
ViewBag.ValueToCheck = Model.Invoice.PONumber;
Html.RenderPartial("nullCheck", Model, ViewBag);
}
okModel.cshtml should be the part of your template you will display when the value is not null...
I haven't tested this myself but it should give you some ideas... contact me if things go wrong XD
Cheers!
This seems like something you should take care of in your controller.
public ActionResult YourControllerAction()
{
var myViewModel = SomeService.GetMyViewModel();
if (myViewModel.Invoice.PONumber == null)
{
myViewModel.Invoice.PONumber = "N/A";
}
//etc
}
This leaves your view clearer (my personal preference)
However in the view you could simply use the null coalescing operator like so:
#Model.Invoice.PONumber ?? "NA"

Parse table in HTML Agility Pack for WP7

I have following HTML:
<table cellspacing="8" cellpadding="6" border="1" style="color: Black; background-color: LightGoldenrodYellow;
width: 60%;" id="GridView2" rules="all">
<tbody>
<tr style="color: White; background-color: #CF4B0A; font-weight: bold;">
<th align="center" scope="col">
Booked At
</th>
<th align="center" scope="col">
Booked On
</th>
<th align="center" scope="col">
Delivered At
</th>
<th align="center" scope="col">
Delivered On
</th>
<th scope="col">
Details
</th>
</tr>
<tr align="left" style="color: #333333; background-color: #FFFBA1; font-family: Arial;
font-size: Small;">
<td align="center">
Not Available
</td>
<td align="center">
Not Available
</td>
<td align="center">
DATA
</td>
<td align="center">
12/01/2012
</td>
<td>
<a href="javascript:__doPostBack('GridView2$ctl02$LinkButton1','')" id="GridView2_ctl02_LinkButton1">
Details</a>
</td>
</tr>
</tbody>
</table>
I would like to parse the above table using HTML Agility pack. I'm using the HAP solution for WP7, downloaded from Codeplex.
Any quick help will be appreciated.
To parse the HTML, use HAP's HtmlDocument.LoadHtml() function and pass it the actual string. That will give you a DOM with all the HTML objects in it.

Resources