0

I'm using TCPDF to create PDF documents and need to render a superscript character without using HTML as the multicell option. No HTML because I need to align the words vertically at the bottom of the cell which doesn't work when the cell has HTML endabled.

Any ideas?

[Edit]

According to Jakuje's hint, I'm using this code to convert the unicode-characters:

$unicodeTable = array('<sup>1</sup>'=>'U+00B9', '<sup>2</sup>'=>'U+00B2', '<sup>3</sup>'=>'U+00B3', '<sup>4</sup>'=>'U+2074', '<sup>5</sup>'=>'U+2075');

function replace_unicode_escape_sequence($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}

function unicode_chr ($chr) {
    $x = explode("+", $chr);
    $str = "\u".end($x);
    return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
}

foreach($unicodeTable as $uKey=>$uValue){
    $text = str_replace($uKey, unicode_chr($uValue), $text);
}

This works in pure php/HTML - but when I use this code with TCPDF, all I get is the unicode-code (e.g. \u00B9)

Swissdude
  • 3,486
  • 3
  • 35
  • 68

2 Answers2

1

You can use UTF8 superscript, if it is some "common" letter, such as

x² or xⁿ
Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • I tried that. When I do it in plain HTML in works. Using TCPDF I get the unicode-code, though (like \u00B9). See my edited question for the code. – Swissdude Dec 29 '16 at 09:56
1

I found the following works with TCPDF

json_decode('"\u00B3"') // for PHP 5.x

"\u{00B2}" // for PHP 7.x

Based on this stack overflow article Unicode character in PHP string

TCPDF 6.2.13 with PHP7.1.4