You will not be able to do this with iText, since it cannot render or rasterize vector graphics in PDF files.
Option 1:
If a GPL license works for you, you could rasterize your PDF file with Imagemagick+GNU Ghostscript, but AFAIK you will have to write the output into a file in this case.
Command line sample:
convert -density 300 -depth 8 c:\temp\mydoc.pdf c:\temp\myrasterimage.png
There is also a .net wrapper in Codeplex that might work for you: ImageMagick.NET
Option A:
If a commercial library is an option for you, you could try with Amyuni PDF Creator .Net. You can either use the method IacDocument.ExportToJpg, which requires writing into a file, or you can use the method IacDocument.DrawCurrentPage, which can be useful for writing the output into a memory stream.
Sample code for exporting one page using IacDocument.DrawCurrentPage
into a memory stream:
const int twipsPerInch = 1440;
const int MM_ISOTROPIC = 7;
private static MemoryStream RasterizePDF(string filePath, int pageIndex, int targetDPI)
{
Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();
doc.SetLicenseKey("Evaluation", "07EFC00...77C23E29");
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
doc.Open(fs, "");
//Get the width and height of the target page
Amyuni.PDFCreator.IacPageFormat format = doc.GetPage(pageIndex).GetPageFormat();
doc.CurrentPageNumber = pageIndex;
//Create Image
Bitmap img = new Bitmap((int)(format.Width * targetDPI / twipsPerInch), (int)(format.Length * targetDPI / twipsPerInch), PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(img);
//set image object background to white
g.Clear(Color.White);
//Get a device context for the grahics object
IntPtr hdc = g.GetHdc();
SetMapMode(hdc, MM_ISOTROPIC);
// set scaling factor
SetWindowExtEx(hdc, twipsPerInch, twipsPerInch, 0);
SetViewportExtEx(hdc, targetDPI, targetDPI, 0);
//draw the contents of the PDF document on to the graphic context
doc.DrawCurrentPage(hdc, false);
//clean up
g.ReleaseHdc(hdc);
g.Dispose();
// Save the bitmap as png into the resulting stream
MemoryStream resultStrm = new MemoryStream();
img.Save(resultStrm, ImageFormat.Png);
//Prepare the stream to be read later on
resultStrm.Position = 0;
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int SetMapMode(IntPtr hdc, int MapMode);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int SetWindowExtEx(IntPtr hdc, int nXExtent, int nYExtent, int not_used);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int SetViewportExtEx(IntPtr hdc, int nXExtent, int nYExtent, int not_used);
Disclaimer: I currently work as a developer of the library