public static void SavePageAllImages(string filePath, string finalPath, int pageIndex)
{
RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(filePath);
var pdf = Load(filePath);
try
{
PdfDictionary pg = pdf.GetPageN(pageIndex);
// recursively search pages, forms and groups for images.
PdfObject obj = FindImageInPDFDictionary(pg);
if (obj != null)
{
int XrefIndex = ((PRIndirectReference)obj).Number;
PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
PdfStream pdfStrem = (PdfStream)pdfObj;
byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
if ((bytes != null))
{
String imageFileName = System.IO.Path.Combine(finalPath, Guid.NewGuid().ToString() + ".png");
File.WriteAllBytes(imageFileName, bytes);
}
}
}
catch
{
throw;
}
finally
{
pdf.Close();
raf.Close();
}
}