예제 #1
0
        /// <summary>
        /// Converting PDF Files TO Specified Image Format
        /// </summary>
        /// <param name="sourceFileName">Source PDF File Path</param>
        /// <param name="DestinationPath">Destination PDF File Path</param>
        /// <param name="outPutImageFormat">Type Of Exported Image</param>
        /// <returns>Returns Count Of Exported Images</returns>
        public int Convert(string sourceFileName, string DestinationPath, ImageFormat outPutImageFormat)
        {
            if (pdfDoc.Open(sourceFileName))
            {
                // pdfapp.Hide();
                pageCount = pdfDoc.GetNumPages();

                for (int i = 0; i < pageCount; i++)
                {
                    pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i);


                    pdfPoint       = (Acrobat.AcroPoint)pdfPage.GetSize();
                    pdfRect.Left   = 0;
                    pdfRect.right  = pdfPoint.x;
                    pdfRect.Top    = 0;
                    pdfRect.bottom = pdfPoint.y;

                    pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);

                    string outimg   = "";
                    string filename = sourceFileName.Substring(sourceFileName.LastIndexOf("\\"));

                    if (pageCount == 1)
                    {
                        outimg = DestinationPath + "\\" + filename + "." + outPutImageFormat.ToString();
                    }
                    else
                    {
                        outimg = DestinationPath + "\\" + filename + "_" + i.ToString() + "." + outPutImageFormat.ToString();
                    }

                    Clipboard.GetImage().Save(outimg, outPutImageFormat);

                    ////////////Firing Progress Event
                    OnExportProgressChanging(outimg);
                }

                Dispose();
            }
            else
            {
                Dispose();
                throw new System.IO.FileNotFoundException(sourceFileName + " Not Found!");
            }
            return(pageCount);
        }
예제 #2
0
        /// <summary>
        /// 将PDF文档转换为图片的方法,你可以像这样调用该方法:ConvertPDF2ImageO2S("F:\\A.pdf", "F:\\", "A", 0, 0, null, 0);
        /// 因为大多数的参数都有默认值,startPageNum默认值为1,endPageNum默认值为总页数,
        /// imageFormat默认值为ImageFormat.Jpeg,resolution默认值为1
        /// </summary>
        /// <param name="pdfInputPath">PDF文件路径</param>
        /// <param name="imageOutputPath">图片输出路径</param>
        /// <param name="imageName">图片的名字,不需要带扩展名</param>
        /// <param name="startPageNum">从PDF文档的第几页开始转换,默认值为1</param>
        /// <param name="endPageNum">从PDF文档的第几页开始停止转换,默认值为PDF总页数</param>
        /// <param name="imageFormat">设置所需图片格式</param>
        /// <param name="resolution">设置图片的分辨率,数字越大越清晰,默认值为1</param>
        public void ConvertPDF2Image(string pdfInputPath)
        {
            // Is NULL
            if (pdfInputPath == null)
            {
                m_nConvertStatus = EErrorType.PTJ_FILENAME_EMPTY;
            }
            if (!System.IO.File.Exists(pdfInputPath))
            {
                m_nConvertStatus = EErrorType.WPS_FILE_NOTEXISTS;
            }
            Acrobat.CAcroPDDoc  pdfDoc   = null;
            Acrobat.CAcroPDPage pdfPage  = null;
            Acrobat.CAcroRect   pdfRect  = null;
            Acrobat.CAcroPoint  pdfPoint = null;
            ewhCopyJpg = new EventWaitHandle(false, 0, "WPSToJPGPDFToJPGUsingArobat");
            try
            {
                // Create the document (Can only create the AcroExch.PDDoc object using late-binding)
                // Note using VisualBasic helper functions, have to add reference to DLL
                pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");

                // validate parameter
                if (!pdfDoc.Open(pdfInputPath))
                {
                    throw new FileNotFoundException();
                }
                if (!Directory.Exists(m_strOutDir))
                {
                    Directory.CreateDirectory(m_strOutDir);
                }
                m_nTotalPage = pdfDoc.GetNumPages();
                PrintLog("ConvertStatus:" + (int)ConvertStatus.START + " " + 0 + " " + m_nTotalPage);
                // start to convert each page
                for (int i = 1; i <= m_nTotalPage; i++)
                {
                    PrintLog("ConvertStatus:" + (int)ConvertStatus.ING + " " + i + " " + m_nTotalPage);
                    pdfPage  = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i - 1);
                    pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
                    pdfRect  = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");
                    // 如果当前分辨率少于1280*720,强制放大
                    int imgWidth  = (int)((double)pdfPoint.x * (int)m_dQuality);
                    int imgHeight = (int)((double)pdfPoint.y * (int)m_dQuality);

                    pdfRect.Left   = 0;
                    pdfRect.right  = (short)imgWidth;
                    pdfRect.Top    = 0;
                    pdfRect.bottom = (short)imgHeight;

                    // 临界区
                    ewhCopyJpg.WaitOne();
                    // Render to clipboard, scaled by 100 percent (ie. original size)
                    // Even though we want a smaller image, better for us to scale in .NET
                    // than Acrobat as it would greek out small text
                    pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * (int)m_dQuality));

                    IDataObject clipboardData = Clipboard.GetDataObject();
                    if (clipboardData.GetDataPresent(DataFormats.Bitmap))
                    {
                        string strJPGName = m_strOutDir + "\\" + Path.GetFileNameWithoutExtension(pdfInputPath) + "_" + pdfDoc.GetNumPages() + "_" + (i).ToString() + ".jpg";
                        Bitmap pdfBitmap  = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
                        pdfBitmap.Save(strJPGName, ImageFormat.Jpeg);
                        pdfBitmap.Dispose();
                    }
                    Clipboard.Clear();
                    ewhCopyJpg.Set();
                }
                QuitAcrobat(ref pdfDoc, ref pdfPage, ref pdfRect, ref pdfPoint);
            }
            catch (Exception ex)
            {
                PrintLog(ex.Message.ToString());
                m_nConvertStatus = EErrorType.PTJ_EXCEPTION_FAILED;
            }
            finally
            {
                QuitAcrobat(ref pdfDoc, ref pdfPage, ref pdfRect, ref pdfPoint);
            }
        }
