LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

C#使用aspose将Office文档转换为PDF代码(去除水印)

admin
2020年4月3日 22:4 本文热度 4206

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+MTQ" +

            "wNDA4MDUyMzI0PC9PcmRlcklEPg0KICAgIDxVc2VySUQ+OTQyMzY8L1VzZXJJRD4NCiAgIC" +

            "A8T0VNPlRoaXMgaXMgYSByZWRpc3RyaWJ1dGFibGUgbGljZW5zZTwvT0VNPg0KICAgIDxQc" +

            "m9kdWN0cz4NCiAgICAgIDxQcm9kdWN0PkFzcG9zZS5Ub3RhbCBmb3IgLk5FVDwvUHJvZHVj" +

            "dD4NCiAgICA8L1Byb2R1Y3RzPg0KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl" +

            "0aW9uVHlwZT4NCiAgICA8U2VyaWFsTnVtYmVyPjlhNTk1NDdjLTQxZjAtNDI4Yi1iYTcyLT" +

            "djNDM2OGYxNTFkNzwvU2VyaWFsTnVtYmVyPg0KICAgIDxTdWJzY3JpcHRpb25FeHBpcnk+M" +

            "jAxNTEyMzE8L1N1YnNjcmlwdGlvbkV4cGlyeT4NCiAgICA8TGljZW5zZVZlcnNpb24+My4w" +

            "PC9MaWNlbnNlVmVyc2lvbj4NCiAgICA8TGljZW5zZUluc3RydWN0aW9ucz5odHRwOi8vd3d" +

            "3LmFzcG9zZS5jb20vY29ycG9yYXRlL3B1cmNoYXNlL2xpY2Vuc2UtaW5zdHJ1Y3Rpb25zLm" +

            "FzcHg8L0xpY2Vuc2VJbnN0cnVjdGlvbnM+DQogIDwvRGF0YT4NCiAgPFNpZ25hdHVyZT5GT" +

            "zNQSHNibGdEdDhGNTlzTVQxbDFhbXlpOXFrMlY2RThkUWtJUDdMZFRKU3hEaWJORUZ1MXpP" +

            "aW5RYnFGZkt2L3J1dHR2Y3hvUk9rYzF0VWUwRHRPNmNQMVpmNkowVmVtZ1NZOGkvTFpFQ1R" +

            "Hc3pScUpWUVJaME1vVm5CaHVQQUprNWVsaTdmaFZjRjhoV2QzRTRYUTNMemZtSkN1YWoyTk" +

            "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);

                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

    }

}

配套aspose.dll
链接:https://pan.baidu.com/s/1kOG4rK7jxDk5yUjYhNa3VQ
提取码:g3iq

该文章在 2024/9/13 17:55:23 编辑过

全部评论1

admin
2020年4月3日 22:19
点击生成wordtopdf

其中遇到以下错误:


原来是框架(.NET Framework 4 Client Profile)不合适,故换一种框架(点击项目---wordtopdf属性---目标框架---选择.NET Framework 4)再次运行没有错误



该评论在 2020/4/3 22:20:48 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved