我正在開發一個使用php和reportico的Web基礎報告應用程序。我想在波斯語(波斯語)中創建報告,所以我需要更改PDF文件的方向(從左從右到左)。是否有任何FPDF中的支持或解決方案在reportico中解決?在FPDF中將頁面方向更改爲從右到左
1
A
回答
1
看到這個URL我認爲它非常有幫助。
http://www.fpdf.de/downloads/addons/31/
或嘗試它。
描述:該擴展允許打印旋轉和剪切(即斜體變形)文本。
TextWithDirection(浮動的x,浮Y,串TXT [,字符串方向])
X:橫座標
Y:座標
TXT:文本串
方向:之一以下值(默認爲R):
- R(右):從左到右
- U(向上):底部到頂部
- d(下):從上到下
- L(左):從右到左
TextWithRotation(浮法X,浮法Y,串TXT,浮txt_angle [,浮動font_angle])
X:橫座標
Y:座標
TXT:文本串
txt_angle:文本的角度
font_angle:(默認0)剪切角
源
<?php
require('fpdf.php');
class RPDF extends FPDF {
function TextWithDirection($x, $y, $txt, $direction='R')
{
$txt=str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt)));
if ($direction=='R')
$s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', 1, 0, 0, 1, $x*$this->k, ($this->h-$y)*$this->k, $txt);
elseif ($direction=='L')
$s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', -1, 0, 0, -1, $x*$this->k, ($this->h-$y)*$this->k, $txt);
elseif ($direction=='U')
$s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', 0, 1, -1, 0, $x*$this->k, ($this->h-$y)*$this->k, $txt);
elseif ($direction=='D')
$s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', 0, -1, 1, 0, $x*$this->k, ($this->h-$y)*$this->k, $txt);
else
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET', $x*$this->k, ($this->h-$y)*$this->k, $txt);
if ($this->ColorFlag)
$s='q '.$this->TextColor.' '.$s.' Q';
$this->_out($s);
}
function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
{
$txt=str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt)));
$font_angle+=90+$txt_angle;
$txt_angle*=M_PI/180;
$font_angle*=M_PI/180;
$txt_dx=cos($txt_angle);
$txt_dy=sin($txt_angle);
$font_dx=cos($font_angle);
$font_dy=sin($font_angle);
$s=sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET',
$txt_dx, $txt_dy, $font_dx, $font_dy,
$x*$this->k, ($this->h-$y)*$this->k, $txt);
if ($this->ColorFlag)
$s='q '.$this->TextColor.' '.$s.' Q';
$this->_out($s);
}
}
?>
例
<?php
define('FPDF_FONTPATH', 'font/');
require('rpdf.php');
$pdf=new RPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 40);
$pdf->TextWithRotation(50, 65, 'Hello', 45, -45);
$pdf->SetFontSize(30);
$pdf->TextWithDirection(110, 50, 'world!', 'L');
$pdf->TextWithDirection(110, 50, 'world!', 'U');
$pdf->TextWithDirection(110, 50, 'world!', 'R');
$pdf->TextWithDirection(110, 50, 'world!', 'D');
$pdf->Output();
?>
0
它可能不是提供最佳的解決方案,但你可以隨時更改方法本身,因爲它是使用細胞方法(支持對齊),你只需要做$對齊參數的方法然後更改所有正在打印文本的行。
(有哪些必須更換六個地方,在最後部分是有點棘手)
也請考慮我剛纔所做的更改,您可能需要修正一些錯誤,但以下是寫方法會是什麼樣子到底,
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);
}
}
}
相關問題
- 1. Aspx將頁面方向更改爲從右到左
- 2. 在Pyocr中將文本方向從左到右更改爲
- 3. 將動作欄方向更改爲從右到左
- 4. Xamarin表單內容頁面:將流向更改爲從右向左?
- 5. 將LinearLayout更改爲從左到右
- 6. 在通用Windows項目中將樞軸方向更改爲從右到左
- 7. 在Splitviewcontroller中將Masterview的位置從左向右更改爲
- 8. ExtJS的面板方向 - 從右到左
- 9. 如何在HorizontalScrollView中從右向左更改滾動方向
- 10. wxWidgets從右到左方向
- 11. 向左/向右滾動到新頁面
- 12. 如何將ShowMessageAsync流向更改爲「從右向左」?
- 13. UIViewAnimationTransitionCurlUp從橫向(左和右)方向從右到左
- 14. 頁面從左向右滾動
- 15. 如何更改新聞速遞運動方向從左到右
- 16. 更改組織結構圖的方向從左到右
- 17. 更改HTML <title>標籤的方向從右到左
- 18. 頁面加載中間/從右到左
- 19. 如何從右向左更改輸入文本方向
- 20. 如何從右向左更改滾動條的方向?
- 21. 在從右到左的頁面中設置滾動條的正確方向
- 22. 如何在prestashop中將產品頁面佈局更改爲左右兩列
- 23. 如何在Android中將圖像從左到右從右向左移動?
- 24. 如何改變書寫方向爲「從右至左」在Eclipse
- 25. 如何在Oracle中從右向左更改我的文本的方向?
- 26. 從左到右jQuery Mobile頁面轉換
- 27. 在Android中的Verticle Slider中將屏幕的方向轉換從右向左更改爲
- 28. 梯度方向從左到右
- 29. delphi TActionMainMenuBar方向從右到左
- 30. Ext.NET TextField的從右到左方向
感謝您的答案,但我想改變整個頁面的方向...你有什麼建議嗎? – hamedkh