예제 #3
0
        /// <summary>
        /// 将PDF文档转换为图片的方法,你可以像这样调用该方法:ConvertPDF2Image("F:\\A.pdf", "F:\\", "A", 0, 0, null, 0);
        /// 因为大多数的参数都有默认值,startPageNum默认值为1,endPageNum默认值为总页数,
        /// imageFormat默认值为ImageFormat.Jpeg,resolution默认值为1
        /// </summary>
        /// <param name="pdfInputPath">PDF文件路径</param>
        /// <param name="imageOutputPath">图片输出路径</param>
        /// <param name="imageName">图片的名字,不需要带扩展名</param>
        /// <param name="startPageNum">从PDF文档的第几页开始转换,默认值为1</param>
        /// <param name="endPageNum">从PDF文档的第几页开始停止转换,默认值为PDF总页数</param>
        /// <param name="imageFormat">设置所需图片格式</param>
        /// <param name="resolution">设置图片的分辨率,数字越大越清晰,默认值为1</param>
        public static void ConvertPDF2Image(string pdfInputPath, string imageOutputPath,
                                            string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, double resolution)
        {
            Acrobat.CAcroPDDoc  pdfDoc   = null;
            Acrobat.CAcroPDPage pdfPage  = null;
            Acrobat.CAcroRect   pdfRect  = null;
            Acrobat.CAcroPoint  pdfPoint = null;

            // Create the document (Can only create the AcroExch.PDDoc object using late-binding)
            // Note using VisualBasic helper functions, have to add reference to DLL
            pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");

            // validate parameter
            if (!pdfDoc.Open(pdfInputPath))
            {
                throw new FileNotFoundException();
            }
            if (!Directory.Exists(imageOutputPath))
            {
                Directory.CreateDirectory(imageOutputPath);
            }
            if (startPageNum <= 0)
            {
                startPageNum = 1;
            }
            if (endPageNum > pdfDoc.GetNumPages() || endPageNum <= 0)
            {
                endPageNum = pdfDoc.GetNumPages();
            }
            if (startPageNum > endPageNum)
            {
                int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
            }
            if (imageFormat == null)
            {
                imageFormat = ImageFormat.Jpeg;
            }
            if (resolution <= 0)
            {
                resolution = 1;
            }

            // start to convert each page
            for (int i = startPageNum; i <= endPageNum; i++)
            {
                pdfPage  = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i - 1);
                pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
                pdfRect  = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");

                int imgWidth  = (int)((double)pdfPoint.x * resolution);
                int imgHeight = (int)((double)pdfPoint.y * resolution);

                pdfRect.Left   = 0;
                pdfRect.right  = (short)imgWidth;
                pdfRect.Top    = 0;
                pdfRect.bottom = (short)imgHeight;

                // Render to clipboard, scaled by 100 percent (ie. original size)
                // Even though we want a smaller image, better for us to scale in .NET
                // than Acrobat as it would greek out small text
                pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * resolution));

                IDataObject clipboardData = Clipboard.GetDataObject();

                if (clipboardData.GetDataPresent(DataFormats.Bitmap))
                {
                    Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
                    pdfBitmap.Save(Path.Combine(imageOutputPath, imageName) + i.ToString() + "." + imageFormat.ToString(), imageFormat);
                    pdfBitmap.Dispose();
                }
            }

            pdfDoc.Close();
            Marshal.ReleaseComObject(pdfPage);
            Marshal.ReleaseComObject(pdfRect);
            Marshal.ReleaseComObject(pdfDoc);
            Marshal.ReleaseComObject(pdfPoint);
        }
