Function to
validate pdf document for Hyperlinks, Actions using aspose.pdf, C#, DotNet
#region "Description"
/*
Method given in blog can be used to
determine if a pdf document contains or not
1) Add
reference to Aspose.Pdf dll in your
project
2) Add
reference to Aspose.Pdf namespace in
your class
e.g. (using Aspose.Pdf;)
3) Add
method isHyperLinkExistInPdf() in
your class
Aspose.Pdf Reference: http://www.aspose.com/.net/total-component.aspx
*/
#endregion
#region "Method"
/// <summary>
/// returns True if Pdf document stream
contains any hyperlink
/// </summary>
/// <param
name="streamPdfDoc">pdf
document stream</param>
/// <returns></returns>
public bool
isHyperLinkExistInPdf(Stream streamPdfDoc)
{
bool
bIsHyperLinkExistInPDF = false;
Page
page = null;
Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationSelector selector = null;
IList
list = null;
try
{
streamPdfDoc.Position = 0;
Aspose.Pdf.Document
pdfDocument = new Aspose.Pdf.Document(streamPdfDoc);
//extract
actions
for (int pages = 1; pages <= pdfDocument.Pages.Count;
pages++)
{
page = pdfDocument.Pages[pages];
selector = new
Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationSelector(new Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation(page, Aspose.Pdf.Rectangle.Trivial));
page.Accept(selector);
list = selector.Selected;
if
(list.Count > 0)
{
bIsHyperLinkExistInPDF = true;
break;
}
}
return
bIsHyperLinkExistInPDF;
}
catch
{
}
return
bIsHyperLinkExistInPDF;
}
#endregion
No comments:
Post a Comment