How to insert Small Caps in header using tcpdf in php

707 views Asked by At

I am using TCPDF to create PDF documents. I want to use small caps in my header, but I failed.

Here is my header code:

Version 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);

Version 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);

This code is working but I want to set XY axis of text.

2

There are 2 answers

0
AudioBubble On

Yahooo....!!! I Solved my issue.

    <?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);
3
Praveen D On

To change font you need to add font style.
Follow this for example.

// 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);