예제 #4
0
        private void GetImgFromClipboard()
        {
            try
            {
                string pdfInputPath    = tempFilePath;
                string imageOutputPath = savePath;
                //string pdfInputPath = @"D:\pdfImgs\test.pdf";
                //string imageOutputPath = @"D:\pdfImgs\";
                int                 startPageNum = 1;
                ImageFormat         imageFormat  = ImageFormat.Jpeg;
                int                 resolution   = 1;
                Acrobat.CAcroPDDoc  pdfDoc       = null;
                Acrobat.CAcroPDPage pdfPage      = null;
                Acrobat.CAcroRect   pdfRect      = null;
                Acrobat.CAcroPoint  pdfPoint     = null;

                // Create the document (Can only create the AcroExch.PDDoc object using late-binding)
                // Note using VisualBasic helper functions, have to add reference to DLL
                pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");

                // validate parameter
                if (!pdfDoc.Open(pdfInputPath))
                {
                    throw new FileNotFoundException();
                }
                if (!Directory.Exists(imageOutputPath))
                {
                    Directory.CreateDirectory(imageOutputPath);
                }
                int endPageNum = pdfDoc.GetNumPages();
                if (startPageNum <= 0)
                {
                    startPageNum = 1;
                }
                if (endPageNum > pdfDoc.GetNumPages() || endPageNum <= 0)
                {
                    endPageNum = pdfDoc.GetNumPages();
                }
                if (startPageNum > endPageNum)
                {
                    int tempPageNum = startPageNum;
                    startPageNum = endPageNum; endPageNum = startPageNum;
                }
                if (imageFormat == null)
                {
                    imageFormat = ImageFormat.Jpeg;
                }
                if (resolution <= 0)
                {
                    resolution = 1;
                }

                // start to convert each page
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    pdfPage  = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i - 1);
                    pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
                    pdfRect  = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");

                    int imgWidth  = (int)((double)pdfPoint.x * resolution);
                    int imgHeight = (int)((double)pdfPoint.y * resolution);

                    pdfRect.Left   = 0;
                    pdfRect.right  = (short)imgWidth;
                    pdfRect.Top    = 0;
                    pdfRect.bottom = (short)imgHeight;

                    // Render to clipboard, scaled by 100 percent (ie. original size)
                    // Even though we want a smaller image, better for us to scale in .NET
                    // than Acrobat as it would greek out small text
                    bool b = pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * resolution));

                    IDataObject clipboardData = Clipboard.GetDataObject();

                    if (clipboardData.GetDataPresent(DataFormats.Bitmap))
                    {
                        Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
                        string imtName   = i.ToString() + ".jpg";
                        pdfBitmap.Save(imageOutputPath + "\\" + imtName, imageFormat);
                        pdfBitmap.Dispose();
                    }
                }
                if (endPageNum > 0)
                {
                    StringBuilder sb = new StringBuilder();

                    sb.Append(string.Format("delete from PreviewFile where AttachmentId={0};", lastCheckId));
                    for (int num = 1; num <= endPageNum; num++)
                    {
                        string filename = imageOutputPath + "\\" + num.ToString() + ".jpg";
                        sb.Append(string.Format("insert into PreviewFile(AttachmentId,SavePath,CreateTime)values({0},'{1}','{2}');", lastCheckId, filename.Replace(sourcePath, "").Replace("\\", "/"), DateTime.Now));
                        Thread.Sleep(1000);
                    }
                    var result = SqlHelper.ExecteNonQueryText(sb.ToString(), null);
                    if (result > 0)
                    {
                    }
                    else
                    {
                        RecodeErroeData(lastCheckId);
                    }
                }

                pdfDoc.Close();
                Marshal.ReleaseComObject(pdfPage);
                Marshal.ReleaseComObject(pdfRect);
                Marshal.ReleaseComObject(pdfDoc);
                Marshal.ReleaseComObject(pdfPoint);
            }
            catch (Exception ex)
            {
                LogControl.LogInfo("从剪切板获取PDF图片异常lastCheckId:" + lastCheckId + " " + ex.ToString());
                RecodeErroeData(lastCheckId);
            }
        }
        /// <summary>
        /// PDF转Image
        /// </summary>
        /// <param name="pdfInputPath">PDF文件</param>
        /// <param name="imageOutputPath">图片文件路径</param>
        /// <param name="imageName">图片名称</param>
        /// <param name="startPageNum">从第几页开始</param>
        /// <param name="endPageNum">到第几页结束</param>
        /// <param name="imageFormat">生成图片类型</param>
        /// <param name="resolution">显示倍数</param>
        public bool ConvertPDF2Image(string pdfInputPath, string imageOutputPath,
                                     string imageName, string Hospsampleid, int startPageNum, int endPageNum, ImageFormat imageFormat, double resolution)
        {
            bool          falg   = true;
            List <string> Sqllst = new List <string>();
            //执行的SQL集合
            string     errormsg = "";
            SortedList SQLlist  = new SortedList(new MySort());
            int        errcount = 0; //标记当前pdf每页是否都已经转图片成功

            Acrobat.CAcroPDDoc  pdfDoc   = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");
            Acrobat.CAcroPDPage pdfPage  = null;
            Acrobat.CAcroRect   pdfRect  = null;
            Acrobat.CAcroPoint  pdfPoint = null;
            try
            {
                //yhl 2017.3.22pdf转图片之前先清空粘贴板信息,防止图片信息没清空,下个条码存了上个条码的信息
                //IDataObject clipboardData1 = Clipboard.GetDataObject();
                //if (clipboardData1.GetDataPresent(DataFormats.Bitmap))
                //{
                Clipboard.Clear();
                // }
                // Create the document (Can only create the AcroExch.PDDoc object using late-binding)
                // Note using VisualBasic helper functions, have to add reference to DLL
                // pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");//.CreateObject("AcroExch.PDDoc", "");
                //var CreatePdf = Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");
                // pdfDoc = (Acrobat.CAcroPDDoc)CreatePdf;

                // pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);
                // validate parameter
                if (!pdfDoc.Open(pdfInputPath))
                {
                    throw new FileNotFoundException();
                }
                if (!Directory.Exists(imageOutputPath))
                {
                    Directory.CreateDirectory(imageOutputPath);
                }
                if (startPageNum <= 0)
                {
                    startPageNum = 1;
                }
                if (endPageNum > pdfDoc.GetNumPages() || endPageNum <= 0)
                {
                    endPageNum = pdfDoc.GetNumPages();
                }
                if (startPageNum > endPageNum)
                {
                    int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
                }
                if (imageFormat == null)
                {
                    imageFormat = ImageFormat.Jpeg;
                }
                if (resolution <= 0)
                {
                    resolution = 1;
                }

                // start to convert each page
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    pdfPage  = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i - 1);
                    pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
                    pdfRect  = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");

                    int imgWidth  = (int)((double)pdfPoint.x * resolution);
                    int imgHeight = (int)((double)pdfPoint.y * resolution);

                    pdfRect.Left   = 0;
                    pdfRect.right  = (short)imgWidth;
                    pdfRect.Top    = 0;
                    pdfRect.bottom = (short)imgHeight;

                    pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * resolution));

                    IDataObject clipboardData = Clipboard.GetDataObject();
                    if (clipboardData.GetDataPresent(DataFormats.Bitmap))
                    {
                        Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
                        pdfBitmap.Save(Path.Combine(imageOutputPath, imageName) + "_" + i + ".jpg", imageFormat);
                        pdfBitmap.Dispose();
                    }

                    string imgpath = Path.Combine(imageOutputPath, imageName) + "_" + i + ".jpg";
                    if (!File.Exists(imgpath) || File.ReadAllBytes(imgpath).Count() <= 0)
                    {
                        errcount++;
                    }

                    string          imageAddress = getImageString(Path.Combine(imageOutputPath, imageName) + "_" + i + ".jpg");
                    int             maxid        = new TableIDDAO().GetNextId("DAAN_LIS_REPORT");
                    DAAN_LIS_REPORT dalisReport  = new DAAN_LIS_REPORT();
                    dalisReport.DAAN_ID       = maxid.ToString();
                    dalisReport.DAAN_JPG      = Convert.FromBase64String(imageAddress);
                    dalisReport.DAAN_BAR_CODE = Hospsampleid;
                    SQLlist.Add(new Hashtable()
                    {
                        { "INSERT", "InsertDAAN_LIS_REPORT" }
                    }, dalisReport);
                }

                pdfDoc.Close();
                Marshal.ReleaseComObject(pdfPage);
                Marshal.ReleaseComObject(pdfRect);
                Marshal.ReleaseComObject(pdfDoc);
                Marshal.ReleaseComObject(pdfPoint);
                falg = service.ExecuteSqlTran(SQLlist, ref errormsg);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                SetTB(imageName + "条码转换失败!" + ex.Message);
                falg = false;
                errcount++;

                pdfDoc.Close();
                Marshal.ReleaseComObject(pdfPage);
                Marshal.ReleaseComObject(pdfRect);
                Marshal.ReleaseComObject(pdfDoc);
                Marshal.ReleaseComObject(pdfPoint);
            }

            if (errcount > 0)
            {
                falg = false;
            }
            return(falg);
        }
