I'm currently building a PDF editor. I have a problemen with implementing the processing of the tags.
I want to allow the following tags: [h1],[h2],[h3],[h4],[h4],[h5],[h6],[strong]
I've build an class with a method called drawText(code below).
The [h1] tag will change the font size and the font weight. As you can see in the code I'm outputting lines of text. Example text line: This is your [strong]boarding pass[/strong], please save this PDF file on your smartphone or tablet and [strong]show it at the gate[/strong].
I'd like to make the text between the [strong] bold. To do this with Zend_PDF I need to set the TTF file with the bold text and then find the current X-coordinate and call $this->pdf()->drawText(text, X-coordinate, Y-coordinate, charset). I've been thinking and trying for hours to write the code which makes this possible(tried using explode, preg_match_all, etc), but I can't get it to work...
I believe I'm not the only one with this problem, and I hope someone has thought about this and can help a little by telling how he or she did it...
Hope to hear from someone and thanks in advance!
/**
* drawSplittedText()
*
* @param array $text
* @return object Application_Plugin_PdfPlugin
*/
public function drawSplittedText(Array $text)
{
// Count the number of rows.
$textRowCount = count($text);
$i = 0;
foreach ($text as $row)
{
// Replace tabs, because they're not outputted properly.
$row = str_replace("\t", ' ', $row);
// If the character encoding of the currrent row not is UTF-8, convert the row characters to UTF-8.
if (($rowEncoding = mb_detect_encoding($row)) != 'UTF-8') {
$row = iconv($rowEncoding, 'UTF-8', $row);
}
// Output row on PDF
$this->pdf()->drawText($row, $this->_defaultMarginleft, $this->currentY, 'UTF-8');
$this->newLine();
++$i;
}
return $this;
}