• C#PDF转图片


    1.spire

    官方的有水印,通过引用

    复制代码
     //private readonly static PdfDocument doc = new PdfDocument();
            //public static Stream PtfToPng(string FileInfo)
            //{
            //byte[] by = Convert.FromBase64String(FileInfo);
            //doc.LoadFromBytes(by);
            //Image bmp = doc.SaveAsImage(0);//默认第一页
            //return ImageToStream(bmp);
    或者 //遍历PDF每一页 //for (int i = 0; i < doc.Pages.Count; i++) //{ // //将PDF页转换成Bitmap图形 // Image bmp = doc.SaveAsImage(i); // //将Bitmap图形保存为Png格式的图片 // string fileName = string.Format("Page-{0}.png", i + 1); // bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); //} //}
    复制代码

    2.

    Install-Package PdfiumViewer -Version 2.13.0

    Install-Package ImageResizer.Plugins.PdfiumRenderer.Pdfium.Dll -Version 1.0.1

     不支持32位程序

    复制代码
            /// <summary>
            /// ptf转图片流
            /// </summary>
            /// FileInf base64string
            /// <returns></returns>
            public static Stream PtfToPng(string FileInfo)
            {
                byte[] by = Convert.FromBase64String(FileInfo);
                Stream sm = new MemoryStream(by);
                using (var document = PdfiumViewer.PdfDocument.Load(sm))
                {
                    var size = document.PageSizes[0];
                    Image ig = document.Render(0, (int)size.Width, (int)size.Height, 300, 300, PdfiumViewer.PdfRenderFlags.Annotations);
                    return ImageToStream(ig);
                }
            }
    
            /// <summary>
            /// 返回图片流
            /// </summary>
            public static Stream ImageToStream(Image img)
            {
                MemoryStream ms = new MemoryStream();
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                return ms;
            }
    复制代码

    3.aspose.ptf,最下方有方块,

    复制代码
    private Stream ConvertToImage(Stream sm)
    {
        Document doc = new Document(sm);
        if (doc == null)
            Console.Write(doc);
        MemoryStream stream = new MemoryStream();
        Resolution reso = new Resolution(128);
        JpegDevice jpegDevice = new JpegDevice(reso, 100);
        jpegDevice.Process(doc.Pages[1], stream);
        return stream;
            //    //Image img = Image.FromStream(stream);
    }
    复制代码

     4.O2S.Components.PDFRender4NET

    复制代码
     /// <summary>
            /// 将PDF文档转换为图片的方法
            /// </summary>
            /// <param name="definition">设置图片的清晰度,数字越大越清晰(1-10)</param>
            public static Stream ConvertPdfImage(string Base64, int definition)
            {
                byte[] by = Convert.FromBase64String(Base64);
                Stream sm = new MemoryStream(by);
                PDFFile pdfFile = PDFFile.Open(sm);
                Bitmap pageImage = pdfFile.GetPageImage(0, 56 * definition);
                pdfFile.Dispose();
                return ImageToStream(pageImage);
            }
    
            /// <summary>
            /// 返回图片流
            /// </summary>
            public static Stream ImageToStream(Image img)
            {
                MemoryStream ms = new MemoryStream();
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                return ms;
            }
    复制代码

    无水印的O2S.Components.PDFRender4NET地址https://pan.baidu.com/s/1h8Zb4j4ofUnS4ZBoHJecHQ        码:cum8

    转自:https://www.cnblogs.com/shuaimeng/p/10523790.html

  • 相关阅读:
    关于json中对象的删除
    JDBC操作数据库 封装好的工具类
    json <--->List集合,实体类 之间的相互转换
    java--->>发送邮件
    登陆的过滤器
    Hadoop + Spark 在CentOS下的伪分布式部署
    CentOS和ubuntu修改hostname的区别
    ubuntu 用户管理 adduser vs useradd
    hadoop2.6.1源码编译64位
    MySQL Binlog详解
  • 原文地址:https://www.cnblogs.com/yangyangblog/p/14326905.html
Copyright © 2020-2023  润新知