<%@ 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> </head> <body> <form id="form1" runat="server"> <div> <asp:Panel ID="UploadPanel" Runat="Server" HorizontalAlign="Center"> <asp:Label Text="Choose File:" Runat="Server" AssociatedControlID="UploadControl" /> <asp:FileUpload ID="UploadControl" Runat="Server" /> <asp:Button ID="UploadButton" Runat="Server" Text="Upload" /> <div> <asp:Literal ID="UploadMessage" Runat="Server" Text="Please choose a file up to 10 MB. The first 100 pages will be loaded." /> </div> </asp:Panel> <radPdf:PdfWebControl ID="PdfWebControl1" runat="server" height="600px" width="100%" MaxPdfPages="100" ThrowMaxPagesException="false" /> </div> </form> </body> </html>
using System; partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack && this.UploadControl.HasFile) { //Get PDF as byte array from upload byte[] pdfData = this.UploadControl.FileBytes; //Check file size (up to 10 MB) if (pdfData.Length <= 10485760) { try { //Load PDF byte array into RAD PDF this.PdfWebControl1.CreateDocument(this.UploadControl.FileName, pdfData); } catch { this.UploadMessage.Text = "PDF file could not be loaded."; } } else { this.UploadMessage.Text = "File is too large. Please choose a file no larger than 1 MB."; } } //Check if PDF is loaded into RAD PDF if (this.PdfWebControl1.DocumentLoaded) { //File is loaded, hide the upload panel this.UploadPanel.Visible = false; } else { //No file was uploaded, do not show RAD PDF this.PdfWebControl1.Visible = false; } } }
<%@ 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> </head> <body> <form id="form1" runat="server"> <div> <asp:Panel ID="UploadPanel" Runat="Server" HorizontalAlign="Center"> <asp:Label Text="Choose File:" Runat="Server" AssociatedControlID="UploadControl" /> <asp:FileUpload ID="UploadControl" Runat="Server" /> <asp:Button ID="UploadButton" Runat="Server" Text="Upload" /> <div> <asp:Literal ID="UploadMessage" Runat="Server" Text="Please choose a file up to 10 MB. The first 100 pages will be loaded." /> </div> </asp:Panel> <radPdf:PdfWebControl ID="PdfWebControl1" runat="server" height="600px" width="100%" MaxPdfPages="100" ThrowMaxPagesException="false" /> </div> </form> </body> </html>
Option Explicit On Option Strict On 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 IsPostBack And Me.UploadControl.HasFile Then 'Get PDF as byte array from upload Dim pdfData As Byte() = Me.UploadControl.FileBytes 'Check file size (up to 1 MB) If pdfData.Length <= 1048576 Then Try 'Load PDF byte array into RAD PDF Me.PdfWebControl1.CreateDocument(Me.UploadControl.FileName, pdfData) Catch Me.UploadMessage.Text = "PDF file could not be loaded." End Try Else Me.UploadMessage.Text = "File is too large. Please choose a file no larger than 1 MB." End If End If 'Check if PDF is loaded into RAD PDF If Me.PdfWebControl1.DocumentLoaded Then 'File is loaded, hide the upload panel Me.UploadPanel.Visible = False Else 'No file was uploaded, do not show RAD PDF Me.PdfWebControl1.Visible = False End If End Sub End Class