C# net core API Word转PDF 无水印

/// <summary>
        /// Word转PDF 无水印 测试成功 20230204
        /// </summary>
        /// <param name="docFile"></param>
        /// <param name="pdfFile"></param>
        /// <returns></returns>
        public static ResultModel WordToPdfTest(string docFile, string pdfFile)
        {
            var resultModel = new ResultModel();
            resultModel.Log = "1,";

            //处理字体-取用户字体目录
            string userfontsfoloder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Microsoft\\Windows\\Fonts\\";
            ArrayList fontSources = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());
            Aspose.Words.Fonts.FolderFontSource folderFontSource = new Aspose.Words.Fonts.FolderFontSource(userfontsfoloder, true);
            fontSources.Add(folderFontSource);
            Aspose.Words.Fonts.FontSourceBase[] updatedFontSources = (Aspose.Words.Fonts.FontSourceBase[])fontSources.ToArray(typeof(Aspose.Words.Fonts.FontSourceBase));
            FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);
            //转换PDF文件
            Aspose.Words.Document doc = new Aspose.Words.Document(docFile);
            try
            {
                if (doc != null)
                {
                    doc.Save(pdfFile, Aspose.Words.SaveFormat.Pdf);
                }
                resultModel.Success = true;
            }
            catch (Exception ex)
            {
                resultModel.ErrorMsg = ex.Message;
            }
            if (doc != null)
            {
                doc.Clone();
                resultModel.Log += "7,Clone()";
            }
            return resultModel;
        }

相关DLL从百度网盘下载

链接:https://pan.baidu.com/s/13ZnUSWNt_xGbdAoDby9tUw?pwd=l4p1
提取码:l4p1

posted @ 2023-02-06 15:56  baivfhpwxf  阅读(306)  评论(0编辑  收藏  举报