如何在 FPDF 中使文本居中?

发布于 2024-10-13 02:20:34 字数 181 浏览 11 评论 0原文

如何让生成的文本显示在页面中央。

生成的 = $_POST 方法...所以我不知道输入中的文本有多长。我需要以某种方式预先确定中心参数。

有什么想法吗?也许是这样的:

MultiCell(0,$height,"text",0,'C') ?

How can I have this generated text appear centered in the page.

Generated = $_POST method ... so I don't know how long will the text in input be. I need to have a pre-determined center parameter somehow.

Any ideas? Maybe like this:

MultiCell(0,$height,"text",0,'C') ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

向地狱狂奔 2024-10-20 02:20:34

通常它是 $pdf->Cell(0, $height, "text", 0, 0, 'C'); 但如果您在页眉或页脚函数中执行此操作,则它是 $this->Cell(0, $height, "text", 0, 0, 'C')。如果您在 function() 调用中执行此操作,请不要忘记将 $height 声明为全局变量。

Normally it's $pdf->Cell(0, $height, "text", 0, 0, 'C'); but if you're doing it in a Header or Footer function it's $this->Cell(0, $height, "text", 0, 0, 'C'). Don't forget to declare $height as a global if you're doing this in a function() call.

君勿笑 2024-10-20 02:20:34

谢谢牛牛!这对我有用:

$mid_x = 135; // the middle of the "PDF screen", fixed by now.
$text = $userFullName;
$pdf_file->Text($mid_x - ($pdf_file->GetStringWidth($text) / 2), 102, $text);

Thanks taur! This works for me:

$mid_x = 135; // the middle of the "PDF screen", fixed by now.
$text = $userFullName;
$pdf_file->Text($mid_x - ($pdf_file->GetStringWidth($text) / 2), 102, $text);
策马西风 2024-10-20 02:20:34

这可能对你有用

MultiCell(0,$height,'You can<P ALIGN="center">center a line</P>',0,'C')

This may work for you

MultiCell(0,$height,'You can<P ALIGN="center">center a line</P>',0,'C')
戴着白色围巾的女孩 2024-10-20 02:20:34
$pdf->Text($mid_x-$pdf->GetStringWidth($text)/2,$y,$text);
$pdf->Text($mid_x-$pdf->GetStringWidth($text)/2,$y,$text);
黒涩兲箜 2024-10-20 02:20:34
            global $title;

            
            // Calculate width of text and position
            $w = $this->GetStringWidth($title)+6;
            $this->SetX((210-$w)/2);
            
        
            // Line break
            $this->Ln(10);

         
            $title = 'YOUR TEXT HERE';
            $this->SetTitle($title);
            $this->SetTextColor(0,0, 0);
            $this->SetFont('Arial','',17);
            $this->SetX(((210-$w)/4),(-50));
            $this->Cell(10, 20, $title);
            global $title;

            
            // Calculate width of text and position
            $w = $this->GetStringWidth($title)+6;
            $this->SetX((210-$w)/2);
            
        
            // Line break
            $this->Ln(10);

         
            $title = 'YOUR TEXT HERE';
            $this->SetTitle($title);
            $this->SetTextColor(0,0, 0);
            $this->SetFont('Arial','',17);
            $this->SetX(((210-$w)/4),(-50));
            $this->Cell(10, 20, $title);
心房的律动 2024-10-20 02:20:34

这对我有用

$mid_x = $pdf->GetPageWidth() / 2;
$text = $userName;
$pdf->Text($mid_x - ($pdf->GetStringWidth($text) / 2),{height}, $text);

This worked for me

$mid_x = $pdf->GetPageWidth() / 2;
$text = $userName;
$pdf->Text($mid_x - ($pdf->GetStringWidth($text) / 2),{height}, $text);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文