I am using TCPDF and specifically the ImageSVG() function to put some text in a box. I am attempting to make it right justified, but I can’t seem to get it right. I also need it to stretch the text inside so that it fits the containing rectangle. So far I have this code:
$pdf->ImageSVG('@<svg width="'.$line4_w.'px" height="'.$line4_h.'px" version="1.1"
viewBox="0 0 '.$line4_w.' '.$line4_h.'" preserveAspectRatio="none"
xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="'.$line4_w.'" height="'.$line4_h.'"
fill="'.$bgcolor.'" />
<!-- A text string that spans most of the viewport -->
<text x="40" y="50" font-size="40" font-family="Verdana" style="fill:'.$color_select_text_main.'" >'.$content.'</text>
</svg>', $x=$line4_x+$text_x, $y=$line4_y, 0, 0, $svgLink = '', $svgAlign = 'R', $svgPalign = '', $svgBorder = 0, $svgFits = true);
The width and the Height values are variable, and so is the content string.
I have used the code from here as a starting point:
http://www.w3.org/TR/SVG/coords.html#ExampleViewBox
But my problem is basically when I change the string length of $content to deliberately overflow the container, the text isn’t shrunk at all, and the remaining text is just cut off.
Regarding the justification, I have tried to use the text-anchor attribute (of the text element), setting it to end, and it basically seemed to just put it completely outside of the viewport.
What am I doing wrong?
I’m pretty sure that my solution isn’t the most efficient, but I abandoned this approach, made the image with ImageMagick and then just used the Image() capability of TCPDF.
ImageMagick’s convert and label functionality is really capable of doing more than what I need for the positioning and rendering of the text. Not sure if this question is worth keeping around, but perhaps it will help someone in the future.