aspose使⽤代码(去除⽔印)(在线显⽰各种格式⽂件)(各种格式⽂件转
pdf)(pdf转图⽚)
1、去除⽔印代码
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+";
//使⽤下⾯代码前都加这个下⾯的
// new Aspose.Slides.License().SetLicense(new MemoryStream(Convert.FromBase64String(Key))); //这个是sldes的,其他类似
2、配套代码(c#)
using Aspose.Cells;
using Aspose.Words;
using Aspose.Words.Fonts;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BorderType = Aspose.Cells.BorderType;
namespace manager.Controllers
{
public class topdfController : ApiController //webapi
{
public const string Key =
"PExpY2Vuc2U+DQogIDxEYXRhPg0KICAgIDxMaWNlbnNlZFRvPkFzcG9zZSBTY290bGFuZCB"+
"UZWFtPC9MaWNlbnNlZFRvPg0KICAgIDxFbWFpbFRvPmJpbGx5Lmx1bmRpZUBhc3Bvc2UuY2"+
"9tPC9FbWFpbFRvPg0KICAgIDxMaWNlbnNlVHlwZT5EZXZlbG9wZXIgT0VNPC9MaWNlbnNlV"+
"HlwZT4NCiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1p"+
"dGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+DQogICAgPE9yZGVySUQ+M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N1YWoyTk"+ "V0ZVJpNUhyZmc9PC9TaWduYXR1cmU+DQo8L0xpY2Vuc2U+";
#region把word转化成Pdf
//转换成pdf
// GET api/changepdf
[HttpGet]
public string changepdf(string ss)
{
string path = System.Web.Hosting.HostingEnvironment.MapPath(ss);//ss是⽂件名 gg.docx这样文科女生学什么专业好
//return path;
try
{
string inpdf = path;
string outpdf =@"/filedata/1111.pdf";//输出⽂件
new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(Key)));
string outtopdf = System.Web.Hosting.HostingEnvironment.MapPath(outpdf);//计算出绝对路径
//ExcelConvert.ExcelConvertManage.StartConvert(inpdf, outpdf);
西双版纳旅游攻略必去景点
Document doc =new Document(inpdf);
doc.Save(outtopdf, Aspose.Words.SaveFormat.Pdf);
return outpdf;
}
catch(Exception ex)
{
return ex.Message;
}
}
#endregion
#region ppt转换为pdf
/
国家安全教育手抄报/[Route("topdf/ppttopdf")]
[HttpGet]
public string ppttopdf(string ss)
{
string path = System.Web.Hosting.HostingEnvironment.MapPath(ss);
//return path;
try
{
string inpdf = path;
string outpdf =@"/filedata/1111.pdf";
new Aspose.Slides.License().SetLicense(new MemoryStream(Convert.FromBase64String(Key)));
string outtopdf = System.Web.Hosting.HostingEnvironment.MapPath(outpdf);
//AsposeLicenseHelper.SetSlidesLicense();
Aspose.Slides.Presentation doc =new Aspose.Slides.Presentation(inpdf);
Aspose.Slides.Presentation doc =new Aspose.Slides.Presentation(inpdf);
doc.Save(outtopdf, Aspose.Slides.Export.SaveFormat.Pdf);
//doc.Save(outtopdf, Aspose.Words.SaveFormat.Pdf);
return outpdf;
}
catch(Exception ex)
{
return ex.Message;
}
}
#endregion
#region excel转换成pdf
//[Route("topdf/exceltopdf")]
[HttpGet]
public string exceltopdf(string ss)
{
string path = System.Web.Hosting.HostingEnvironment.MapPath(ss);
//return path;
try
{
string inpdf = path;
string outpdf =@"/filedata/1111.pdf";
new Aspose.Cells.License().SetLicense(new MemoryStream(Convert.FromBase64String(Key)));
string outtopdf = System.Web.Hosting.HostingEnvironment.MapPath(outpdf);
Aspose.Cells.Workbook excel =new Workbook(inpdf);
excel.Save(outtopdf, Aspose.Cells.SaveFormat.Pdf);
return outpdf;
}
catch(Exception ex)
{
return ex.Message;
}
}
#endregion
}
}
3、aspose操作代码(word,excel,ppt转pdf然后再转图⽚显⽰)(这是我转来收藏的代码)
using Aspose.Cells;
using Aspose.Words.Saving;
using ESBasic;
using OMCS.Engine.WhiteBoard;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using SMES.LocaleManagerWeb.DoucmentManager;
using ImageSaveOptions = Aspose.Words.Saving.ImageSaveOptions;
using SaveFormat = Aspose.Words.SaveFormat;
namespace SMES.LocaleManagerWeb
{
public partial class Upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//new Aspose.Words.License().SetLicense(AsposeLicenseHelper.LStream);
//new Aspose.Cells.License().SetLicense(AsposeLicenseHelper.LStream);
//new Aspose.Slides.License().SetLicense(AsposeLicenseHelper.LStream);
及第花是哪种花/
/new Aspose.Pdf.License().SetLicense(AsposeLicenseHelper.LStream);
string documentExts ="pdf|doc|docx|xlsx|xls|ppt|pptx";
string imageExts ="jpeg|png|jpg|bmp";
string otherExts ="pdf|xls|xlsx|ppt|pptx";
HttpFileCollection files = Request.Files;//这⾥只能⽤<input type="file" />才能有效果,因为服务器控件是HttpInputFile类型
FileUpModel model =new FileUpModel();
if(files.Count ==0|| files[0].InputStream.Length ==0)
{
model =new FileUpModel(){ State =0, Error ="没有到⽂件"};
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(model));
//Response.End();
return;
}
try梦见同事死了
{
HttpPostedFile file = files[0];
model.Extension =GetExtension(file.FileName);
if((documentExts +"|"+ imageExts +"|"+ otherExts).IndexOf(model.Extension.ToLower())==-1)
{
model =new FileUpModel(){ State =0, Error ="不允许上传"+ model.Extension +"类型⽂件"};
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(model));
//Response.End();
return;
}
model.Size = file.ContentLength /1024;
DateTime nowtime = DateTime.Now;
string dic ="/UpLoadFile/"+ nowtime.ToString("yy/MM/dd/");
string newFilename ="/UpLoadFile/"+ nowtime.ToString("yy/MM/dd/")+ Guid.NewGuid().ToString("N")+"."+ model.Extension;
string filepath = Server.MapPath("~"+ newFilename);
if(!System.IO.Directory.Exists(Server.MapPath(dic)))
{
System.IO.Directory.CreateDirectory(Server.MapPath(dic));
}
file.SaveAs(filepath);
//将⽂档装换为图图⽚
if(documentExts.IndexOf(model.Extension.ToLower())!=-1)
{
腊八的祝福语怎么说//图⽚⽬录
string imagedic = newFilename.Replace("."+ model.Extension,"");
IImageConverterFactory f =new ImageConverterFactory();
IImageConverter imageConverter = f.CreateImageConverter("."+ model.Extension);
string opath = Server.MapPath("~"+ newFilename);
string imgpath = Server.MapPath("~"+ imagedic +"/");
Thread thd =new Thread(new ThreadStart(()=>{ imageConverter.ConvertToImage(opath, imgpath);}));
thd.Start();
//DocumentToImage(newFilename, imagedic);
//DocumentToImage(newFilename, imagedic);
model.ImagePath = imagedic;
}
model.State =1;
model.Path = newFilename;
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(model));
}
catch(Exception ee)
{
model =new FileUpModel(){ State =0, Error = ee.Message };
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(model));
Response.End();
}
}
private void DocumentToImage(string filename,string imagedic)
{
Thread thd =new Thread(new ThreadStart(()=>
{
ConvertWordToImage(Server.MapPath("~"+ filename), Server.MapPath("~"+ imagedic +"/"),"A",0,0, ImageFormat.Png,0);
}));
thd.Start();
}
private string GetExtension(string filename)
{
if(string.IsNullOrEmpty(filename))
return"";
string[] strs = filename.Split('.');
if(strs.Length >0)
{
return strs[strs.Length -1];
}
else
{
return"";
}
}
public void ConvertWordToImage(string wordInputPath,string imageOutputPath,
string imageName,int startPageNum,int endPageNum, ImageFormat imageFormat,float resolution)
{
try
{
AsposeLicenseHelper.SetWordsLicense();
/
/ open word file
Aspose.Words.Document doc =new Aspose.Words.Document(wordInputPath);
// validate parameter
if(doc ==null){throw new Exception("Word⽂件⽆效或者Word⽂件被加密!");}
if(imageOutputPath.Trim().Length ==0){ imageOutputPath = Path.GetDirectoryName(wordInputPath);}
if(!Directory.Exists(imageOutputPath)){ Directory.CreateDirectory(imageOutputPath);}
if(imageName.Trim().Length ==0){ imageName = Path.GetFileNameWithoutExtension(wordInputPath);}
if(startPageNum <=0){ startPageNum =1;}
if(endPageNum > doc.PageCount || endPageNum <=0){ endPageNum = doc.PageCount;}
if(startPageNum > endPageNum){int tempPageNum = startPageNum; startPageNum = endPageNu
m; endPageNum = startPageNum;} if(imageFormat ==null){ imageFormat = ImageFormat.Png;}
if(resolution <=0){ resolution =128;}
var imageSaveOptions =new ImageSaveOptions(GetSaveFormat(imageFormat))
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论