logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
oberon232  
#1 Posted : Friday, March 8, 2019 4:05:40 PM(UTC)
oberon232

Rank: Newbie

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 6
United States
Location: FL

Thanks: 1 times
I have a page that I've marked with text.
I know the position on the page and what the text says.
Now I want to remove that text, not just hide it but remove it from the page.
Is there a way to do this?
Paul Rayman  
#2 Posted : Sunday, March 10, 2019 7:01:44 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 779

Thanks: 1 times
Was thanked: 97 time(s) in 95 post(s)
you can enumerate page.PageObjects collection, locate and remove the TextObject.
Next you should re-generate page content by calling page.GenerateContent() method.

Code:
using (var doc = PdfDocument.Load(@"d:\test.pdf"))
{
    var page = doc.Pages[0];
    for(int i=page.PageObjects.Count-1; i>=0; i--)
    {
        if (!(page.PageObjects[i] is PdfTextObject))
            continue;
        var obj = page.PageObjects[i] as PdfTextObject;
        if (obj.TextUnicode == "some text")
        {
            page.PageObjects.RemoveAt(i);
            break;
        }
    }
    page.GenerateContent();
    doc.Save(@"d:\test_modified.pdf", SaveFlags.NoIncremental);
}
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.