using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
// the HTML to PDF converter namespace
using Winnovative;
// the PDF Viewer namespace
using PdfViewer4AspNet;
namespace PdfViewer4AspNetDemo
{
public partial class DisplayPdfBytes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadPageFitModes();
LoadDocumentDisplayModes();
LoadPdfStream();
}
}
protected void btnConvert_Click(object sender, EventArgs e)
{
// apply the viewer settings before loading the PDF from stream
ApplyViewerPreferences();
ApplySecurityOptions();
LoadPdfStream();
}
private void LoadPageFitModes()
{
string[] pageFitModes = Enum.GetNames(typeof(PageFitMode));
ddlPageFitMode.DataSource = pageFitModes;
ddlPageFitMode.DataBind();
ddlPageFitMode.SelectedValue = pdfViewerControl.PageFitMode.ToString();
}
private void LoadDocumentDisplayModes()
{
string[] pageModes = Enum.GetNames(typeof(DocumentDisplayMode));
ddlPageMode.DataSource = pageModes;
ddlPageMode.DataBind();
ddlPageMode.SelectedValue = pdfViewerControl.DocumentDisplayMode.ToString();
}
private void ApplyViewerPreferences()
{
pdfViewerControl.DocumentDisplayMode =
(DocumentDisplayMode)Enum.Parse(typeof(DocumentDisplayMode), ddlPageMode.SelectedValue);
pdfViewerControl.ShowNavigationPanel = cbShowWindowUI.Checked;
pdfViewerControl.ShowScrollbars = cbShowScrollbars.Checked;
pdfViewerControl.ShowToolbarMode =
cbShowToolbar.Checked ? ShowToolbarMode.Show : ShowToolbarMode.Hide;
pdfViewerControl.PageFitMode =
(PageFitMode)Enum.Parse(typeof(PageFitMode), ddlPageFitMode.SelectedValue);
}
private void ApplySecurityOptions()
{
pdfViewerControl.PdfSecurityOptions.CanPrint = cbAllowPrint.Checked;
pdfViewerControl.PdfSecurityOptions.CanCopyContent = cbAllowContentCopy.Checked;
pdfViewerControl.PdfSecurityOptions.CanFillFormFields = cbAllowFormFilling.Checked;
pdfViewerControl.PdfSecurityOptions.CanEditContent = cbAllowContentEdit.Checked;
pdfViewerControl.PdfSecurityOptions.CanEditAnnotations = cbAllowEditAnnotations.Checked;
pdfViewerControl.PdfSecurityOptions.CanAssembleDocument = cbAllowAssemble.Checked;
pdfViewerControl.PdfSecurityOptions.UserPassword = textBoxUserPassword.Text.Trim();
}
private void LoadPdfStream()
{
//get the PDF stream
string urlToConvert = textBoxURLToConvert.Text.Trim();
byte[] pdfBytes = new PdfConverter().GetPdfBytesFromUrl(urlToConvert);
// set the PDF bytes to be loaded in viewer
pdfViewerControl.LicenseKey = "R8nYyNnfyNnZ2dnI3MbYyNvZxtnaxtHR0dE=";
pdfViewerControl.PdfSourceBytes = pdfBytes;
}
protected void btnApplyViewerPreferences_Click(object sender, EventArgs e)
{
// update the viewer preferences
ApplyViewerPreferences();
ApplySecurityOptions();
}
}
}