예제 #6
0
        /* private static void TurnTheImageToPdf(ref List<System.Drawing.Image> allName)
         * {
         *   throw new NotImplementedException();
         * }*/


        //ConvertPDF2Image(string pdfInputPath, string imageOutputPath, string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, double resolution)
        //将pdfInputPath改成得到的pdfToPdfPath路径

        /*public static void ConvertPDF2Image(List<string> pdfInputPath,string outpath ,int startPageNum, int endPageNum, ImageFormat imageFormat, double resolution)
         * {
         *  string imageinputPath=pdfInputPath[0];
         *  string imageOutputPath = outpath;
         *  string imageName;
         *  int flag=0;
         *  Acrobat.CAcroPDDoc pdfDoc = null;
         *  Acrobat.CAcroPDPage pdfPage = null;
         *  Acrobat.CAcroRect pdfRect = null;
         *  Acrobat.CAcroPoint pdfPoint = null;
         *  pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");
         *  if (!pdfDoc.Open(imageinputPath))
         *  {
         *      throw new FileNotFoundException();
         *  }
         *
         *  if (!Directory.Exists(imageOutputPath))
         *  {
         *      Directory.CreateDirectory(imageOutputPath);
         *  }
         *
         *  if (startPageNum <= 0)
         *  {
         *      startPageNum = 1;
         *  }
         *  if (endPageNum > pdfDoc.GetNumPages())
         *  {
         *      endPageNum = pdfDoc.GetNumPages();
         *  }
         *  if (startPageNum > endPageNum)
         *  {
         *      int tempPageNum = startPageNum;
         *      startPageNum = endPageNum;
         *      endPageNum = startPageNum;
         *  }
         *  for(int i=0;i< pdfInputPath.Count; i++)
         *  {
         *      string fileName = pdfInputPath[i].Substring(0, pdfInputPath[i].Length - 4);
         *      imageOutputPath = pdfInputPath[i].Substring(0, pdfInputPath[i].Length - 4);//这里有问题
         *      imageName = fileName;
         *      flag++;
         *      for (int j = startPageNum; j <= endPageNum; j++)
         *      {
         *          pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(j - 1);
         *          pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
         *          pdfRect = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");
         *          int imgWidth = (int)((double)pdfPoint.x * resolution);
         *          int imgHeight = (int)((double)pdfPoint.y * resolution);
         *          pdfRect.Left = 0;
         *          pdfRect.right = (short)imgWidth;
         *          pdfRect.Top = 0;
         *          pdfRect.bottom = (short)imgHeight;
         *          pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * resolution));
         *          IDataObject clipboardData = Clipboard.GetDataObject();
         *          if (clipboardData.GetDataPresent(DataFormats.Bitmap))
         *          {
         *              Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
         *              pdfBitmap.Save(Path.Combine(imageOutputPath, imageName)+ ".Jpeg", imageFormat);
         *              pdfBitmap.Dispose();
         *          }
         *      }
         *
         *
         *  }
         *  if (flag == pdfInputPath.Count) {
         *      MessageBox.Show("转化成功");
         *  }
         *
         * }*/
        //将小pdf转换成图片
        public static string ConvertPDF2Image(string pdfInputPath, string imageOutputPath, string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, double resolution)

        {
            string imagePath = null;

            Acrobat.CAcroPDDoc pdfDoc = null;

            Acrobat.CAcroPDPage pdfPage = null;

            Acrobat.CAcroRect pdfRect = null;

            Acrobat.CAcroPoint pdfPoint = null;

            pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");

            if (!pdfDoc.Open(pdfInputPath))
            {
                throw new FileNotFoundException();
            }

            if (!Directory.Exists(imageOutputPath))
            {
                Directory.CreateDirectory(imageOutputPath);
            }

            if (startPageNum <= 0)
            {
                startPageNum = 1;
            }
            if (endPageNum > pdfDoc.GetNumPages())
            {
                endPageNum = pdfDoc.GetNumPages();
            }
            if (startPageNum > endPageNum)
            {
                int tempPageNum = startPageNum;
                startPageNum = endPageNum;
                endPageNum   = startPageNum;
            }

            for (int i = startPageNum; i <= endPageNum; i++)

            {
                pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i - 1);

                pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();

                pdfRect = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");



                int imgWidth = (int)((double)pdfPoint.x * resolution);

                int imgHeight = (int)((double)pdfPoint.y * resolution);
                pdfRect.Left = 0;

                pdfRect.right = (short)imgWidth;

                pdfRect.Top = 0;

                pdfRect.bottom = (short)imgHeight;


                pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * resolution));



                IDataObject clipboardData = Clipboard.GetDataObject();



                if (clipboardData.GetDataPresent(DataFormats.Bitmap))

                {
                    Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);

                    pdfBitmap.Save(Path.Combine(imageOutputPath, imageName) + ".Png", imageFormat);

                    pdfBitmap.Dispose();
                }
            }
            pdfDoc.Close();
            imagePath = imageName + ".Png";

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfPage);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfRect);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfDoc);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfPoint);
            return(imagePath);
        }