PDF text replace alignment issue



We are replacing the text in the PDF, when we do this there is an alignment issue.
We are replacing text in multiple pages at multiple locations, locations are not fixed.




Thanks for contacting support.

Would you please share your sample PDF document along with a sample code snippet, which you are using to replace the text. We will test the scenario in our environment and address it accordingly.


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];
//dot was added
//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

                    SqlCommand com1 = new SqlCommand("spGetMaster", con);
                    com1.CommandType = CommandType.StoredProcedure;
                    com1.Parameters.Add("@masked", SqlDbType.VarChar).Value = sub1;
                    SqlDataReader reader = com1.ExecuteReader();
                    if (reader.HasRows)
                        //update text and other properties
                        CustName = reader["de_masked"].ToString();
                        //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;
                            SqlDataReader reader1 = com.ExecuteReader();
                            //update text and other properties
                            string CustName1 = reader1["de_masked"].ToString();
                            textFragment.Text = CustName1;
                        //setting password to pdf
                        SqlCommand cmd1 = new SqlCommand("spGetMaster", con);
                        cmd1.CommandType = CommandType.StoredProcedure;
                        cmd1.Parameters.Add("masked", SqlDbType.VarChar).Value = sub1;
                        SqlDataReader rd = cmd1.ExecuteReader();
                        string pass = rd["pdfpassword"].ToString();
                        custEmail = rd["Email"].ToString();
                        ccemail = rd["ccemail"].ToString();
                        pdfDocument.Encrypt(pass, "", 0, CryptoAlgorithm.RC4x128);
                        newfilename = i + ".pdf";
                        pdfDocument.Save(destination + @"\" + newfilename);

HSBC SA DPM156 Standard Valuation Pack 31 Mar 2017 (English).PDF (233.5 KB)



Thanks for sharing the code snippet and sample PDF.

We have noticed that the code you have shared contains Database calls in it from where you are getting values to be replaced with original content. However, in order to simplify the scenario, could you just share only text which you want to replace and the values with which you want original text to be replaced. We will test the scenario in our environment and address it accordingly.



I want to replace “HSBC SA DPM156” to name like “Resemble Systems”

Text replace issue overwrite & print locked


Thanks for sharing details.

We have tested the scenario using Aspose.PDF for .NET 18.5 with following code snippet and were unable to notice alignment issue. For your reference, an output PDF document is also attached.

Document doc = new Document(dataDir + "HSBC SA DPM156 Standard Valuation Pack 31 Mar 2017 (English).pdf");
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"HSBC SA DPM156");
textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction =
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection)
  textFragment.Text = @"Resemble Systems";
doc.Save(dataDir + "DocOutput.replaced.pdf");

DocOutput.replaced.pdf (286.3 KB)

Would you please try the scenario using latest version of the API and in case you still face any issue, please share a sample console application, able to reproduce the issue. We will again test the scenario in our environment and address it accordingly.


There are alignment issue kindly check page number 3.



Thanks for writing back.

We were able to notice the mentioned issue in output PDF document. Hence, for the sake of correction, we have logged it as PDFNET-44739 in our issue tracking system. We will further look into the details of the issue and keep you posted with the status of its rectification. Please be patient and spare us little time.

We are sorry for the inconvenience.



Could you please update us regarding this issue ?, Its been quite a time now.



Thanks for your inquiry.

I am afraid that earlier logged issue has not been yet resolved. Since, the issue has been logged under free support model, it will be investigated on first come first serve basis. There are other pending issues in the queue as well, which were logged prior to your issue. As soon as we have some definite updates regarding resolution of your issue, we will let you know. Please spare us little time.

We are sorry for the inconvenience.


Is there any update yet?


We need to make this particular issue as high priority, What we can do it about it ?
I hope you will do the needful.




Thanks for your inquiry.

I am afraid that earlier logged issue is not yet resolved, due to other pending issues in the queue.

At the moment, the issue has low priority as it has been logged under free support model, where issues are resolved on first come first serve basis. I am afraid to share that resolution of the issue in this mode of support may take months and depends upon how long is the queue of pending issues awaiting to be resolved.

In case you need your issue to be resolved on urgent basis, you can please consider subscribing to paid support, where issues are resolved on high priority. In case of any further updates, regarding issue resolution, we will let you know once we have some. Please spare us little time.

We are sorry for the inconvenience.


Could you please help me with the pricing of paid support as i am unable to find it anywhere on your website.



You may please contact our sales team by posting an inquiry in Aspose.Purchase forums. You will definitely be provided with required information.