public void EscapeUri(string uri, string result, bool isEscaped) { //ExStart //ExFor:PdfSaveOptions.EscapeUri //ExSummary: Shows how to escape hyperlinks or not in the document. DocumentBuilder builder = new DocumentBuilder(); builder.InsertHyperlink("Testlink", uri, false); // Set this property to false if you are sure that hyperlinks in document's model are already escaped PdfSaveOptions options = new PdfSaveOptions(); options.EscapeUri = isEscaped; builder.Document.Save(MyDir + @"\Artifacts\PdfSaveOptions.EscapedUri Out.pdf", options); //ExEnd Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(MyDir + @"\Artifacts\PdfSaveOptions.EscapedUri Out.pdf"); // get first page Page page = pdfDocument.Pages[1]; // get the first link annotation LinkAnnotation linkAnnot = (LinkAnnotation)page.Annotations[1]; GoToURIAction action = (GoToURIAction)linkAnnot.Action; string uriText = action.URI; Assert.AreEqual(result, uriText); //ExEnd }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); Document doc = new Document(dataDir + "SampleHtmlFile.html", new HtmlLoadOptions()); doc.Save(new MemoryStream()); foreach (Annotation a in doc.Pages[1].Annotations) { if (a.AnnotationType == AnnotationType.Link) { LinkAnnotation la = (LinkAnnotation)a; if (la.Action is GoToURIAction) { GoToURIAction gta = (GoToURIAction)la.Action; gta.URI = ""; TextFragmentAbsorber tfa = new TextFragmentAbsorber(); tfa.TextSearchOptions = new TextSearchOptions(a.Rect); doc.Pages[a.PageIndex].Accept(tfa); foreach (TextFragment tf in tfa.TextFragments) { tf.TextState.Underline = false; tf.TextState.ForegroundColor = Color.Black; } } doc.Pages[a.PageIndex].Annotations.Delete(a); } } doc.Save(dataDir + "RemoveHyperlinksFromText_out.pdf"); // ExEnd:1 }