Arabic And Persian Support Added To DOM PDF

This commit is contained in:
devansh bawari 2021-01-08 20:23:01 +05:30
parent 445d116fc0
commit 71abe8f4ca
3 changed files with 75 additions and 1476 deletions

View File

@ -33,6 +33,7 @@
"intervention/image": "^2.4",
"intervention/imagecache": "^2.3",
"kalnoy/nestedset": "5.0.1",
"khaled.alshamaa/ar-php": "^5.5",
"konekt/concord": "^1.2",
"laravel/framework": "^7.0",
"laravel/scout": "^8.0",

1522
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,10 @@
namespace Webkul\Admin\Http\Controllers\Sales;
use PDF;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Sales\Repositories\InvoiceRepository;
use PDF;
class InvoiceController extends Controller
{
@ -141,8 +141,30 @@ class InvoiceController extends Controller
{
$invoice = $this->invoiceRepository->findOrFail($id);
$pdf = PDF::loadView('admin::sales.invoices.pdf', compact('invoice'))->setPaper('a4');
$html = view('admin::sales.invoices.pdf', compact('invoice'))->render();
return $pdf->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf');
return PDF::loadHTML($this->adjustArabicAndPersianContent($html))
->setPaper('a4')
->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf');
}
/**
* Adjust arabic and persian content.
*
* @param string $html
* @return string
*/
private function adjustArabicAndPersianContent($html)
{
$arabic = new \ArPHP\I18N\Arabic();
$p = $arabic->arIdentify($html);
for ($i = count($p)-1; $i >= 0; $i-=2) {
$utf8ar = $arabic->utf8Glyphs(substr($html, $p[$i-1], $p[$i] - $p[$i-1]));
$html = substr_replace($html, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
}
return $html;
}
}