0

I can successfully add text to a pdf and store the object's ID in this way:

int ID = theDoc.AddText(ItemText);

However, when I try to update the item's text on the pdf in the following way, it does not work.

theDoc.SetInfo(ID, ":Text", ItemText);

Here is the documentation on the SetInfo function: http://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/setinfo.htm

The function takes in the pdf object's ID, the type, and the data to be inserted. I believe my error is in the second parameter (type), but I am not sure how I can make the type more descriptive.

Any ideas or input would be awesome.

user1170679
  • 75
  • 1
  • 10

1 Answers1

2

If you are adding the text using AddText then you will get an ID back. To change the text call Doc.Delete on the ID and then add your new text.

In terms of extracting text in existing PDF documents you should be using the TextOperation class. Something like this:

TextOperation op = new TextOperation(theDoc);
op.PageContents.AddPages();
string text = op.GetText();

The text that is returned is the text found on the pages that have been selected - in this case all the pages in the document.

Then you can select bits of the text using the same kind of operation as string.Substring. So if your text was "Hello World!" you could select the Hello bit using something like:

IList<TextFragment> frags = op.Select(0, 5);

The list of TextFragments represents the way that the text is stored in the PDF. So you can get each fragment, find out where in the content stream it is and manipate it as desired.

  • Thanks for the answer! I am wondering though, how I can have my replacement text still use the same text style (font and size) and containing rectangle. Is there a way to obtain this information by object ID? So would it be possible to get that info, delete the text then add the new text with the old object's style and in the same area? Imagine using their example seen here: http://www.abcpdfeditor.com/ except you can edit added text and it is still contained in the same rectangle. – user1170679 Jul 12 '13 at 14:38
  • @OnceUponATimeInTheWest: I have created a rectangle over the existing text. I would like to remove the existing text group/fragment. Does ABCPdf has an option to do that? – CSS Apr 10 '18 at 07:17