简体   繁体   中英

Format text controls on pdf using iTextSharp and C#

I have a pdf document where I am filling all the values using the below code.

using(MemoryStream ms = new MemoryStream())
{
  // Fill the PDF with the XFA
  using(PdfStamper stamper = new PdfStamper(oInPDF, ms))
  {
    stamper.Writer.CloseStream = false;
    XfaForm.SetXfa(oXFA, stamper.Reader, stamper.Writer);
 }

 // Code for Flatten the filled PDF.
}

I am trying to draw a box in red around the value displayed to highlight when the values are not in the expected range. I would like to know, how do I locate the position of a control on a pdf page using iTextSharp and C#.

Any help or info on this, much appreciated.

Many Thanks.

Finally managed to draw borders around controls with below code.

XmlDocument newXMLDoc = new XmlDocument();
newXMLDoc.LoadXml(@"<border><edge thickness=""1.3mm""><color value=""0, 0, 255""/></edge></border>");

if (Rs.Rows.Count > 0)
 {
    foreach (DataRow query in Rs.Rows)
     {
        if(isRET)
          {
            if (oXFA.DomDocument.SelectSingleNode("//t:*[@name='" + Rs[0] + "']", oNameSpace) != null)
             {
                XmlNode newNode = 
oXFA.DomDocument.ImportNode(newXMLDoc.SelectSingleNode("border"), true);
oXFA.DomDocument.SelectSingleNode("//t:*[@name='" + Rs[0] + "']", oNameSpace).AppendChild(newNode);
             }
          }
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM