title: How to scale text within a fixed rectangle with itext7?
body: <p>I'm trying to make a pdf document with itext7 in c# which should have fixed rectangles containing varying text that should scale within the boundaries of the (invisible) rectangles.</p>
  
  <p>I have tried to find if there's automatic scaling, but so far only found auto-scaling for formfields. Since the pdf will be used for plotting text, formfields are of no use.</p>
  
  <p>Code below is a snippet placing a 'box' with fixed dimensions, where all the text should be shown scaled (on one line)</p>
  
  <pre><code>float fontSize = 22f;
  
  Text lineTxt = new Text("A VERY LONG TEXT SHOULD BE SCALED").SetFont(lineFont).SetFontSize(fontSize);
  
  iText.Kernel.Geom.Rectangle lineTxtRect = new iText.Kernel.Geom.Rectangle(100, posHeight - 200, (float)plotline.producttype_plotmaxwidthpts, (float)plotline.producttype_plotmaxheightpts);
  
  Div lineDiv = new Div();
  lineDiv.SetMaxHeight((float)plotline.producttype_plotmaxheightpts);
  lineDiv.SetWidth((float)plotline.producttype_plotmaxwidthpts);
  lineDiv.SetHeight((float)plotline.producttype_plotmaxheightpts);
  lineDiv.SetVerticalAlignment(VerticalAlignment.MIDDLE);
  lineDiv.SetBorder(new DashedBorder(1));
  
  Paragraph linePara = new Paragraph().Add(lineTxt).
          SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).
          SetBorder(new DottedBorder(1)).
          SetMultipliedLeading(0.7f).
          SetMaxHeight((float)plotline.producttype_plotmaxheightpts).
          SetHeight((float)plotline.producttype_plotmaxheightpts);
  
  lineDiv.Add(linePara);
  
  new Canvas(PageCanvas, pdf, lineTxtRect).Add(lineDiv).SetBorder(new SolidBorder(1f));
  </code></pre>