If you want to access the client side JavaScript API of the PDF web viewer, then subscribing to body.load may not work because not all necessary resources have been loaded yet. In this case it is better to use the ASP.NET AJAX provided Sys.Application.load event.
The following code snippet demonstrates how to use this method:
<head runat="server">
<script type="text/javascript" language="javascript">
Sys.Application.add_load(function () {
showDocInfo();
});
function showDocInfo() {
var viewer = $find('pdfViewer1');
if (viewer) {
var doc = viewer.get_document();
if (!doc.IsValid) {
alert("No document loaded.");
}
else {
alert(
"Title: " + doc.DocumentInfo.Title +
"\nSubject: " + doc.DocumentInfo.Subject +
"\nKeywords: " + doc.DocumentInfo.Keywords +
"\nAuthor: " + doc.DocumentInfo.Author +
"\nCreator: " + doc.DocumentInfo.Creator +
"\n\nPages: " + doc.Pages.length);
}
}
}
</script>
</head> 1 <head runat="server">
2 <script type="text/javascript" language="javascript">
3 Sys.Application.add_load(function () {
4 showDocInfo();
5 });
6
7 function showDocInfo() {
8 var viewer = $find('pdfViewer1');
9 if (viewer) {
10 var doc = viewer.get_document();
11 if (!doc.IsValid) {
12 alert("No document loaded.");
13 }
14 else {
15 alert(
16 "Title: " + doc.DocumentInfo.Title +
17 "\nSubject: " + doc.DocumentInfo.Subject +
18 "\nKeywords: " + doc.DocumentInfo.Keywords +
19 "\nAuthor: " + doc.DocumentInfo.Author +
20 "\nCreator: " + doc.DocumentInfo.Creator +
21 "\n\nPages: " + doc.Pages.length);
22 }
23 }
24 }
25 </script>
26 </head>