c# pdf转图片

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目录下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值