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

text-align: right doesn't work #2103

Closed
maziyaryosofi opened this issue Feb 29, 2020 · 14 comments
Closed

text-align: right doesn't work #2103

maziyaryosofi opened this issue Feb 29, 2020 · 14 comments
Labels

Comments

@maziyaryosofi
Copy link

hi
when i use text-align: right on a div not working correctly.
just lastest line of text work correctly and all of top line not set text-align:right.
how can i solve this? anyone ever found this problem too?

@simonberger
Copy link
Member

simonberger commented Mar 1, 2020

@maziyaryosofi Please add a minimal example of your problem.
I did some test which all showed no problems. If this does not work somewhere, it should be caused by a special case.

Issue added also to laravel plugin: barryvdh/laravel-dompdf#664

@maziyaryosofi
Copy link
Author

maziyaryosofi commented Mar 1, 2020

hi

my controller code is:
`$data['description'] = 'این یک متن تست جهت بررسی موضوع باشد. این یک متن تست جهت بررسی موضوع باشد. این یک متن تست جهت بررسی موضوع باشد.';

$pdf = PDF::loadView('printpdf', $data)->setPaper('a4', 'landscape');
return $pdf->download('print.pdf');`

and my printpdf.balde.php is:
printpdf.blade.zip

@simonberger
Copy link
Member

simonberger commented Mar 1, 2020

Works in the newest version of dompdf.

Extracted HTML document:

<!DOCTYPE html>
<html lang="fa">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1, maximum-scale=1, viewport-fit=cover, shrink-to-fit=no">
    <style type="text/css">
        @font-face {
            font-family: 'iransans';
            font-style: normal;
            font-weight: normal;
            src: url('fonts/iransans.ttf') format('truetype');
        }
        body{
            margin: 0 0 0 0;
            padding: 0 0 0 0;
            direction: rtl;
            width: 297mm;
            height: 210mm;
            direction: rtl;
        }
        .control-body {
            position: relative;
            left: 114mm;
            top: 48mm;
            width: 178mm;
            height: 89.5mm;
            padding: 0 0 0 0;
            margin-right: 0;
        }
        .description{
            position: absolute;
            top: 67.2mm;
            right: 87mm;
            width: 54mm;
            height: 17mm;
            /*background: #000000;*/
            color: #000000;
            font-family: "iransans";
            font-size: 13px;
            line-height: 5px;
            vertical-align: middle;
            text-align: right;
            padding: 0 0 0 0;
            margin: 0 0 0 0;
        }
    </style>
</head>
<body dir="rtl" style="direction: rtl">
<div class="control-body">
    <div class="description">این یک متن تست جهت بررسی موضوع باشد. این یک متن تست جهت بررسی موضوع باشد. این یک متن تست جهت بررسی موضوع باشد.</div>
</div>
</body>
</html>

Don't you use the newest version of barryvdh/laravel-dompdf ?

@maziyaryosofi
Copy link
Author

i downloaded it 5 days ago.
need to download it again?

i get this pdf when run it and all of text and line doesn't have text-align:right;
print.pdf

@simonberger
Copy link
Member

No this is not how it looks like.
dompdf2103.pdf

Either it is a problem of your font (I used this to test; http://fontsfree.net/iransans-font-download.html), or of the laravel wrpapper (it shouldnt do something special I hope) or you aren't using the newest release of dompdf together with laravel-dompdf. You should check your version.

@maziyaryosofi
Copy link
Author

hi
i install dompdf again.
install font you suggest and test it. it is work.
but i add miladhamzelou/dompdf-persian to dompdf to use persian, after do it text-align: right doesn' work.

from miladhamzelou/dompdf-persian package i add this code to the root dompdf/dompdf.
I18N.zip

and then go to the dompdf/dompdf/src/renderer/Text.php and above
$this->_canvas->text($x, $y, $text,
addedd this code:
if (!class_exists('I18N_Arabic')) { require_once( DOMPDF_DIR . "/I18N/Persian/Glyphs.php" ); $Arabic = new \I18N_Persian_Glyphs('Glyphs'); $text = $Arabic->utf8Glyphs($text); }

after do this word text-align right not working as well.
please help me, how can i solve this?
with warm regard.

@simonberger
Copy link
Member

We can't provide this kind of support here. If you provide an actual html which is then rendered incorrectly by dompdf i kindly help you.
But I won't debug through the use of third party packages what is going wrong.

@maziyaryosofi
Copy link
Author

thanks alot.
but how can i use persian text in dompdf?

@simonberger
Copy link
Member

simonberger commented Mar 3, 2020

Your reporting style doesn't help much. You state something does not work without saying what and what you expect.
I start to think you misinterpret what text-align right means.
That has nothing to do with text from right to left which is part of the persian language. It just aligns they text on the right side of the HTML container it is in.

Right to left languages are indeed not really supported right now. I am interested to open dompdf to everyone and have a look at it in the nearer future but right now you have to use what's available.
Here are some sources you can look at Maybe something works for you.

#1904
#2066
#712

EDIT:
What you did sounds exactly like what the first mentioned pull request does. This code would break normal usage of dompdf but should at least do something for your case. If not add some printing to your code to debug it.

@maziyaryosofi
Copy link
Author

how can i add printing to my code to see where is the problem?

@simonberger
Copy link
Member

Simply adding for example:

echo "Transform text: " . $text;
$text = $Arabic->utf8Glyphs($text);
echo " -> " . $text . "\n";

to see if it has any impact. From this point you can debug into the utf8Glyphys method later. One guess for example is an encoding problem.
If you can't access the printed text you can also just write it into a file.

But as written before I can't provide more support here. There will be some progress regarding RTL language support soon though.

@simonberger
Copy link
Member

simonberger commented Mar 7, 2020

@maziyaryosofi Please have a try of #2107 and let me know how it works for you

@bsweeney
Copy link
Member

bsweeney commented Jun 8, 2020

I think we're going to have to push implementation of this one while we work out some issues with initial support.

@bsweeney
Copy link
Member

Closing this issue as insufficiently instructive of the problem. Alignment should be working as expected with the current release. Complex text layout (bidi, shaping, ordering) is still under development. Follow #2619 for updates.

@bsweeney bsweeney removed this from the dompdf-next milestone Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants