C# word 转图片 PDF 转图片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# word 转图片 PDF 转图片相关的知识,希望对你有一定的参考价值。
word转图片使用的Aspose组件,Aspose.word.dll
public bool Word2Png(string docFile, string pngDir, out int pngCount) { ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png); options.Resolution = 300; options.PrettyFormat = true; options.UseAntiAliasing = true; pngCount = 0; try { Aspose.Words.Document doc = new Aspose.Words.Document(docFile); for (int i = 0; i < doc.PageCount; i++) { options.PageIndex = i; doc.Save(pngDir + i + ".png", options); pngCount++; } return true; } catch { return false; } }
PDF 转图片使用的是Aspose.pdf.dll 组件
public bool PDF2PNG(string srcPdfPath, string desPicPath) { try { Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(srcPdfPath); for (int pageCount = 1; pageCount <= pdf.Pages.Count; pageCount++) { using (FileStream imageStream = new FileStream(desPicPath + "\\" + pageCount + ".png", FileMode.Create)) { //create Resolution object Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300); Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice(resolution); //convert a particular page and save the image to stream pngDevice.Process(pdf.Pages[pageCount], imageStream); //close stream imageStream.Close(); } } return true; } catch (Exception e) { return false; } }
以上是关于C# word 转图片 PDF 转图片的主要内容,如果未能解决你的问题,请参考以下文章