RAD PDF - PDF Viewer & Editor for ASP.NET
Feature Overview Live Demo Download Support Pricing & Purchasing Contact Us

RAD PDF - Interactive Demonstrations

Basic Demo | Customized PDF Viewer | Integration | PDF Document Editor | PDF Form Filler
View Source
In this example, not only have we customized the RAD PDF interface with our own controls, but we have also setup several listeners to interact with events raised in RAD PDF (such as save). When the save button is clicked, our code will prompt you, asking if you would like the entire page to PostBack and update a label with the saved PDF size. When the page is changed, our code updates the displayed page number.

RAD PDF Sample Source Files

Default.aspx

<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RAD PDF Sample</title>
    <script type="text/javascript">
        var api = null;
        
        function showViewInformation(view)
        {
            //show page information
            document.getElementById("pageInformation").innerHTML = "Page " + view.page + " of " + api.getPageCount();
        }
        
        function initRadPdf()
        {
            //get id
            var id = "<%= PdfWebControl1.ClientID%>";
            
            //get api instance
            api = new PdfWebControlApi(id);
            
            //attach listeners
            api.addEventListener(
                "viewChanged", 
                function(evt) {
                    //show new view information
                    showViewInformation(evt.view);
                }
                );
            api.addEventListener(
                "printing", 
                function(evt) {
                    //to cancel printing, we would return false or set evt.cancel = true
                    return true;
                });
            api.addEventListener(
                "saved",
                function(evt) {
                    if (window.confirm("Save completed. Do PostBack?")) {
                        __doPostBack(id, "");
                    }
                });
                
            //initially show view information
            showViewInformation(api.getView());
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align:center;">
        <asp:Label ID="PdfSize" RunAt="server" />
    </div>
    <div style="text-align:center;">
        <button onclick="if(api){api.save();}return false;">Save</button>
        <button onclick="if(api){api.download();}return false;">Download</button>
        <button onclick="if(api){api.print();}return false;">Print</button>
    </div>
    <div>
        <radPdf:PdfWebControl ID="PdfWebControl1" RunAt="server"
            Height="600px" 
            Width="100%" 
            OnClientLoad="initRadPdf();" 
            HideBookmarks="True"
            HideBottomBar="True"
            HideDownloadButton="True"
            HideSearchText="True"
            HideSideBar="True"
            HideThumbnails="True"
            HideToolsTabs="True"
            HideTopBar="True"
            />
    </div>
    <div style="text-align:center;">
        <button onclick="if(api){api.setView( { 'page' : api.getView().page - 1 } );}return false;">Previous Page</button>
        <span id="pageInformation" style="padding:0px 5px;"></span>
        <button onclick="if(api){api.setView( { 'page' : api.getView().page + 1 } );}return false;">Next Page</button>
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using RadPdf.Data.Document;

partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            //Get PDF as byte array from file (or database, browser upload, remote storage, etc)
            byte[] pdfData = System.IO.File.ReadAllBytes(@"C:\demo.pdf");
            
            //Load PDF byte array into RAD PDF
            this.PdfWebControl1.CreateDocument("Document Name", pdfData,
              PdfDocumentSettings.IsReadOnlyExceptFormFields);
        }
        else
        {
            this.PdfSize.Text = "PDF size on last save: " + this.PdfWebControl1.GetPdf().Length.ToString() + " bytes";
        }
    }
}

Default.aspx

<%@ Page Language="VB" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RAD PDF Sample</title>
    <script type="text/javascript">
        var api = null;
        
        function showViewInformation(view)
        {
            //show page information
            document.getElementById("pageInformation").innerHTML = "Page " + view.page + " of " + api.getPageCount();
        }
        
        function initRadPdf()
        {
            //get id
            var id = "<%= PdfWebControl1.ClientID%>";
            
            //get api instance
            api = new PdfWebControlApi(id);
            
            //attach listeners
            api.addEventListener(
                "viewChanged", 
                function(evt) {
                    //show new view information
                    showViewInformation(evt.view);
                }
                );
            api.addEventListener(
                "printing", 
                function(evt) {
                    //to cancel printing, we would return false or set evt.cancel = true
                    return true;
                });
            api.addEventListener(
                "saved",
                function(evt) {
                    if (window.confirm("Save completed. Do PostBack?")) {
                        __doPostBack(id, "");
                    }
                });
                
            //initially show view information
            showViewInformation(api.getView());
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align:center;">
        <asp:Label ID="PdfSize" RunAt="server" />
    </div>
    <div style="text-align:center;">
        <button onclick="if(api){api.save();}return false;">Save</button>
        <button onclick="if(api){api.download();}return false;">Download</button>
        <button onclick="if(api){api.print();}return false;">Print</button>
    </div>
    <div>
        <radPdf:PdfWebControl ID="PdfWebControl1" RunAt="server"
            Height="600px" 
            Width="100%" 
            OnClientLoad="initRadPdf();" 
            HideBookmarks="True"
            HideBottomBar="True"
            HideDownloadButton="True"
            HideSearchText="True"
            HideSideBar="True"
            HideThumbnails="True"
            HideToolsTabs="True"
            HideTopBar="True"
            />
    </div>
    <div style="text-align:center;">
        <button onclick="if(api){api.setView( { 'page' : api.getView().page - 1 } );}return false;">Previous Page</button>
        <span id="pageInformation" style="padding:0px 5px;"></span>
        <button onclick="if(api){api.setView( { 'page' : api.getView().page + 1 } );}return false;">Next Page</button>
    </div>
    </form>
</body>
</html>

Default.aspx.vb

Option Explicit On
Option Strict On

Imports RadPdf.Data.Document

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            'Get PDF as byte array from file (or database, browser upload, remote storage, etc)
            Dim pdfData As Byte() = System.IO.File.ReadAllBytes("C:\demo.pdf")

            'Load PDF byte array into RAD PDF
            Me.PdfWebControl1.CreateDocument("Document Name", pdfData, _
              PdfDocumentSettings.IsReadOnlyExceptFormFields)
        Else

            Me.PdfSize.Text = "PDF size on last save: " & Me.PdfWebControl1.GetPdf().Length.ToString() & " bytes"
        End If
    End Sub
End Class
Terms of Use | Privacy
RAD PDF & PDFescape are Red Software products - ©2007-2012 Red Software