ptf转图片
Posted shuaimeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); }
以上是关于ptf转图片的主要内容,如果未能解决你的问题,请参考以下文章