首页 .Net .NET Core Aspose Word(.doc,docx)转成pdf文件

.NET Core Aspose Word(.doc,docx)转成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
{
    >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的使用

特别声明:本站部分内容收集于互联网是出于更直观传递信息的目的。该内容版权归原作者所有,并不代表本站赞同其观点和对其真实性负责。如该内容涉及任何第三方合法权利,请及时与824310991@qq.com联系,我们会及时反馈并处理完毕。