zoukankan      html  css  js  c++  java
  • ptf转图片

    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

            /// <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

  • 相关阅读:
    (转)Apache与Tomcat 区别联系
    (转)JAVA排序汇总
    (转)Java线程:大总结
    (转)Java线程:新特征-原子量,障碍器
    (转)Java线程:新特征-条件变量
    oracle中的not in和not exists注意事项
    oracle字符乱码的解决方法
    线刷和卡刷的区别
    nexus5刷机
    linux上复制行到另一个文件
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/10523790.html
Copyright © 2011-2022 走看看