Generating thumbnail from PDF file RRS feed

  • Question

  •  I am generating thumbnail from PDF file which is working fine in VS2008 windows application. But is is throwing error on web application....here is my code

    using System;

    using System.Configuration;

    using System.Data;

    using System.Linq;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.HtmlControls;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Xml.Linq;

    using System.Drawing;

    using System.Windows.Forms;

    using System.Runtime.InteropServices;

    using Acrobat;

    using System.Reflection;

    using System.Runtime.CompilerServices;

    using System.Deployment;

    public partial class _Default : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)



    private void generateThumbnailForPDF(string fileName)


    CAcroPDDoc doc = null;

    CAcroPDPage page = null;



    // instanciate adobe acrobat

    doc = (CAcroPDDoc)new Acrobat.AcroPDDocClass();

    if (doc.Open(fileName))


    if (doc.GetNumPages() > 0)


    // get reference to page

    // pages use a zero based index so 0 = page1

    page = (CAcroPDPage)doc.AcquirePage(0);

    AcroPoint pt = (AcroPoint)page.GetSize();

    AcroRect rect = new AcroRectClass();

    rect.Top = 0;

    rect.Left = 0;

    rect.right = pt.x;

    rect.bottom = pt.y;

    page.CopyToClipboard(rect, 50, 50, 100);

    object obj = page;


    //page.Draw(Convert. rect, 50, 50, 50, 100);

    IDataObject data = Clipboard.GetDataObject();

    //object data = Clipboard.GetData();

    System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)data.GetData(DataFormats.Bitmap);

    // calculate new height and width for thumbnail and maintain aspect ratio

    int h = (int)((double)pt.y * ((double)100 / (double)pt.x));

    int w = 100;

    // create thumbnail

    System.Drawing.Image img = bmp.GetThumbnailImage(50, 50, null, IntPtr.Zero);

    Session["ThumbNailImaage"] = img;






    //if (doc == null)

    MessageBox.Show("Acrobat is not installed. Adobe Acrobat is required.", "Acrobat no Installed", MessageBoxButtons.OK, MessageBoxIcon.Error);




    if (page != null) Marshal.ReleaseComObject(page);

    if (doc != null) Marshal.ReleaseComObject(doc);



    protected void Button1_Click(object sender, EventArgs e)


    string fileName = FileUpload1.PostedFile.FileName;




    in this line i am getting error

    IDataObject data = Clipboard.GetDataObject();

    Clipboard.GetDataObject(); it is returning null

    please help me

    Thanks in advanced

    Friday, July 4, 2008 5:34 AM


  • Well for starters, you can't use using System.Windows.Forms; in web development. 
    Same with messagebox.show : it won't show up in the browser, but it will show up on the server, waiting for input from the server... And since most of the time it's a dedicated server with no one logged in, your server will just hang forever. If it were even possible.
    It's the same reason why you're clipboard is action funny, because the static Clipboard class is defined in the System.Windows.Forms namespace... Big no no!
    I'm sorry to say, but you need to rethink some of your code if you want to port to web development vs form development. :'(
    • Marked as answer by jack 321 Tuesday, July 8, 2008 3:50 AM
    Friday, July 4, 2008 1:56 PM