0

This is my controller stockcontroller.php, using for export data

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 is working fine while PDF is not supporting Arabic content it shows ????? like symbols in place of Arabic language. Note : Previously I was using same code for pdf and excel there was the same issue. So I try to make it separate from excel

  • does the fonts exists? at least, does dompdf know where to load the fonts? – Bagus Tesa May 15 '17 at 13:14
  • There are _fonts_ folder inside **dompdf lib** which contains some fonts, but which one is necessary for Arabic. I don't know. – user3640494 May 15 '17 at 13:19
  • can take a look on it? at least, if its working in excel, you had the fonts.. really, check the font in excel, try to find its filename in `Windows/Fonts` directory.. compare it with dompdf lib. it's been ages since my last time meddling with dompdf.. – Bagus Tesa May 15 '17 at 13:21
  • I am using Ubuntu, also tried with font change, but still not working – user3640494 May 15 '17 at 17:42
  • which package do you have used for pdf? – MohamedSabil83 May 15 '17 at 20:29
  • Ah i see, i never used Laravel in a dedicated *nix family. But it looks like you could check on /etc/share/fonts based on [this QA about font location](https://superuser.com/a/774883/534347). The reason i pointed out fonts, in most cases PDF will 'burn' the text into image. @MohamedSabil83 its on the tag, `dompdf`. – Bagus Tesa May 15 '17 at 22:44
  • just dompdf? you have used `composer require **what**` to install it. also, take a look for `niklasravnsborg/laravel-pdf` – MohamedSabil83 May 16 '17 at 00:40
  • @MohamedSabil83 first i have tried with **"dompdf/dompdf": "0.6.2"** then due to some issue on server I am using Dompdf folder(from github) and using following in controller to make it work use Dompdf\Dompdf; // on top inside function using following include ('dompdf/autoload.inc.php'); // to make it work, reset code is above – user3640494 May 16 '17 at 05:52
  • Now I am using TCPDF in place of dompdf, which provides Arabic lang support with "dejavusans" font. – user3640494 May 24 '17 at 09:19

0 Answers0