0

When creating a PDF in PHP (with TCPDF), I have a line of text aligned to the right. When I increase the left margin, this line extends beyond the page border, though the right margin is specified at 10mm. The remaining of the text (left aligned) respects the right margin.

Small left margin works:

$pdf->SetMargins(10, 10, 10, true);
$html = "<p>City name, August 30, 2018</p>";
$pdf->writeHTML($html, true, false, true, false, 'R');

Increased left margin doesn't work:

$pdf->SetMargins(25, 10, 10, true);
$html = "<p>City name, August 30, 2018</p>";
$pdf->writeHTML($html, true, false, true, false, 'R');

The 8 from 2018 disappears to the right of the page. Is this a bug, or am I missing something?

Rodrigo
  • 4,706
  • 6
  • 51
  • 94

1 Answers1

1

I just try to checking at the writeHtml method, and I try to print $this->rtl value, but not changing when I set $align to R.

And I got an idea.

So, I can solve this problem with adding some line of simple code.

// path/to/tcpdf.php
// Line: 17140
if ($align == 'R') {
    $this->rtl = true;
}

Adding code to library:

Result:

Hope this can help your problem.

Nur Muhammad
  • 174
  • 10
  • Thank you. It may be a solution. Right now I just reduced the left margin. If the project owner ask me to increase it, I'll use your solution. Sad that PDF is so hard to create in PHP! :( – Rodrigo Aug 31 '18 at 01:45
  • My pleasure. If you want, you can try to use DOMPDF also. – Nur Muhammad Aug 31 '18 at 02:07
  • Yes, I saw it as one of the options [here](https://ourcodeworld.com/articles/read/226/top-5-best-open-source-pdf-generation-libraries-for-php). Have tried a few of those, each one with their own set of problems. Haven't tried DOMPDF yet, though. Thank you! – Rodrigo Aug 31 '18 at 02:35