How to Replace the NEW Text inplace of old text if I have the coordinates?

116 views
Skip to first unread message

Snehasis Samal

unread,
Aug 1, 2013, 9:19:15 AM8/1/13
to pdfne...@googlegroups.com
Hi,

I am repalcing the Old text with new one "NEWText". But the new PDF does not contain anything but blank in place of old text. But Link annotation is working.

Q:2, Its replacing the first text found, not all the words in all pages? How to replace all words in all pages if the search text found?

TextSearch.ResultCode code = txt_search.Run(ref page_num, ref result_str, ref ambient_string, hlts);

if (code == TextSearch.ResultCode.e_found)
{
//add a link annotation based on the location of the found instance
hlts.Begin(doc);
while (hlts.HasNext())
{
pdftron.PDF.Page cur_page = doc.GetPage(hlts.GetCurrentPageNumber());
double[] quads = hlts.GetCurrentQuads();
int quad_count = quads.Length / 8;
for (int i = 0; i < quad_count; ++i)
{
//assume each quad is an axis-aligned rectangle
int offset = 8 * i;
double x1 = Math.Min(Math.Min(Math.Min(quads[offset + 0], quads[offset + 2]), quads[offset + 4]), quads[offset + 6]);
double x2 = Math.Max(Math.Max(Math.Max(quads[offset + 0], quads[offset + 2]), quads[offset + 4]), quads[offset + 6]);
double y1 = Math.Min(Math.Min(Math.Min(quads[offset + 1], quads[offset + 3]), quads[offset + 5]), quads[offset + 7]);
double y2 = Math.Max(Math.Max(Math.Max(quads[offset + 1], quads[offset + 3]), quads[offset + 5]), quads[offset + 7]);

Rect rectContaningText = new Rect(x1, y1, x2, y2);
ContentReplacer replacer = new ContentReplacer();
string replacement_text = "NEWText";
replacer.AddText(rectContaningText, replacement_text);
replacer.Process(cur_page);


pdftron.PDF.Annots.Link hyper_link = pdftron.PDF.Annots.Link.Create(doc, new Rect(x1, y1, x2, y2), pdftron.PDF.Action.CreateURI(doc, "http://www.pdftron.com"));
hyper_link.RefreshAppearance();
cur_page.AnnotPushBack(hyper_link);

}
hlts.Next();
}
doc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized);

Reply all
Reply to author
Forward
0 new messages