将文本与MPDF结盟

发布于 2025-02-11 09:26:30 字数 537 浏览 1 评论 0 原文

我正在使用mpdf ,但我并没有解决如何将文本集中。目前的格式是L-TO-R。我该如何居中?

<?php
use setasign\Fpdi\Fpdi;

require_once __DIR__ . '/vendor/autoload.php';

require_once('FPDI/autoload.php');
require_once('fpdf/fpdf.php'); 
require_once('FPDI/Fpdi.php'); 

$pdf = new \Mpdf\Mpdf();

$pdf->AddPage(); 

$pdf->setSourceFile('PDF/Sample.pdf'); 

$pdf->WriteText(20, 20, "This is a text");

//rest of code
?>

I am using WriteText() from mPDF https://mpdf.github.io/reference/mpdf-functions/writetext.html but I am not getting around of how to center the text. Currently the format is L-to-R. How do I Center it?

<?php
use setasign\Fpdi\Fpdi;

require_once __DIR__ . '/vendor/autoload.php';

require_once('FPDI/autoload.php');
require_once('fpdf/fpdf.php'); 
require_once('FPDI/Fpdi.php'); 

$pdf = new \Mpdf\Mpdf();

$pdf->AddPage(); 

$pdf->setSourceFile('PDF/Sample.pdf'); 

$pdf->WriteText(20, 20, "This is a text");

//rest of code
?>

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

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

发布评论

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

评论(1

旧竹 2025-02-18 09:26:30

您有两个选择:

  1. 增加WriteText的第一个参数,直到文本写在所需区域的中心为止。这要么需要猜测文本和区域的宽度,要么对其进行计算。

  2. 使用另一种编写文本的方法。使用html/css或 multicell()具有与指定边界内的文本相关的参数。

You have two options:

  1. Increase the first parameter of WriteText until you text is written in the center of the area you want. This either requires to guess the width of the text and the area, or calculating it.

  2. Use another method of writing text. Either use HTML/CSS or WriteCell() or MultiCell() which have a parameter to align text inside a specified boundary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文