using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export;
using Telerik.Windows.Documents.Fixed.Model;
using Telerik.Windows.Documents.Fixed.Model.Editing;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadRotator1.DataSource = GetData();
            RadListView1.DataSource = GetData();
            RadRotator1.DataBind();
            RadListView1.DataBind();
        }
    }

    private object GetData()
    {
        return new List<PdfThumb>() { 
            new PdfThumb { ImageUrl = "/Images/FullImages/AJAX_ImageGallery_pdf.png", ThumbnailUrl = "/Images/Thumbnails/AJAX_ImageGallery_pdf.png", PdfUrl = "/PdfFiles/RadImageGallery.pdf" },
            new PdfThumb { ImageUrl = "/Images/FullImages/AJAX_MediaPlayer_pdf.png", ThumbnailUrl = "/Images/Thumbnails/AJAX_MediaPlayer_pdf.png", PdfUrl = "/PdfFiles/RadMediaPlayer.pdf" },
            new PdfThumb { ImageUrl = "/Images/FullImages/AJAX_Menu_pdf.png", ThumbnailUrl = "/Images/Thumbnails/AJAX_Menu_pdf.png", PdfUrl = "/PdfFiles/RadMenu.pdf" }
        };
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        LinkButton lb = sender as LinkButton;
        string script = String.Format("Sys.Application.add_load(function() {{ openWindow($get('{0}')); }});", lb.ClientID); ;
        lb.ToolTip = "pdf.js/web/viewer.html?file=/PdfFiles/PdfProcessing.pdf";

        GenerateTestPdfFile();

        ScriptManager.RegisterStartupScript(this, this.GetType(), "openPdfFile", script, true); 
    }

    private void GenerateTestPdfFile()
    {
        PdfFormatProvider formatProvider = new PdfFormatProvider();
        RadFixedDocument document = new RadFixedDocument();

        formatProvider.ExportSettings.ImageQuality = ImageQuality.High;

        using (FileStream pdfStream = new FileStream(Server.MapPath("~/PdfFiles/PdfProcessing.pdf"), FileMode.Create))
        {
            DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("/Images/FullImages"));
            foreach (FileInfo fileInfo in dirInfo.GetFiles())
            {
                RadFixedPage page = document.Pages.AddPage();
                FixedContentEditor editor = new FixedContentEditor(page);

                page.Size = new System.Windows.Size(400, 560);

                using (FileStream fs = fileInfo.OpenRead())
                {
                    editor.DrawImage(fs);
                }
            }

            formatProvider.Export(document, pdfStream);
        }
    }
}