For those that are having problems loading large PDF files and having Memory issues. Below is code that will load one page at a time from the pdf file and create thumbnail list. This is a low memory usage method. Enjoy!!
public static ImageList PdfToImageList(string fileName, string tag = "")
{
ImageList imgList = new ImageList();
int i = 0;
try
{
int pageCount = new PdfDocument(fileName).Pages.Count;
// Get one page at a time, instead of loading the entire document
for (int j = 0; j < pageCount; j++)
{
Document document = new Document();
ImportedPageData pageData = new ImportedPageData(fileName, j + 1);
document.Pages.Add(new Page());
document.Pages[document.Pages.Count - 1].Elements.Add(pageData);
using (var iPdf = new InputPdf(document.Draw()))
{
using (var rastObj = new PdfRasterizer(iPdf))
{
byte[][] t = rastObj.Draw(ceTe.DynamicPDF.Rasterizer.ImageFormat.Bmp, ImageSize.Dpi96);
foreach (byte[] z in t)
{
using (var ms = new MemoryStream(z))
{
using (Bitmap tempImage = new Bitmap(ms))
{
Bitmap bmp = new Bitmap(100, 100);
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(tempImage, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));
}
imgList.Add(bmp);
imgList[i].Tag = fileName;
}
}
i++;
}
t = null;
}
}
}