基本信息
源码名称:c# pdf 转图片 示例源码(O2S.Components.PDFRender4NET)
源码大小:9.51M
文件格式:.rar
开发语言:C#
更新时间:2018-08-16
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

c# pdf 转图片,转换后 图片保存在 同目录下的 picture 文件夹了



public static void ConvertPDF2Image(string pdfInputPath, string imageOutputPath,
            string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, Definition definition)
        {
            PDFFile pdfFile = PDFFile.Open(pdfInputPath);

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

            // 开始的页
            if (startPageNum <= 0)
            {
                startPageNum = 1;
            }

            if (endPageNum > pdfFile.PageCount)
            {
                endPageNum = pdfFile.PageCount;
            }

            if (startPageNum > endPageNum)
            {
                int tempPageNum = startPageNum;
                startPageNum = endPageNum;
                endPageNum = startPageNum;
            }

            // 转成图片,并保存
            for (int i = startPageNum; i <= endPageNum; i )
            {
                Bitmap pageImage = pdfFile.GetPageImage(i - 1, 56 * (int)definition);
                pageImage.Save(imageOutputPath imageName i.ToString() "." imageFormat.ToString(), imageFormat);
                pageImage.Dispose();
            } 
            pdfFile.Dispose();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 打开文件
            
            OpenFileDialog addFileDialog = new OpenFileDialog();
            addFileDialog.Filter = "pdf|*.pdf";

            //  
            if (addFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (addFileDialog.FileName != null)
                {
                    //得到地址信息
                    address_pdf = addFileDialog.FileName;
                }
                else
                {
                    ;
                }
            }
            else
            {
                ;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase "\\picture\\";
            ConvertPDF2Image(address_pdf, str, "A", 1, 1000, ImageFormat.Jpeg, Definition.Four);
            MessageBox.Show("PDF转JPEG完成!");
        }