Hi
Is there a way to iterate text segment and disable hyperlink in PDF document?
Thanks
Hi Oren,
Document doc = new Document(“input.pdf”);<o:p></o:p>
// get the first link annotation from first page of document<o:p></o:p>
LinkAnnotation linkAnnot = (LinkAnnotation)doc.Pages[1].Annotations[1];<o:p></o:p>
if (linkAnnot.Action is GoToURIAction)<o:p></o:p>
{<o:p></o:p>
// Modification link: change link URI<o:p></o:p>
GoToURIAction goToAction = (GoToURIAction)linkAnnot.Action;<o:p></o:p>
// specify the URI for link object<o:p></o:p>
goToAction.URI = “”;<o:p></o:p>
// save the document with updated link<o:p></o:p>
// Search the text under the annotation<o:p></o:p>
TextFragmentAbsorber ta = new TextFragmentAbsorber();<o:p></o:p>
Aspose.Pdf.Rectangle rect = linkAnnot.Rect;<o:p></o:p>
rect.LLX -= 10;<o:p></o:p>
rect.LLY -= 10;<o:p></o:p>
rect.URX += 10;<o:p></o:p>
rect.URY += 10;<o:p></o:p>
ta.TextSearchOptions = new TextSearchOptions(rect);<o:p></o:p>
ta.Visit(doc.Pages[1]);<o:p></o:p>
// Change color and text.<o:p></o:p>
foreach (TextFragment tf in ta.TextFragments)<o:p></o:p>
{<o:p></o:p>
tf.TextState.ForegroundColor = Aspose.Pdf.Color.Red;<o:p></o:p>
tf.Text = “Click Here”;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
doc.Save(“output.pdf”);
Please feel free to contact us for any further assistance.
Best Regards,
Hi
Thank you very much for the example.
How can I disable links that are generated from a text such as:
http://edition.cnn.com . If the text has a pattern of link (e.g. http, www…) the PDF Acrobat link the text.
Thanks
Hi Oren,
any update on this issue?
Hi Camille,
Hello,
is there any news on this issue?
Thanks,
Hi Camille,
// load the PDF file<o:p></o:p>
Document doc = new Document(myDir+"Hyperlink.pdf");
//create TextAbsorber object to find all the phrases matching the regular expression for hyperlink of e-mail
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|])|((([a-zA-Z]|[0-9])|([-]|[_]|[.]))+[@](([a-zA-Z0-9])|([-])){2,63}[.](([a-zA-Z0-9]){2,63})+$)");
//set text search option to specify regular expression usage
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions=textSearchOptions;
int pageNum = 1;
//accept the absorber for all the pages
Aspose.Pdf.Page page = doc.Pages[pageNum];
page.Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
LinkAnnotation linkAnnot = new LinkAnnotation(page, textFragment.Rectangle);
linkAnnot.Border=new Border(linkAnnot);
linkAnnot.Border.Width=0;
page.Annotations.Add(linkAnnot);
}
doc.Save(myDir+"HyperlinkRemoved.pdf");