aspose授权亲测可用配套代码

aspose授权亲测可用配套代码

2023年7月3日发(作者:)

aspose授权亲测可⽤配套代码⽀持excel,word,ppt,pdfusing ;using ;using ESBasic;using oard;using System;using c;using g;using g;using ;using ;using ing;using ;using ;using ntManager;using ImageSaveOptions = aveOptions;using SaveFormat = rmat;namespace ManagerWeb{ public partial class Upload : { protected void Page_Load(object sender, EventArgs e) { //new e().SetLicense(m); //new e().SetLicense(m); //new e().SetLicense(m); //new e().SetLicense(m); string documentExts = "pdf|doc|docx|xlsx|xls|ppt|pptx"; string imageExts = "jpeg|png|jpg|bmp"; string otherExts = "pdf|xls|xlsx|ppt|pptx"; HttpFileCollection files = ;//这⾥只能⽤才能有效果,因为服务器控件是HttpInputFile类型 FileUpModel model = new FileUpModel(); if ( == 0 || files[0]. == 0) { model = new FileUpModel() { State = 0, Error = "没有找到⽂件" }; (izeObject(model)); //(); return; } try { HttpPostedFile file = files[0]; ion = GetExtension(me); if ((documentExts + "|" + imageExts + "|" + otherExts).IndexOf(r()) == -1) { model = new FileUpModel() { State = 0, Error = "不允许上传" + ion + "类型⽂件" }; (izeObject(model)); //(); return; } = tLength / 1024; DateTime nowtime = ; string dic = "/UpLoadFile/" + ng("yy/MM/dd/"); string newFilename = "/UpLoadFile/" + ng("yy/MM/dd/") + d().ToString("N") + "." + ion; string filepath = h("~" + newFilename); if (!(h(dic))) { Directory(h(dic)); } (filepath); //将⽂档装换为图图⽚ if (f(r()) != -1) { //图⽚⽬录 string imagedic = e("." + ion, ""); IImageConverterFactory f = new ImageConverterFactory(); IImageConverter imageConverter = ImageConverter("." + ion); string opath = h("~" + newFilename); string imgpath = h("~" + imagedic + "/"); Thread thd = new Thread(new ThreadStart(() => { tToImage(opath, imgpath); })); (); //DocumentToImage(newFilename, imagedic); ath = imagedic; } = 1; = newFilename; (izeObject(model)); } catch (Exception ee) { model = new FileUpModel() { State = 0, Error = e }; (izeObject(model)); (); } } private void DocumentToImage(string filename, string imagedic) { Thread thd = new Thread(new ThreadStart(() => { ConvertWordToImage(h("~" + filename), h("~" + imagedic + "/"), "A", 0, 0, , 0); })); (); } private string GetExtension(string filename) { if (OrEmpty(filename)) return ""; string[] strs = ('.'); if ( > 0) { return strs[ - 1]; } else { return ""; } } public void ConvertWordToImage(string wordInputPath, string imageOutputPath, string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution) { try { dsLicense(); // open word file nt doc = new nt(wordInputPath); // validate parameter if (doc == null) { throw new Exception("Word⽂件⽆效或者Word⽂件被加密!"); } if (().Length == 0) { imageOutputPath = ectoryName(wordInputPath); } if (!(imageOutputPath)) { Directory(imageOutputPath); } if (().Length == 0) { imageName = eNameWithoutExtension(wordInputPath); } if (startPageNum <= 0) { startPageNum = 1; } if (endPageNum > unt || endPageNum <= 0) { endPageNum = unt; } if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; } if (imageFormat == null) { imageFormat = ; } if (resolution <= 0) { resolution = 128; } var imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat)) { Resolution = resolution }; // start to convert each page for (int i = startPageNum; i <= endPageNum; i++) { dex = i - 1; (e(imageOutputPath, imageName) + "_" + ng() + "." + ng(), imageSaveOptions); } } catch (Exception ex) { } } private SaveFormat GetSaveFormat(ImageFormat imageFormat) { SaveFormat sf = n; if (()) sf = ; else if (()) sf = ; else if (()) sf = ; else if (()) sf = ; else sf = n; return sf; } } public class FileUpModel { ///

/// 状态 1成功 0失败 /// public int State { get; set; } /// /// 错误信息 /// public string Error { get; set; } /// /// ⽂件⼤⼩ /// public decimal Size { get; set; } /// /// 服务端路径 /// public string Path { get; set; } public string ImagePath { get; set; } public string Extension { get; set; } } #region 图⽚转换器⼯⼚ -> 将被注⼊到OMCS的多媒体管理器IMultimediaManager的ImageConverterFactory属性 /// /// 图⽚转换器⼯⼚。 /// public class ImageConverterFactory : IImageConverterFactory { public IImageConverter CreateImageConverter(string extendName) { if (extendName == ".doc" || extendName == ".docx") { return new Word2ImageConverter(); } if (extendName == ".pdf") { return new Pdf2ImageConverter(); } if (extendName == ".ppt" || extendName == ".pptx") { return new Ppt2ImageConverter(); } if (extendName == ".xls" || extendName == ".xlsx") { return new Xls2ImageConverter(); } return null; } public bool Support(string extendName) { return extendName == ".doc" || extendName == ".docx" || extendName == ".pdf" || extendName == ".ppt" || extendName == ".pptx" || extendName == ".rar"; } } #endregion #region 将word⽂档转换为图⽚ public class Word2ImageConverter : IImageConverter { private bool cancelled = false; public event CbGeneric ProgressChanged; public event CbGeneric ConvertSucceed; public event CbGeneric ConvertFailed; public void Cancel() { if (led) { return; } led = true; } public void ConvertToImage(string originFilePath, string imageOutputDirPath) { led = false; ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, null, 200); } /// /// 将Word⽂档转换为图⽚的⽅法

///

/// Word⽂件路径 /// 图⽚输出路径,如果为空,默认值为Word所在路径

/// 从PDF⽂档的第⼏页开始转换,如果为0,默认值为1 /// 从PDF⽂档的第⼏页开始停⽌转换,如果为0,默认值为Word总页数 /// 设置所需图⽚格式,如果为null,默认格式为PNG /// 设置图⽚的像素,数字越⼤越清晰,如果为0,默认值为128,建议最⼤值不要超过1024 private void ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution) { try { dsLicense(); nt doc = new nt(wordInputPath); if (doc == null) { throw new Exception("Word⽂件⽆效或者Word⽂件被加密!"); } if (().Length == 0) { imageOutputDirPath = ectoryName(wordInputPath); } if (!(imageOutputDirPath)) { Directory(imageOutputDirPath); } if (startPageNum <= 0) { startPageNum = 1; } if (endPageNum > unt || endPageNum <= 0) { endPageNum = unt; } if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; } if (imageFormat == null) { imageFormat = ; } if (resolution <= 0) { resolution = 128; } string imageName = eNameWithoutExtension(eNameWithoutExtension(wordInputPath)); //string imageName = eNameWithoutExtension(wordInputPath); aveOptions imageSaveOptions = new aveOptions(); tion = resolution; for (int i = startPageNum; i <= endPageNum; i++) { if (led) { break; } MemoryStream stream = new MemoryStream(); dex = i - 1; //string imgPath = e(imageOutputDirPath, imageName) + "_" + ng("000") + "." + ng(); string imgPath = e(imageOutputDirPath, "A") + "_" + i + ".Png"; (stream, imageSaveOptions); img = ream(stream); Bitmap bm = (img, 0.6f); (imgPath, imageFormat); e(); e(); e(); (200); if (ssChanged != null) { ssChanged(i - 1, endPageNum); } } if (led) { return; } if (tSucceed != null) { tSucceed(); } } catch (Exception ex) { if (tFailed != null) { tFailed(e); } } } } #endregion #region 将pdf⽂档转换为图⽚ public class Pdf2ImageConverter : IImageConverter { private bool cancelled = false; public event CbGeneric ProgressChanged; public event CbGeneric ConvertSucceed; public event CbGeneric ConvertFailed; public void Cancel() { if (led) { return; } led = true; } public void ConvertToImage(string originFilePath, string imageOutputDirPath) { led = false; ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200); } ///

/// 将pdf⽂档转换为图⽚的⽅法

///

/// pdf⽂件路径 /// 图⽚输出路径,如果为空,默认值为pdf所在路径

/// 从PDF⽂档的第⼏页开始转换,如果为0,默认值为1 /// 从PDF⽂档的第⼏页开始停⽌转换,如果为0,默认值为pdf总页数

/// 设置图⽚的像素,数字越⼤越清晰,如果为0,默认值为128,建议最⼤值不要超过1024 private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution) { try { License(); nt doc = new nt(originFilePath); if (doc == null) { throw new Exception("pdf⽂件⽆效或者pdf⽂件被加密!"); } if (().Length == 0) { imageOutputDirPath = ectoryName(originFilePath); } if (!(imageOutputDirPath)) { Directory(imageOutputDirPath); } if (startPageNum <= 0) { startPageNum = 1; } if (endPageNum > || endPageNum <= 0) { endPageNum = ; } if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; } if (resolution <= 0) { resolution = 128; } string imageNamePrefix = eNameWithoutExtension(eNameWithoutExtension(originFilePath)); for (int i = startPageNum; i <= endPageNum; i++) { if (led) { break; } MemoryStream stream = new MemoryStream(); //string imgPath = e(imageOutputDirPath, imageNamePrefix) + "_" + ng("000") + ".Png"; string imgPath = e(imageOutputDirPath, "A") + "_" + i + ".Png"; tion reso = new tion(resolution); vice jpegDevice = new vice(reso, 100); s([i], stream); Image img = ream(stream); Bitmap bm = (img, 0.6f); (imgPath, ); e(); e(); e(); (200); if (ssChanged != null) { ssChanged(i - 1, endPageNum); } } if (led) { return; } if (tSucceed != null) { tSucceed(); } } catch (Exception ex) { if (tFailed != null) { tFailed(e); } } } } #endregion #region 将ppt⽂档转换为图⽚ public class Ppt2ImageConverter : IImageConverter { private Pdf2ImageConverter pdf2ImageConverter; public event CbGeneric ProgressChanged; public event CbGeneric ConvertSucceed; public event CbGeneric ConvertFailed; public void Cancel() { if (2ImageConverter != null) { (); } } public void ConvertToImage(string originFilePath, string imageOutputDirPath) { ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200); } ///

/// 将pdf⽂档转换为图⽚的⽅法

///

/// ppt⽂件路径 /// 图⽚输出路径,如果为空,默认值为pdf所在路径

/// 从PDF⽂档的第⼏页开始转换,如果为0,默认值为1 /// 从PDF⽂档的第⼏页开始停⽌转换,如果为0,默认值为pdf总页数

/// 设置图⽚的像素,数字越⼤越清晰,如果为0,默认值为128,建议最⼤值不要超过1024 private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution) { try { desLicense(); tation doc = new tation(originFilePath); if (doc == null) { throw new Exception("ppt⽂件⽆效或者ppt⽂件被加密!"); } if (().Length == 0) { imageOutputDirPath = ectoryName(originFilePath); } if (!(imageOutputDirPath)) { Directory(imageOutputDirPath); } if (startPageNum <= 0) { startPageNum = 1; } if (endPageNum > || endPageNum <= 0) { endPageNum = ; } if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; } if (resolution <= 0) { resolution = 128; } //先将ppt转换为pdf临时⽂件 string tmpPdfPath = originFilePath + ".pdf"; (tmpPdfPath, ); //再将pdf转换为图⽚ Pdf2ImageConverter converter = new Pdf2ImageConverter(); tFailed += new CbGeneric(converter_ConvertFailed); tSucceed += new CbGeneric(converter_ConvertSucceed); ssChanged += new CbGeneric(converter_ProgressChanged); tToImage(tmpPdfPath, imageOutputDirPath); //删除pdf临时⽂件 (tmpPdfPath); if (tSucceed != null) { tSucceed(); } } catch (Exception ex) { if (tFailed != null) { tFailed(e); } } 2ImageConverter = null; } void converter_ProgressChanged(int done, int total) { if (ssChanged != null) { ssChanged(done, total); } } void converter_ConvertSucceed() { if (tSucceed != null) { tSucceed(); } } void converter_ConvertFailed(string msg) { if (tFailed != null) { tFailed(msg); } } } #endregion #region Excel public class Xls2ImageConverter : IImageConverter { private Xls2ImageConverter xls2ImageConverter; public event CbGeneric ProgressChanged; public event CbGeneric ConvertSucceed; public event CbGeneric ConvertFailed; public void Cancel() { if (2ImageConverter != null) { (); } } public void ConvertToImage(string originFilePath, string imageOutputDirPath) { ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200); } private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution) { try { lsLicense(); ok excel = new Workbook(originFilePath); if (excel == null) { throw new Exception("excel⽂件⽆效或者excel⽂件被加密!"); } if (().Length == 0) { imageOutputDirPath = ectoryName(originFilePath); } if (!(imageOutputDirPath)) { Directory(imageOutputDirPath); } if (startPageNum <= 0) { startPageNum = 1; } if (endPageNum > || endPageNum <= 0) { endPageNum = ; } if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; } if (resolution <= 0) { resolution = 128; } //先将excel转换为pdf临时⽂件 string tmpPdfPath = originFilePath + ".pdf"; (tmpPdfPath, ); //再将pdf转换为图⽚ Pdf2ImageConverter converter = new Pdf2ImageConverter(); tFailed += new CbGeneric(converter_ConvertFailed); tSucceed += new CbGeneric(converter_ConvertSucceed); ssChanged += new CbGeneric(converter_ProgressChanged); tToImage(tmpPdfPath, imageOutputDirPath); //删除pdf临时⽂件 (tmpPdfPath); if (tSucceed != null) { tSucceed(); } } catch (Exception ex) { if (tFailed != null) { tFailed(e); } } 2ImageConverter = null; } void converter_ProgressChanged(int done, int total) { if (ssChanged != null) { ssChanged(done, total); } } void converter_ConvertSucceed() { if (tSucceed != null) { tSucceed(); } } void converter_ConvertFailed(string msg) { if (tFailed != null) { tFailed(msg); } } } #endregion}

using System;using c;using ;using ;using ;using ;using ;namespace ntManager{ public static class AsposeLicenseHelper { public const string Key = "PExpY2Vuc2U+DQogIDxEYXRhPg0KICAgIDxMaWNlbnNlZFRvPkFzcG9zZSBTY290bGFuZCB" + "UZWFtPC9MaWNlbnNlZFRvPg0KICAgIDxFbWFpbFRvPmJpbGx5Lmx1bmRpZUBhc3Bvc2UuY2" + "9tPC9FbWFpbFRvPg0KICAgIDxMaWNlbnNlVHlwZT5EZXZlbG9wZXIgT0VNPC9MaWNlbnNlV" + "HlwZT4NCiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1p" + "dGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+DQogICAgPE9yZGVySUQ+MTQ" + "wNDA4MDUyMzI0PC9PcmRlcklEPg0KICAgIDxVc2VySUQ+OTQyMzY8L1VzZXJJRD4NCiAgIC" + "A8T0VNPlRoaXMgaXMgYSByZWRpc3RyaWJ1dGFibGUgbGljZW5zZTwvT0VNPg0KICAgIDxQc" + "m9kdWN0cz4NCiAgICAgIDxQcm9kdWN0PkFzcG9zZS5Ub3RhbCBmb3IgLk5FVDwvUHJvZHVj" + "dD4NCiAgICA8L1Byb2R1Y3RzPg0KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl" + "0aW9uVHlwZT4NCiAgICA8U2VyaWFsTnVtYmVyPjlhNTk1NDdjLTQxZjAtNDI4Yi1iYTcyLT" + "djNDM2OGYxNTFkNzwvU2VyaWFsTnVtYmVyPg0KICAgIDxTdWJzY3JpcHRpb25FeHBpcnk+M" + "jAxNTEyMzE8L1N1YnNjcmlwdGlvbkV4cGlyeT4NCiAgICA8TGljZW5zZVZlcnNpb24+My4w" + "PC9MaWNlbnNlVmVyc2lvbj4NCiAgICA8TGljZW5zZUluc3RydWN0aW9ucz5odHRwOi8vd3d" + "3LmFzcG9zZS5jb20vY29ycG9yYXRlL3B1cmNoYXNlL2xpY2Vuc2UtaW5zdHJ1Y3Rpb25zLm" + "FzcHg8L0xpY2Vuc2VJbnN0cnVjdGlvbnM+DQogIDwvRGF0YT4NCiAgPFNpZ25hdHVyZT5GT" + "zNQSHNibGdEdDhGNTlzTVQxbDFhbXlpOXFrMlY2RThkUWtJUDdMZFRKU3hEaWJORUZ1MXpP" + "aW5RYnFGZkt2L3J1dHR2Y3hvUk9rYzF0VWUwRHRPNmNQMVpmNkowVmVtZ1NZOGkvTFpFQ1R" + "Hc3pScUpWUVJaME1vVm5CaHVQQUprNWVsaTdmaFZjRjhoV2QzRTRYUTNMemZtSkN1YWoyTk" + "V0ZVJpNUhyZmc9PC9TaWduYXR1cmU+DQo8L0xpY2Vuc2U+"; public static Stream LStream = (Stream)new MemoryStream(se64String(Key)); static readonly string LicensePath = ationBase + ""; public static void SetWordsLicense() { var l=new License();

ense(LicensePath); } public static void SetPdfLicense() { var l = new e(); ense(LicensePath); } public static void SetSlidesLicense() { var l = new e(); ense(LicensePath); } ///

/// Excel /// public static void SetCellsLicense() { var l = new e(); ense(LicensePath); } }}

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688384729a130040.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信