ab-alselwi/laravel-arabic-html
Composer 安装命令:
composer require ab-alselwi/laravel-arabic-html
包简介
Convert laravel view to arabic html (pdf) by using ArPHP and dompdf with arabic fonts and text.
README 文档
README
To handle Arabic text issue in a more clean way with no need to hack dompdf script at all.
This package makes it easy to convert view blade to pdf using laravel-dompdf and Ar-PHP.
قمنا بكتابة هذا الباكج لدعم اللغة العربية في مكتبة laravel-dompdf من خلال استخدام Ar-PHP سيقوم الباكج بتنزيل المكتبات المطلوبة في حال كانت غير موجودة دون الحاجة لتنزيلها كلاً على حده.
يوفر هذا الباكج حالياً دالة واحدة فقط وهي toArabicHTML() بالاضافة إلى انه يمكنك استخدام المكتبات الأصلية في تحويل أي محتوى إلى ملف pdf .
Contents
Requirements
- DOM extension
- MBString extension
- php-font-lib
- php-svg-lib
Note that some required dependencies may have further dependencies (notably php-svg-lib requires sabberworm/php-css-parser).
Recommendations
- OPcache (OPcache, XCache, APC, etc.): improves performance
- GD (for image processing)
- IMagick or GMagick extension: improves image processing performance
Installation
Package Installation
Install the package using composer:
composer require ab-alselwi/laravel-arabic-html
Configuration
فقط هنا تحتاج للقيام باعداد المكتباات المرتبطة .
The defaults configuration settings are set in config/dompdf.php. Copy this file to your own config directory to modify the values. You can publish the config using this command:
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
ينصح بتحديد مجلد الخطوط في المسار storage\fonts .
You need to setup font_dir in config\dompdf by copy fonts folder to storage\fonts or any folder with read and write permissions. You should be carful when write css , and font . you can't use font-weight:number like font-weight:600 ; just use font-weight:bold.
بعض التنسيقات قد لا يتم دعمها في dompdf مثل font-weight مع القيم الرقمية بالاضافة للعديد من التنسيقات التي تعتمد على flex box , ولعرض رسالة خطأ في حال وجود أي تنسيقات غير مدعومة يمكنك تغيير اعدادات عرض الخطاء كما يلي :
'show_warnings' => true , // Throw an Exception on warnings from dompdf
for more detials about dompdf settings :
Usage
To handle Arabic text issue in a more clean way with no need to hack dompdf script at all.We use View macro, so use view('your_blade_view_name')->toArabicHTML() to support any content in Arabic . dompdf/dompdf#712 (comment)
function parameters :
- $line_length :int ,optional, default 100. max length in line.
- $hindo :bool, optional, default false. convert numbers in text to hindo.
- $forcertl :bool, optional, default false. force right to left document direction.
تسختدم الدالة دالة utf8Glyphs الموجودة في مكتبة Ar-PHP لذا يمكنك أن تقوم بتخصيص بارامترات هذه الدالة حيث :
- 1 - $line_length : اختياري رقم - في حال وجود نصوص طويلة قد يتطلب منك تحديد كم حرفاً في السطر الواحد قمنا بتعديل القيمة الافتراضية من 50 الى 100 حرف .
- 2- $hindo : اختياري قيمة منطقية bool في حال رغبت في تحويل الأرقام الموجودة في المستند إلى أرقام هندية قمنا بتعديل القيمة الافتراضية إلى false حيث ستبقى الأرقام على حالها بألارقام العربية والتي تكتب في اللغة الانجليزية حالياُ
- 3- $forcertl : اختياري قيمة منطقية bool تتوافق القيمة الافتراضية مع الدالة الأصلية false حيث تشير إلى فرض تحويل اتجاه المستند من اليمين إلى اليسار
Example:
$html = view('invoice')->toArabicHTML(); $pdf = PDF::loadHTML($html)->output(); $headers = array( "Content-type" => "application/pdf", ); // Create a stream response as a file download return response()->streamDownload( fn () => print($pdf), // add the content to the stream "invoice.pdf", // the name of the file/stream $headers );
هذا هو شكل ال view invoice.blade.php
<!DOCTYPE html> <html dir="rtl"> <head> <title>Arabic Invoice </title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { font-family: DejaVu Sans !important; } body { font-size: 16px; font-family: 'DejaVu Sans', 'Roboto', 'Montserrat', 'Open Sans', sans-serif; padding: 10px; margin: 10px; color: #777; } body { color: #777; text-align: right; } body h1 { margin-bottom: 0px; padding-bottom: 0px; color: #000; } body h3 { margin-top: 10px; margin-bottom: 20px; color: #555; } body a { color: #06f; } @page { size: a4; margin: 0; padding: 0; } .invoice-box table { direction: ltr; width: 100%; text-align: right; border: 1px solid; font-family: 'DejaVu Sans', 'Roboto', 'Montserrat', 'Open Sans', sans-serif; } .row { display: block; padding-left: 24; padding-right: 24; page-break-before: avoid; page-break-after: avoid; } .column { display: block; page-break-before: avoid; page-break-after: avoid; } </style> </head> <body> <div class="row"> <div class="column"> <p class="text-darky">بيانات باللغة العربية </p> </div> </div> <h1>ان هذا عبارة عن قالب عادي </h1> <h3>ومن هنا قمنا بعرض قالب اعتيادي فقط كمثال توضيحي .</h3> <div class="invoice-box"> <table> <tr class="top"> <td colspan="2"> <table> <tr> <td class="title"> </td> <td> فاتورة #: 123<br /> الانشاء : يناير 1, 2015<br /> تاريخ : فبراير 1, 2015 </td> </tr> </table> </td> </tr> <tr class="heading"> <td>العنصر </td> <td>السعر </td> </tr> <tr class="item"> <td>تصميم موقع </td> <td>$300.00</td> </tr> <tr class="item"> <td>استضافة (3 أشهر )</td> <td>$75.00</td> </tr> <tr class="item "> <td>نطاق (1 عام )</td> <td>$10.00</td> </tr> <tr class="total last"> <td>الإجمالي : </td> <td>$385.00 </td> </tr> </table> <div> <p lang="ar"> انما نحن هنا نقوم بكتابة نصوص عربية فلما لا يكون هناك اخرى مما قد يحتم علينا أن نكتب أكثر.<br> وعليه فإن السطر هذا يعتبر سطر جديد </p> </div> </div> </body> </html>
ab-alselwi/laravel-arabic-html 适用场景与选型建议
ab-alselwi/laravel-arabic-html 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32.8k 次下载、GitHub Stars 达 36, 最近一次更新时间为 2022 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「arabic」 「arabic-glyphs」 「arabic-calendar」 「arabic-html」 「arabic-dompdf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ab-alselwi/laravel-arabic-html 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ab-alselwi/laravel-arabic-html 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ab-alselwi/laravel-arabic-html 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Set of functionalities enable Arabic website developers to serve professional search, present and process Arabic content in PHP
ar-php-laravel
ar-php-laravel
Convert numbers to Arabic words
Laravel MPdf : Easily generate PDF files with arabic support
Package to convert English number to Nepali number and Nepali number to English number.
统计信息
- 总下载量: 32.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-13