Aspose PDF - Remove/Add Paragraphs based on conditions while reading Existing PDF

I have 2 Issue around ASPOSE PDF in C#.

I have a Existing PDF with huge data around 18 pages.

  1. I have repaced text in pdf dynamically from C# code for which I have used TextAbsorber. TextAbsorber worked in replacing text but format was missed. When I replaced the text, text is coming out of PDF margins instead of creating new line.
    How do I fix thies issue? How to replace long text in pdf with no formating issues?

  2. I have to remove or add paragraphs in the existing pdf conditonal base. How to play/render with content in existing pdf.

@immoses

Can you please share your sample PDF along with the sample code snippet that you have used to replace the text? We will test the scenario in our environment and address it accordingly.

About your requirements of removing paragraphs against particular condition, can you please share some more details with sample source and expected output PDF? We will look into its feasibility and share our feedback with you.

Here is the code snippet for replacing text in the pdf.

Take any PDF with some text and replace

string filePath = string.Empty;
string root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
filePath = Path.Combine(root, @“Resources\sample.pdf”);

            Document pdfDocument = new Document(filePath);
            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(Constants.UserFirstName);
            pdfDocument.Pages.Accept(textFragmentAbsorber);
            textFragmentAbsorber.TextFragments[1].Text = FirstName;

            textFragmentAbsorber = new TextFragmentAbsorber(Constants.UserLastName);
            pdfDocument.Pages.Accept(textFragmentAbsorber);
            textFragmentAbsorber.TextFragments[1].Text = string.empty;

Not sure how to hide and show paragaraphs in existing pdf.

@immoses

The text replacement with our sample PDFs is working fine at our end. Furthermore, it may not be possible to hide the paragraphs. However, you can find and then set the text to an empty string. In case you are facing some issues, please share your sample PDF with us so that we can investigate the reasons and share our feedback with you.