I' developing a web base reporting application using php and reportico.I want to make reports in Farsi(Persian) so I need to change the direction of PDF files(From left-to-right, to rght-to-left).is there any supprot for that in FPDF, or any solution to solve it in reportico?
changing page direction to right-to-left in FPDF
3.8k Views Asked by hamedkh At
2
There are 2 best solutions below
0

It might not be the best solution to offer, But you can always change the method itself, Since it is using Cell method (which supports alignment), You only have to do the $align parameter on the method and then change all the lines which are printing the text.
(There are six places which it must be replaced, The last part is a little tricky)
Also Please consider that I have just made the changes And you may have to fix a few bugs, But Here is what Write method would look like in the end,
function Write($h, $txt, $link='', $align='L')
{
// Output text in flowing mode
$cw = &$this->CurrentFont['cw'];
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin);
$s = str_replace("\r",'',$txt);
if ($this->unifontSubset) {
$nb = mb_strlen($s, 'UTF-8');
if($nb==1 && $s==" ") {
$this->x += $this->GetStringWidth($s);
return;
}
}
else {
$nb = strlen($s);
}
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while($i<$nb)
{
// Get next character
if ($this->unifontSubset) {
$c = mb_substr($s,$i,1,'UTF-8');
}
else {
$c = $s[$i];
}
if($c=="\n")
{
// Explicit line break
if ($this->unifontSubset) {
$this->Cell($w,$h,mb_substr($s,$j,$i-$j,'UTF-8'),0,2,$align,0,$link);
}
else {
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,$align,0,$link);
}
$i++;
$sep = -1;
$j = $i;
$l = 0;
if($nl==1)
{
$this->x = $this->lMargin;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin);
}
$nl++;
continue;
}
if($c==' ')
$sep = $i;
if ($this->unifontSubset) { $l += $this->GetStringWidth($c); }
else { $l += $cw[$c]*$this->FontSize/1000; }
if($l>$wmax)
{
// Automatic line break
if($sep==-1)
{
if($this->x>$this->lMargin)
{
// Move to next line
$this->x = $this->lMargin;
$this->y += $h;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin);
$i++;
$nl++;
continue;
}
if($i==$j)
$i++;
if ($this->unifontSubset) {
$this->Cell($w,$h,mb_substr($s,$j,$i-$j,'UTF-8'),0,2,$align,0,$link);
}
else {
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,$align,0,$link);
}
}
else
{
if ($this->unifontSubset) {
$this->Cell($w,$h,mb_substr($s,$j,$sep-$j,'UTF-8'),0,2,$align,0,$link);
}
else {
$this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,$align,0,$link);
}
$i = $sep+1;
}
$sep = -1;
$j = $i;
$l = 0;
if($nl==1)
{
$this->x = $this->lMargin;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin);
}
$nl++;
}
else
$i++;
}
// Last chunk
if($i!=$j) {
if ($this->unifontSubset) {
$this->Cell($w, $h,mb_substr($s,$j,$i-$j,'UTF-8'),0,0,$align,0,$link);
// $this->Cell($l, $h,mb_substr($s,$j,$i-$j,'UTF-8'),0,0,'',0,$link);
}
else {
$this->Cell($w, $h,substr($s,$j),0,0,$align,0,$link);
// $this->Cell($l, $h,substr($s,$j),0,0,'',0,$link);
}
}
}
See this URL i think it very help full.
http://www.fpdf.de/downloads/addons/31/
OR Try it.
Description : This extension allows to print rotated and sheared (i.e. distorted like in italic) text.
TextWithDirection(float x, float y, string txt [, string direction])
x: abscissa
y: ordinate
txt: text string
direction: one of the following values (R by default):
TextWithRotation(float x, float y, string txt, float txt_angle [, float font_angle])
x: abscissa
y: ordinate
txt: text string
txt_angle: angle of the text
font_angle: shear angle (0 by default)
Source
Example
output:- http://www.fpdf.org/en/script/ex31.pdf