将文本与MPDF结盟
我正在使用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
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两个选择:
增加WriteText的第一个参数,直到文本写在所需区域的中心为止。这要么需要猜测文本和区域的宽度,要么对其进行计算。
使用另一种编写文本的方法。使用html/css或 multicell()具有与指定边界内的文本相关的参数。
You have two options:
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.
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.