Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML rtl content . #2558

Closed
BahaaEldeenOsama opened this issue Jan 26, 2024 · 11 comments
Closed

HTML rtl content . #2558

BahaaEldeenOsama opened this issue Jan 26, 2024 · 11 comments

Comments

@BahaaEldeenOsama
Copy link

BahaaEldeenOsama commented Jan 26, 2024

I try to decode html code with Arabic language appear in template word rtl, but appear every time ltr.

        $html ='<p dir="rtl" style="text-align: right;">
                            <span style="font-size: 14pt; color: rgb(0, 0, 0);">
                                <strong>
                                    <span lang="AR-SA" style="text-align: right; direction: rtl" >أتعهد أنا المتدرب/ة المذكور/ة أعلاه بالالتزام بتعليمات البرنامج التدريبي (رواد السياحة) بالتالي</span>
                                </strong>
                            </span>
                        </p>
        
                        
    
                    <p class="MsoListParagraphCxSpMiddle" dir="RTL" style="margin-right: 32.2pt; mso-margin-bottom-alt: auto; mso-add-space: auto; text-indent: -18.0pt; line-height: normal; mso-list: l0 level1 lfo1; background: white;">
                        <span style="font-size: 12pt; color: rgb(0, 0, 0);">
                            <span style="line-height: 107%; font-family: Symbol;">
                                <span style="mso-list: Ignore;">&middot;<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-weight: normal; font-stretch: normal; line-height: normal; font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>
                            </span>
                            <!--[endif]-->
                            <span lang="AR-SA" style="line-height: 107%;">أتعهد بصحة البيانات المرفوعة وأتحمل كامل المسؤولية إذا ثبت خلاف ذلك</span>
                        </span>
                    </p>
    
                    <p class="MsoListParagraphCxSpMiddle" dir="RTL" style="margin-right: 32.2pt; mso-margin-bottom-alt: auto; mso-add-space: auto; text-indent: -18.0pt; line-height: normal; mso-list: l0 level1 lfo1; background: white;">&nbsp;</p>
                    <p class="MsoListParagraphCxSpMiddle" dir="RTL" style="margin-right: 32.2pt; mso-margin-bottom-alt: auto; mso-add-space: auto; text-indent: -18.0pt; line-height: normal; mso-list: l0 level1 lfo1; background: white;">
                        <span style="font-size: 12pt; color: rgb(0, 0, 0);">
                            <span lang="AR-SA" style="line-height: 107%;">
                                <span style="font-size: 14pt; color: rgb(0, 0, 0);">
                                    <strong>
                                        <span lang="AR-SA">بناء على جميع ما سبق فإني أتفهم بشكل كامل أنه في حال إخلالي بأي من بنود التعهد فإني أتحمل كامل المسؤولية على ذلك</span>
                                    </strong>
                                </span>
                            </span>
                        </span>
                    </p>';


  $phpWord = new PhpWord();
  $section = $phpWord->addSection();
  $wordTable = $section->addTable();
  $wordTable->addRow();
  $cell = $wordTable->addCell();
  Html::addHtml($cell, $html, false, false);
  $templateProcessor->setComplexBlock('HTML', $wordTable);
@BahaaEldeenOsama BahaaEldeenOsama changed the title How to appear decode HTML Arabic words rtl in template . HTML rtl content . Jan 26, 2024
@BahaaEldeenOsama
Copy link
Author

@Progi1984

@BahaaEldeenOsama
Copy link
Author

@troosan

@oleibman
Copy link
Contributor

After

$phpWord = new PhpWord();

Try adding:

Settings::setDefaultRtl(true);

@BahaaEldeenOsama
Copy link
Author

BahaaEldeenOsama commented Jan 29, 2024

I tried use this function but, setDefaultRtl is not a function in : Settings

I used versions of

  phpoffice/phpword : 0.18.3
  php : 8.1

@oleibman

@oleibman
Copy link
Contributor

Try upgrading to the latest PhpWord release (1.2.0).

@BahaaEldeenOsama
Copy link
Author

BahaaEldeenOsama commented Jan 30, 2024

Many thanks @oleibman 🙏

@BahaaEldeenOsama
Copy link
Author

BahaaEldeenOsama commented Jan 30, 2024

@oleibman
appreciate your reply.

I Try to use section rather than table cell to do the height is dynamic with content .
but appear I need use class of element "Class "PhpOffice\PhpWord\Writer\Word2007\Element\Section" not found", I actually use it .

@oleibman
Copy link
Contributor

The error message is correct - there is no such class. I'm not sure why it tried to access it. Can you show me all your code so that I can try to figure out what's going wrong. Here's what I used, without any problems:

  $phpWord = new PhpWord();
  Settings::setDefaultRtl(true);
  $section = $phpWord->addSection();
  Html::addHtml($section, $html, false, false);

@BahaaEldeenOsama
Copy link
Author

BahaaEldeenOsama commented Jan 30, 2024

I want to access the setComplexBlock() with section to avoid limitation of fixed height in table cell .

 $phpWord = new PhpWord();
  Settings::setDefaultRtl(true);
  $section = $phpWord->addSection();
  Html::addHtml($section, $html, false, false);
  $templateProcessor->setComplexBlock('HTML', $section); // error here

@oleibman
Copy link
Contributor

I am not familiar enough with TemplateProcessor to make the change I am about to describe. I will open a new issue. As you have seen, you get an error when you try to use setComplexBlock on a section. However, if the section could be treated as a container, it would work. This could be done by inserting a small amount of code in TemplateProcessor. After:

$elementName = substr(get_class($complexType), strrpos(get_class($complexType), '\\') + 1);

Insert:

if ($elementName === 'Section') {
    $elementName = 'Container';
}

Now, no error is thrown, and the result is probably what you want. As I mentioned, I'm not that familiar with TemplateProcessor, so I'm not sure that it is what you want, nor if there are any other repercussions from this change. But you might try it and see if it accomplishes what you want.

@BahaaEldeenOsama
Copy link
Author

I am grateful for your help 🙏
I tried to make section fit with TemplateProcessor, but it not working.
I working to make cell height of table is dynamic with lines of text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants