public delegate int Pdf2JpgCallBack(int nMin, int nMax, int nCur);
class PPTOpreator
{
[DllImport("PDFToX.dll")]
private static extern int OpenPDF(string szPDFFileName, string szPWD);
[DllImport("PDFToX.dll")]
private static extern int ClosePDF(int hPDF);
[DllImport("PDFToX.dll")]
private static extern int GetPageNum(int hPDF);
[DllImport("PDFToX.dll")]
private static extern int ExportIMG(int hPDF, string szDir, string szPrefix,
int nFormatA, int dpiX, int dpiY, int nFrom, int nTo, Pdf2JpgCallBack pfun);
[DllImport("PDFtoX.dll", EntryPoint = "SetRCPath")]
private static extern int SetRCPath(string rcPath);
public static int Report(int nMin, int nMax, int nCur)
{
return 1;
}
public void pdfToImage(string fromPath)
{
DateTime t1 = DateTime.Now;
//Presentation ppt = new Presentation(fromPath);
//MemoryStream tempMemoryPdf = new MemoryStream();
//ppt.Save(tempMemoryPdf, Aspose.Slides.Export.SaveFormat.Pdf);
#region-----------iDiTect.Converter--------------
//LicenseManager.SetKey("CLTCN-MQF93-49AQ4-KCSXS-FVZWP-X49BW");
//PdfToImageConverter converter = new PdfToImageConverter();
//converter.Load(File.ReadAllBytes(@"D:\待删文件\test1.pdf"));
//converter.DPI = 72;
//for (int i = 0;i < converter.PageCount;i++)
//{
// Image pageImage = converter.PageToImage(i);
// pageImage.Save(@"D:\待删文件\test1\" + i.ToString() + ".jpg",ImageFormat.Jpeg);
//}
#endregion-----------iDiTect.Converter--------------
#region--------------PDFtoX----------------
//int openPdfSC = OpenPDF(@"D:\待删文件\test1.pdf","");
int openPdfSC = OpenPDF(@"D:\待删文件\test1.pdf", "");
Pdf2JpgCallBack myCallBack = new Pdf2JpgCallBack(Report);
int exportImgSC = ExportIMG(openPdfSC, @"D:\待删文件\test1","test",2,72,72,1,GetPageNum(openPdfSC),myCallBack);
#endregion--------------PDFtoX----------------
DateTime t2 = DateTime.Now;
TimeSpan t3 = t2 - t1;
double getSeconds = t3.TotalSeconds;
if(exportImgSC >= 0)
{
MessageBox.Show("success!用时:"+getSeconds.ToString()+"s");
}
else
{
MessageBox.Show("fail!");
}
}
}
需要将PDFToX.DLL放在debug目录下