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; } }
时间: 2024-10-31 05:56:44