gpt4 book ai didi

php - 在 FPDF 中将页面方向更改为从右到左

转载 作者:行者123 更新时间:2023-12-05 06:47:13 24 4
gpt4 key购买 nike

我正在使用 php 和 reportico 开发一个基于网络的报告应用程序。我想用波斯语(波斯语)制作报告,所以我需要更改 PDF 文件的方向(从左到右,到右到左).FPDF 是否对此有任何支持,或者在 reportico 中是否有任何解决方案?

最佳答案

看到这个 URL,我认为它非常有帮助。

http://www.fpdf.de/downloads/addons/31/

或尝试一下。

描述:此扩展允许打印旋转和剪切(即像斜体一样扭曲)的文本。

TextWithDirection(float x, float y, string txt [, string direction])

x: 横坐标

y: 纵坐标

txt:文本字符串

方向:以下值之一(默认为R):

  • R(右):从左到右
  • U(上):从下到上
  • D(向下):从上到下
  • L(左):从右到左

TextWithRotation(float x, float y, string txt, float txt_angle [, float 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();
?>

输出:- http://www.fpdf.org/en/script/ex31.pdf

关于php - 在 FPDF 中将页面方向更改为从右到左,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12233949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com