/// <summary> /// 实例化转换工具 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="fileExtension">文件扩展名</param> /// <param name="callBack">回调方法</param> public Conversion(string filePath, string fileExtension, Action <int, string> callBack) { switch (fileExtension.ToLower()) { case ".doc": case ".docx": ConversionFunc = new WordConversion(); break; case ".pdf": ConversionFunc = new PdfConversion(); break; case ".xls": case ".xlsx": ConversionFunc = new ExcelConversion(); break; case ".ppt": case ".pptx": ConversionFunc = new PptConversion(); break; default: throw new Exception("不支持的文件类型。"); } FilePath = filePath; ConversionFunc.CallBack = callBack; }
public void ConvertToImage(string filePath, int resolution) { //先将Word转换为PDF文件 string pdfPath; try { using (WordToPdf convert = new WordToPdf()) { pdfPath = convert.ToPdf(filePath); } } catch (COMException) { pdfPath = Path.ChangeExtension(filePath, "pdf"); if (!File.Exists(pdfPath)) { Aspose.Words.Document doc = new Aspose.Words.Document(filePath); doc.Save(pdfPath, Aspose.Words.SaveFormat.Pdf); } } //再将PDF转换为图片 PdfConversion converter = new PdfConversion() { CallBack = CallBack }; converter.ConvertToImage(pdfPath, resolution); }
public void ConvertToImage(string filePath, int resolution) { Aspose.Slides.Presentation doc = new Aspose.Slides.Presentation(filePath); //先将ppt转换为PDF文件 string tmpPdfPath = Path.ChangeExtension(filePath, "pdf"); doc.Save(tmpPdfPath, Aspose.Slides.Export.SaveFormat.Pdf); //再将PDF转换为图片 PdfConversion converter = new PdfConversion() { CallBack = CallBack }; converter.ConvertToImage(filePath, resolution); }
public void ConvertToImage(string filePath, int resolution) { Aspose.Cells.Workbook doc = new Aspose.Cells.Workbook(filePath); //先将Excel转换为PDF临时文件 string pdfPath = Path.ChangeExtension(filePath, "pdf"); doc.Save(pdfPath, Aspose.Cells.SaveFormat.Pdf); //再将PDF转换为图片 PdfConversion converter = new PdfConversion() { CallBack = CallBack }; converter.ConvertToImage(filePath, resolution); }