We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Text replacement causes word alignment problem

Dear Aspose Support Team,

I have some trouble with the textalignment when replacing text in PDF-Files with the TextFragmentAbsorber like you described it in your Example: http://www.aspose.com/docs/display/pdfnet/Replace+Text+in+all+pages+of+PDF+document .

In some cases the lenght of the line changes, in other cases some words or even the whole line are overlapping.

There are only some PDF-Documents where the line alignment is corrupt after the manipulation and since the last update the number has gotten significantly smaller, but it is still an issue.

I coudn’t find any similaritie between all the PDF-Documents which could cause the problem. So I added an example project with some documents and described in the code which document caused which problem. I only found out, that in some cases calling the .Optimize()-method on an document, before editing it, could fix the problem. But not with the documents in the example project.

Best Regards

Hi Bea,

Thanks for contacting support.

I have tested the text replace scenario and have managed to notice that resultant file contents are garbled. For the sake of correction, I have individually logged these problems in our issue tracking system.

  1. Page7FromLeseprobe.pdf - Text replace for this document is logged as PDFNEWNET-40212.
  2. Page9From2011 Sammlung Urteile.pdf - Line contents are not auto adjusted after text replace. Problem is logged as PDFNEWNET-40213.
  3. Page2Fromarbeitsvertrag_2013.pdf - Extra line space in text line after text replace. Problem is logged as PDFNEWNET-40214.
  4. Page3FromLagebericht des BSI zur IT-Sicherheit in Deutschland - Stand November 2014.pdf - Text is overlapping at first edited word. Problem is logged as PDFNEWNET-40215.
  5. Süddeutsche - Hackerangriff auf den Bundestag.pdf - Text is overlapping at first edited word. Problem is logged as PDFNEWNET-40216.
  6. Pressemitteilung CSRD_e.V. IT-Sicherheitsgesetz nicht verfassungskonform.pdf - when two words in the same line are edited the second manipulation is shifted. Problem is separately logged as PDFNEWNET-40217.

We will further look into the details of these problems and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as PDFNET-40215,PDFNET-40213,PDFNET-40214) have been fixed in Aspose.PDF for .NET 19.2.


Thanks for your patience.

In reference to earlier logged ticket (PDFNET-40216), it has been resolved in Aspose.PDF for .NET 19.2. Please take into account that ReplaceAdjustment.None means that no adjustment is performed. It may lead to text overlapping or extra space problem in dependence of the replaced text length.

We recommend to use (default) ReplaceAdjustment.ShiftRestOfLine option for the case of aligned text. The default behavior is also applied if no options are specified.

Please consider the following code snippet.

//Open document
Document doc = new Document(myDir + "40216.pdf");

//Fixes some of the adjustmentproblems with overlapping text during textmanipulation if you call .Optimize() before replacing the text

//Code similar to http://www.aspose.com/docs/display/pdfnet/Replace+Text+in+all+pages+of+PDF+document

//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("beeinträchtigt");            
//accept the absorber for all the pages
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
    //update text
    double oldWidth = textFragment.Rectangle.Width;
    textFragment.Text = ".";
    while (textFragment.Rectangle.Width < oldWidth)
        textFragment.Text += ".";
    //textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Black;
    textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.Yellow;
doc.Save(myDir + "40216_Edited_19.2_default.pdf");

Resultant document was also found OK in our testing process. 40216_Edited_19.2_default.pdf (105.1 KB)

In case of any further assistance, please feel free to let us know.

The issues you have found earlier (filed as PDFNET-40217) have been fixed in Aspose.PDF for .NET 19.3.