This technical tip allows developers to get selected link on a page in PDF file using Saaspose.Pdf REST API in your .NET applications. Saaspose.Pdf is a REST API to create, edit & manipulate PDF files. It also convert PDF file to DOC, DOCX, HTML, XPS, TIFF etc. It is platform independent REST API & working with web, desktop, mobile or cloud applications alike. Some important steps for performing this task are to build URI to get selected link on a page, Parse the json string to JObject, Deserializes the JSON to an object and the classes used in this process are given in detail.
Sample Code for Get Selected Link on a Page in PDF File
[C# Code]
//build URI to get selected link on a page
string strURI = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/1/links/1";
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());
Link tempLink = 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 PdfLinkResponse class
public class PdfLinkResponse : BaseResponse
{
public PdfLinkResponse() { }
public Link Link { 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; }
}
[VB.NET Code]
'build URI to get selected link on a page
Dim strURI As String = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/1/links/1"
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())
Dim tempLink As Link = pdfLinkResponse.Link
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())
Overview: Saaspose.Pdf
Saaspose.Pdf is a REST API to create, edit & manipulate PDF files. It also convert PDF file to DOC, DOCX, HTML, XPS, TIFF etc. You can create a new PDF either from scratch or from HTML, XML, template, database, XPS or an image. A PDF file can also be rendered to JPEG, PNG, GIF, BMP, TIFF and many other image formats. It works with any language like .NET, Java, PHP, Ruby, Python and many others. It is platform independent REST API & working with web, desktop, mobile or cloud applications alike.
More about Saaspose.Pdf
- Homepage of Saaspose.Pdf
- More Technical Tips by Saaspose.Pdf about Working with Documents
- More Technical Tips by Saaspose.Pdf
- Ask technical questions/queries from Saaspose Support Team
Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465
No comments:
Post a Comment