Briskstar Technologies
Briskstar Technologies

Reputation: 2253

Print Arabic Text - Right to Left

In print page, I am passing css: direction: rtl to see arabic properly.

But while, printing all other css styles gets applied but direction: rtl is not working and prints normal left to right texts of Arabic.

Here is the JS Fiddler

Here is the codes

<div class="formBLock" style="padding-top:0px;">

        <div class="formCon CaseDetailsButton">
            <div class="divbtn">
                <a class="btn more2" href="/ClientInquiry/ar/CaseInquiry">الرجوع </a>
            </div>
            <div class="divbtn">
                            <input type="button" id="btnPrint" class="btn more2" value="طباعة "/>   
             </div>
        </div>

               <div id="dvPrint">
                    <div style="border:1px black solid;width:90%;margin-left:5%;margin-right:5%;float:right;margin-top:10px;">
                            <div style="border-bottom:1px black solid;float:right;margin-top: 10px;width: 100%;">
                                <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; font-weight:bold;"> تم استلام طلبكم : الاستعلام عن تقرير الحادث</span>
                            </div>  
                            <div style="border-bottom:1px black solid;float:right;margin-top: 10px;width: 100%;">
                                <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%;">شكرا لاستخدامكم نظام شركة نجم للاستعلام </span><br />
                                <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%;">المعلومات أدناه توضح الوضع الحالي لمستندات الحادث</span>
                            </div>   
                            <div style="border:1px solid black;width:90%;margin-left:5%;margin-right:5%;height:200px;float:right;margin-top: 10px;">
                                <div style="float:right;width:30%;">
                                    <div style="height:50px;border-bottom:1px solid black;text-align:center;border-left:1px solid #000000">
                                        <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; margin-top:7%;">بيانات الحادث</span>
                                    </div>   
                                    <div style="height:150px;text-align:center;border-left:1px solid #000000">
                                        <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; margin-top:30%;">حالة إرسال المستندات</span>
                                    </div>   
                                </div>
                                <div style="height:200px;width:33.3%;margin-top:0px;float:right;border-left:1px solid #000000">
                                    <div style="border-bottom:1px solid black;height:50px;text-align:center;">
                                        <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; margin-top:6%;">رقم الحالة</span>
                                    </div>
                                    <div style="border-bottom:1px solid black;height:50px;text-align:center;">
                                        <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; margin-top:6%;">حالة الإرسال</span>
                                    </div>
                                </div>
                                <div style="height:100px;width:36.3%;margin-top:0px;float:right;">
                                    <div style="border-bottom:1px solid black;height:50px;">
                                        <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; margin-top:6%;">RD21031414</span>
                                    </div>
                                    <div style="border-bottom:1px solid black;height:50px;">
                                           <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; margin-top:6%;">&nbsp;قيد المعالجة من شركة نجم</span>
                                    </div>
                                </div>
                            </div>

                            <div style="border-top:1px solid black;float:right;margin-top: 10px;width: 100%;">
                                <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%; font-weight:bold;">شركة نجم لخدمات التأمين</span>
                                <span style="color: #8F8E8E;float: right;font-family: Tahoma;font-size: 15px;font-weight: normal;margin-bottom: 5px;margin-right: 10px;margin-top: 1px;vertical-align: middle;width: 90%;">لمزيد من المعلومات يرجى الاتصال بـ 920000460 كما يمكنك زيارة 
                                    <a href="CaseFooterLink" target="_blank">Site.sa</a>
                                    أو الفرع الأقرب لشركة نجم 
                                </span>
                            </div>
                    </div>
                </div>  
        <iframe name="print_frame" width="0" height="0" frameborder="0" src="about:blank"></iframe>
    </div> 

javascript:

$(document).ready(function () {

     $("#btnPrint").click(function () {
         var ObjdvPrint = $("#dvPrint");
         window.frames["print_frame"].document.body.innerHTML = ObjdvPrint.html();
         window.frames["print_frame"].window.focus()
         window.frames["print_frame"].window.print()
         return false;
     });
 });

Upvotes: 1

Views: 3703

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201518

The problem is, as per the comments, that when a print button is used, the data printed has text aligned to the left, not right (the writing direction is not the issue).

The reason is that the printing is performed this way:

var ObjdvPrint = $("#dvPrint");
window.frames["print_frame"].document.body.innerHTML = ObjdvPrint.html();
window.frames["print_frame"].window.focus()
window.frames["print_frame"].window.print()

So a frame is created, containing only an element (with id="dvPrint") of the original document. This element has various inline styles (in style attributes), but nothing that would set the horizontal alignment, so the default text-align: left is applied. Whatever is set on the body element of the original document has no impact.

The fix is to set the alignment on the content of that element, in a manner that is retained when the frame is created. Since you are using innerHTML, it does not help to set things on that element itself. But in this case, the content of that element is a single inner div element, so it helps to set the alignment to it:

<div id="dvPrint">
   <div dir="rtl" style="...">

You could alternatively just add text-align: right in the content of the style attribute of the inner element. But dir="rtl" by definition sets the horizontal alignment (text-align: right), among other things. It also sets the overall writing directionality, which is normally not necessary, but a good precaution against a) browser bugs and b) possible mix of e.g. Arabic and Latin characters in some future version of the document.

Upvotes: 3

Briskstar Technologies
Briskstar Technologies

Reputation: 2253

By using below meta it will work.

http://www.katpatuka.org/pub/doc/content-language/ar.htm

Thanks everyone for help !!!?

Upvotes: 1

Related Questions