这是我的控制器stockcontroller.php,用于导出数据
public function exportStock(Request $request)
{
header('http-equiv : Content-Type; Content-Type: text/html; charset=utf-8');
if($request->status=='show')
{
$su=stock::where('is_active',1);
}
elseif ($request->status=='hide')
{
$su=stock::where('is_active',0);
}
else{
$su=stock::where('is_active','!=',2);
}
$su=$su->get();
$exp=$request->exp;
if($exp=='Export to Excel') {
$exp = 'XLS';
Excel::create('Export Data', function ($excel) use ($su) {
$excel->sheet('sheet 1', function ($sheet) use ($su) {
$sheet->appendRow(['S.No.', 'Stock Name(En)', 'Stock Name(Ar)', 'Users participated', 'Quantity', 'Status']);
$sn = 1;
foreach ($su as $p) {
if ($p->userQuantity()->first()) {
$temp = $p->userQuantity()->sum('quantity');
} else {
$temp = '';
}
if ($p->userStocks()->first()) {
$temp2 = $p->userStocks()->count();
} else {
$temp2 = '';
}
if ($p->is_active == '1') {
$st = 'Show';
} elseif ($p->is_active == '0') {
$st = 'Hide';
}
$sheet->appendRow([$sn, $p->name_en, $p->name_ar, $temp, $temp2, $st]);
$sn++;
}
});
})->download($exp);
return redirect('admin/stock');
}
if($exp=='Export to PDF'){$exp='PDF';
include ('dompdf/autoload.inc.php');
// instantiate and use the dompdf class
$var="<table><tr><th>S.No.</th><th>Stock Name(En)</th><th>Stock Name(Ar)</th><th>Users participated</th><th>Quantity</th><th>Status</th></tr>";
$tt=1;
foreach ($su as $dd) {
if ($dd->userQuantity()->first()) {
$temp = $dd->userQuantity()->sum('quantity');
} else {
$temp = '';
}
if ($dd->userStocks()->first()) {
$temp2 = $dd->userStocks()->count();
} else {
$temp2 = '';
}
if ($dd->is_active == '1') {
$st = 'Show';
} elseif ($dd->is_active == '0') {
$st = 'Hide';
}
$var .= "<tr><td>$tt</td><td>$dd->name_en</td><td>$dd->name_ar</td><td>$temp</td><td>$temp2</td><td>$st</td></tr>";
$tt++;
}
$var.="</table>";
$dompdf = new Dompdf();
$dompdf->loadHtml($var);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
}
}
Excel工作正常,而PDF不支持阿拉伯语内容 显示?????像符号代替阿拉伯语。注意 : 以前我使用相同的pdf和excel代码也是一样的 问题。所以我尝试将它与excel分开
答案 0 :(得分:0)
我可以使用mpdf库解决问题。
http://www.solutionsbased.in/laravel-arabic-content-display-issue-in-the-pdf/