| This example allows you to get links on a page in PDF file using Saaspose.Pdf REST API in your .NET applications. |
| We're referring to the following common methods to perform general operations: |
Get All Links on a Page in PDF (.NET REST)
| This example allows you to get links on a page in PDF file using Saaspose.Pdf REST API in your .NET applications. |
| We're referring to the following common methods to perform general operations: |
//build URI to get links List<Link> ListLinks = new List<Link>(); int iTotalLinks = GetLinksCount(pageNumber); for (int index = 1; index <= iTotalLinks; index++) { ListLinks.Add(GetLink(pageNumber,index)); } public int GetLinksCount(int pageNumber) { //build URI to get page count string strURI = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/" + pageNumber + "/links"; string signedURI = Sign(strURI); Stream responseStream = ProcessCommand(signedURI, "GET"); StreamReader reader = new StreamReader(responseStream); string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); //Deserializes the JSON to a object. PdfLinksResponse pdfLinksResponse = JsonConvert.DeserializeObject<PdfLinksResponse>(parsedJSON.ToString()); int count = pdfLinksResponse.Links.List.Count; return count; } public Link GetLink(int pageNumber, int attachmentIndex) { //build URI to get page count string strURI = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/" + pageNumber + "/links/"+attachmentIndex; string signedURI = Sign(strURI); Stream responseStream = ProcessCommand(signedURI, "GET"); StreamReader reader = new StreamReader(responseStream); string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); //Deserializes the JSON to a object. PdfLinkResponse pdfLinkResponse = JsonConvert.DeserializeObject<PdfLinkResponse>(parsedJSON.ToString()); return pdfLinkResponse.Link; } //Here is the BaseResponse class public class BaseResponse { public BaseResponse() { } public string Code { get; set; } public string Status { get; set; } } //Here is the PdfLinksResponse class public class PdfLinksResponse : BaseResponse { public PdfLinksEnvelop Links { get; set; } } //Here is the PdfLinkResponse class public class PdfLinkResponse : BaseResponse { public PdfLinkResponse() { } public Link Link { get; set; } } //Here is the PdfLinksEnvelop class public class PdfLinksEnvelop { public List<LinkResponse> Links { get; set; } public List<Link> List { get; set; } } //Here is the LinkResponse class public class LinkResponse { public string Href { get; set; } public string Rel { get; set; } public string Title { get; set; } public string Type { get; set; } } //Here is the Link class public class Link { public Link() { } public LinkActionType ActionType { get; set; } public string Action { get; set; } public LinkHighlightingMode Highlighting { get; set; } public Color Color { get; set; } } //Here is the LinkActionType enum public enum LinkActionType { GoToAction, GoToURIAction, JavascriptAction, LaunchAction, NamedAction, SubmitFormAction } //Here is the LinkHighlightingMode enum public enum LinkHighlightingMode { None, Invert, Outline, Push, Toggle } //Here is the Color class public class Color { public Color() { } public List<LinkResponse> Links { get; set; } public int A { get; set; } public int B { get; set; } public int G { get; set; } public int R { get; set; } }
'build URI to get links Dim ListLinks As New List(Of Link)() Dim iTotalLinks As Integer = GetLinksCount(pageNumber) For index As Integer = 1 To iTotalLinks ListLinks.Add(GetLink(pageNumber, index)) Next Public Function GetLinksCount(pageNumber As Integer) As Integer 'build URI to get page count Dim strURI As String = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/" & pageNumber & "/links" Dim signedURI As String = Sign(strURI) Dim responseStream As Stream = ProcessCommand(signedURI, "GET") Dim reader As New StreamReader(responseStream) Dim strJSON As String = reader.ReadToEnd() 'Parse the json string to JObject Dim parsedJSON As JObject = JObject.Parse(strJSON) 'Deserializes the JSON to a object. Dim pdfLinksResponse As PdfLinksResponse = JsonConvert.DeserializeObject(Of PdfLinksResponse)(parsedJSON.ToString()) Dim count As Integer = pdfLinksResponse.Links.List.Count Return count End Function Public Function GetLink(pageNumber As Integer, attachmentIndex As Integer) As Link 'build URI to get page count Dim strURI As String = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/" & pageNumber & "/links/" & attachmentIndex Dim signedURI As String = Sign(strURI) Dim responseStream As Stream = ProcessCommand(signedURI, "GET") Dim reader As New StreamReader(responseStream) Dim strJSON As String = reader.ReadToEnd() 'Parse the json string to JObject Dim parsedJSON As JObject = JObject.Parse(strJSON) 'Deserializes the JSON to a object. Dim pdfLinkResponse As PdfLinkResponse = JsonConvert.DeserializeObject(Of PdfLinkResponse)(parsedJSON.ToString()) Return pdfLinkResponse.Link End Function
