title: how to dynamically render a textbox value in asp.net web page into the same position in a PDF using iTextSharp?
body: <p>How to dynamically render a textbox value in Asp.net web page into PDF using iTextSharp?</p>
  
  <p>The text have to be placed in the PDF in the same position as the textbox in the web page, as the number of textboxes vary in different scenarios because the textboxes are contained in different FormViews. There are many FormViews in the page &amp; only some FormViews will be datbound in some cases. So we cant set a position for each textbox. The position should be same as that in the web page.</p>
  
  <p>I have done like this:</p>
  
  <pre><code>        Dim TextBox5 As TextBox = DirectCast(FormView2.FindControl("TextBox5"), TextBox)
  
          Dim htmlarraylist As List(Of IElement) = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(New StringReader(TextBox5.Text), Nothing)
  
          For Each element As IElement In htmlarraylist
  
              document.Add(element)
  
          Next
  </code></pre>
  
  <p>But the textbox will be added to the last of the PDF document only.</p>
  
  <p>If it is to be placed at an absolute position in PDF, it can be done like this:</p>
  
  <pre><code>        Dim cb As PdfContentByte = writer.DirectContent
  
          cb.BeginText()
  
          Dim TextBox5 As TextBox = DirectCast(FormView2.FindControl("TextBox5"), TextBox)
  
          Dim text As String = TextBox5.Text
  
          cb.SetFontAndSize(bf, 8)
  
          cb.ShowTextAligned(1, text, 122, 474, 0)
  
          cb.EndText()
  </code></pre>
  
  <p>But both of these cant be done in my case. Please help.</p>