Aspose PDF alignment issue on PDF edit

We have purchase the license for one of our client and i am replacing text in PDF at multiple location in multiple pages, when i do so in one page there is an alignment issue.
For reference kindly check the attached image and code

static void Main(string[] args)
{
License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand(“spconfiguration”, con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
source = dr[“FTPURLSource”].ToString();
destination = dr[“FTPURLDestination”].ToString();
dr.Close();
con.Close();
string mydir = source + @"";
string[] myfiles = Directory.GetFiles(mydir + “”).Select(Path.GetFileName).ToArray();
foreach (var i in myfiles)
{
if (i.Contains(“HSBC”))
{
string sub = "HSBC SA “+i.Split(’ ‘, ‘.’)[2] ;
string sub1 = i.Split(’ ', ’ ‘)[2];
//string sub = str.Substring(8, 6);
//string sub1 = rowString.Substring(0, 3);
//string sub = rowString.Replace(’”’, ’ ').Trim();
if (sub.Contains(“DPM”))
{
Document pdfDocument = new Document(mydir + i);
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(sub);
//accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);

                    SqlCommand com1 = new SqlCommand("spGetMaster", con);
                    con.Open();
                    com1.CommandType = CommandType.StoredProcedure;
                    com1.Parameters.Add("@masked", SqlDbType.VarChar).Value = sub1;
                    com1.ExecuteNonQuery();
                    SqlDataReader reader = com1.ExecuteReader();
                    reader.Read();
                    if (reader.HasRows)
                    {
                        //update text and other properties
                        CustName = reader["de_masked"].ToString();
                        reader.Close();
                        //get the extracted text fragments
                        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
                        //loop through the fragments             
                        foreach (TextFragment textFragment in textFragmentCollection)
                        {
                            //string str = "select de_masked from master where Masked='" + sub.ToString() + "'";
                            SqlCommand com = new SqlCommand("spGetMaster", con);
                            com.CommandType = CommandType.StoredProcedure;
                            com.Parameters.Add("@masked", SqlDbType.VarChar).Value = sub1;
                            com.ExecuteNonQuery();
                            SqlDataReader reader1 = com.ExecuteReader();
                            reader1.Read();
                            //update text and other properties
                            string CustName1 = reader1["de_masked"].ToString();
                            textFragment.Text = CustName1;
                            reader1.Close();
                        }
                        //setting password to pdf
                        SqlCommand cmd1 = new SqlCommand("spGetMaster", con);
                        cmd1.CommandType = CommandType.StoredProcedure;
                        cmd1.Parameters.Add("masked", SqlDbType.VarChar).Value = sub1;
                        cmd1.ExecuteNonQuery();
                        SqlDataReader rd = cmd1.ExecuteReader();
                        rd.Read();
                        string pass = rd["pdfpassword"].ToString();
                        custEmail = rd["Email"].ToString();
                        ccemail = rd["ccemail"].ToString();
                        pdfDocument.Encrypt(pass, "", 0, CryptoAlgorithm.RC4x128);
                        rd.Close();
                        newfilename = i + ".pdf";
                        pdfDocument.Save(destination + @"\" + newfilename);
                        sendEmail();
                        insertdata();
                        //setpass();
                        string oldfile = mydir + i;
                        File.Delete(oldfile);

                    }

code.JPG (14.9 KB)

@shaikh,

Please send us your source PDF and simplify the code to the problematic text replacement. We will investigate your scenario and share our findings with you.