Click here to Skip to main content
13,287,834 members (51,817 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 20 Sep 2006

ASP.NET Clipboard for PDF Rasterization

, 20 Sep 2006
Rate this:
Please Sign up or sign in to vote.
Use the clipboard to rasterize and/or resize a PDF file. This allows you to also save it for use as a JPG.


The first question you may ask is "Why would you ever want to use the server's clipboard to do anything?" Good question :). I came across this problem when I was trying to write a PDF parser that would rasterize the front page and save it into a Bitmap object. From here, you can save it to a file, database, etc. To do this, I was using the Adobe Acrobat COM library that comes with Adobe Acrobat 7.0. Unfortunately, they do not have a function that allows you to simply save to a file. They do, however, let you copy the image to the clipboard and then recover it in whatever format you want.


I found some great code by Jonathan Hodgson here: Generate Thumbnail Images from PDF Documents. This code was written for a C#/VB.NET Windows app, and works great if used that way. However, when I tried to use this text in the OnClick event of an ASP.NET Button control, I found that nothing was happening. Turns out, the CopyToClipboard command was working fine, because if I traced through, I could press Ctrl+v and see the image perfectly. However, when the Clipboard.GetObject method was called, it was always returning null.


After much digging and two days of work, I stumbled on the reason: the thread started for the ASP.NET application did not have the right ApartmentState to read the Clipboard class. So, here is what I did to work around this:

protected void Button_Click(object sender, EventArgs e)
     Thread cbThread = new Thread(new ThreadStart(CopyToClipboard));
     cbThread.ApartmentState = ApartmentState.STA;

protected void CopyToClipboard()
     In here, put the code that copies AND retrieves from the clipboard.
     If you use global variables, the Bitmap you populate 
     here can be used elsewhere in your code.

Final Notes

I do not recommend doing this in a multi-user environment as there is no guarantee that the user that copied to the clipboard will be the one who retrieves from it. Also, images/PDFs can be very large and the clipboard is slow.

I hope this is of some use to someone. It solved my problem, and saved me $900 by not having to buy a PDF Rasterizer control. Feel free to respond, and let me know if it helped you out or if you have any questions.


This article was posted first on the telerik forums.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Oleg Fridman
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow it works on windows Pin
abdulqadar11-Aug-08 21:13
memberabdulqadar11-Aug-08 21:13 
Generalhelp me....................... Pin
langamanish@yahoo.com22-Jul-08 20:14
memberlangamanish@yahoo.com22-Jul-08 20:14 
Generalthanks .. this code help me.. Pin
langamanish@yahoo.com22-Jul-08 2:15
memberlangamanish@yahoo.com22-Jul-08 2:15 
GeneralReally Helpfull Pin
Komal Bhatia16-Mar-08 21:57
memberKomal Bhatia16-Mar-08 21:57 
GeneralReally It help in the same case given by U Pin
KKGaurav6-Nov-07 2:18
memberKKGaurav6-Nov-07 2:18 
QuestionHelp to tune the settings Pin
zan20063-Apr-07 6:44
memberzan20063-Apr-07 6:44 
GeneralI've the same problem Pin
Unfounds23-Jan-07 4:29
memberUnfounds23-Jan-07 4:29 
GeneralRe: I've the same problem Pin
Oleg Fridman23-Jan-07 4:33
memberOleg Fridman23-Jan-07 4:33 
GeneralRe: I've the same problem Pin
shin99921-Jun-07 13:01
membershin99921-Jun-07 13:01 
GeneralNot work in Win2003 server with IIS6.0 Pin
Ajay Singh24-Oct-06 2:57
memberAjay Singh24-Oct-06 2:57 
AnswerRe: Not work in Win2003 server with IIS6.0 Pin
Oleg Fridman24-Oct-06 11:52
memberOleg Fridman24-Oct-06 11:52 
AnswerRe: Not work in Win2003 server with IIS6.0 Pin
Oleg Fridman26-Oct-06 10:27
memberOleg Fridman26-Oct-06 10:27 

In a different thread another person had the same problem.
He wrote:


We are actually using the adobe acrobat 6.0 sdk for generating the thumbnails of the pdf pages. using the code from the following link.

And this code is working fine on the win200o professional and Xp professional OS which is running with IIS5.0.

When we run this code on win2003 server machine which is running with IIS6.0 by default this code is not running properly. The main problem is we find out is with the introduction of new application pool concept in IIS6.0.

If we change the worker process isolation mode in IIS6.0 to be compatible with IIS 5.0 then the code runs fine but the report server(SQL server reporting services 2005) installed on the machine stops working.

We are not able to find the solution for this.

Note: To change the isolation mode in IIS 6.0. Here the link to find the step for this one[^]


Please give this a shot and let me know. Please note the problem he saw with SQL server.

- Oleg Fridman
GeneralRe: Not work in Win2003 server with IIS6.0 Pin
patric4213-Nov-07 3:35
memberpatric4213-Nov-07 3:35 
GeneralRe: Not work in Win2003 server with IIS6.0 Pin
Oleg Fridman13-Nov-07 3:42
memberOleg Fridman13-Nov-07 3:42 
GeneralWatch your EULA Pin
lrosenthol26-Sep-06 11:46
memberlrosenthol26-Sep-06 11:46 
GeneralRe: Watch your EULA Pin
Oleg Fridman26-Oct-06 10:30
memberOleg Fridman26-Oct-06 10:30 
QuestionThis was right on the mark... Pin
westberg25-Sep-06 12:25
memberwestberg25-Sep-06 12:25 
AnswerRe: This was right on the mark... Pin
Oleg Fridman25-Sep-06 15:54
memberOleg Fridman25-Sep-06 15:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 20 Sep 2006
Article Copyright 2006 by Oleg Fridman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid