2

我正在使用 TCPDF 创建 PDF 文档。我想在标题中使用小型大写字母,但我失败了。

这是我的标题代码:

版本 1

<?php
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file ='image/pacra.jpg';
        $this->Image($image_file, 100, 05, 20);
        // Set font
        $this->SetFont('times', 15);

        // Title
      $this->Cell(0,57, 'Trying To Use Small Caps', 0, false, 'C', 0, '', 0, false);
        $this->Line(10,32,200,32);

版本 2

<?php
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file ='image/pacra.jpg';
        $this->Image($image_file, 100, 05, 20);
        // Set font
        $this->SetFont('times', 15);
        $str = 'Trying To Use Small Caps';
        $str = preg_replace("/([a-z]+)/e","strtoupper('<small>\\1</small>')",$str);
        $str= $this->writeHTML($str);

此代码有效,但我想设置文本的 XY 轴。

4

2 回答 2

1

雅虎……!!!我解决了我的问题。

    <?php
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file ='image/pacra.jpg';
        $this->Image($image_file, 100, 05, 20);
        // Set font
        $this->SetFont('times','B');
        $this->SetFontSize(16);
        //$this->SetTextColor(0,63,127);
        $this->SetXY(52,25);
        $str = 'Tying to Use Small Caps';
        $str = preg_replace("/([a-z]+)/e","strtoupper('<small>\\1</small>')",$str);
        $str= $this->writeHTML($str);
于 2015-06-17T13:32:56.800 回答
0

要更改字体,您需要添加字体样式。
以此为例。

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
于 2015-06-17T13:11:12.400 回答