Bootstrap
利用Aspose组件将word转成pdf文件,转换的性能比较好,转换的比较快,格式兼容性也挺好。另外服务器或PC上不用安装msoffice word软件就可以转换。下面分享一下.NET Core中调用Aspose组件转pdf代码。

1、Aspose组件下载

Aspose下载地址:https://products.aspose.com/words/net

破解版下载地址:https://download.csdn.net/download/yedajiang44/10667863 (aspose.words 18.7破解版含net 和 .net core 2.0版本)

官方文档地址:https://docs.aspose.com/display/wordsnet/Home

官方Demo代码:https://github.com/aspose-words/Aspose.Words-for-.NET

2、Word转Pdf代码

注意:除了引用Aspose.Words.dll,还要用Nuget安装System.Text.Encoding.CodePages和SkiaSharp

using Aspose.Words;
using System;
using System.IO;
namespace WordToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                if (args == null || args.Length < 2)
                    throw new ArgumentException("参数不正确!");
                var sourceFilePath = args[0];
                var objectFilePath = args[1];
                if (!File.Exists(sourceFilePath))
                    throw new FileNotFoundException("文件未找到", sourceFilePath);
                if (File.Exists(objectFilePath))
                    File.Delete(objectFilePath);
                WordToPdf(sourceFilePath, sourceFilePath);
                //WordToPdf(@"f:\1.doc", @"f:\1.pdf");
            }
            catch (Exception ex)
            {
                Console.Write("Error:{0}", ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
        public static void WordToPdf(string wordPath, string pdfPath)
        {
            try
            {
                //Aspose.Words.License lic = new Aspose.Words.License();
                //lic.SetLicense("Aspose.Total.lic");破解版不用设置license
                //打开word文件
                Document doc = new Aspose.Words.Document(wordPath);
                //验证参数
                if (doc == null) { throw new Exception("Word文件无效"); }
                doc.Save(pdfPath, Aspose.Words.SaveFormat.Pdf);//还可以改成其它格式
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
    }
}

3、本文项目代码下载

下载地址:https://www.cjavapy.com/download/5be403a1dc72d915fc310688/

相关文档:.NET Core Aspose Word(.doc,docx)文件加水印   

                  VS(Visual Studio)中Nuget的使用