title: SVG XML Right Justified and Stretched to Fit
body: <p>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:</p>
  
  <pre><code>$pdf-&gt;ImageSVG('@&lt;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"&gt;
    &lt;rect x="0" y="0" width="'.$line4_w.'" height="'.$line4_h.'" 
          fill="'.$bgcolor.'" /&gt;
    &lt;!-- A text string that spans most of the viewport --&gt;
    &lt;text x="40" y="50" font-size="40" font-family="Verdana" style="fill:'.$color_select_text_main.'" &gt;'.$content.'&lt;/text&gt;
  &lt;/svg&gt;', $x=$line4_x+$text_x, $y=$line4_y, 0, 0, $svgLink = '', $svgAlign = 'R', $svgPalign = '', $svgBorder = 0, $svgFits = true);
  </code></pre>
  
  <p>The width and the Height values are variable, and so is the content string.</p>
  
  <p>I have used the code from here as a starting point:</p>
  
  <p><a href="http://www.w3.org/TR/SVG/coords.html#ExampleViewBox" rel="nofollow">http://www.w3.org/TR/SVG/coords.html#ExampleViewBox</a></p>
  
  <p>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. </p>
  
  <p>Regarding the justification, I have tried to use the <code>text-anchor</code> attribute (of the text element), setting it to end, and it basically seemed to just put it completely outside of the viewport.</p>
  
  <p>What am I doing wrong?</p>