.NET Core Aspose Word(.doc,docx)转成pdf文件
一、 Aspose Word(.doc,docx)转成pdf文件
.NET Core中,你可以使用Aspose.Words库将Word文档(.doc或.docx格式)转换成PDF文件。Aspose.Words是一个商业库,提供了广泛的文档处理功能,包括读取、修改和保存不同格式的文档,同时支持文档的转换。利用Aspose组件将word转成pdf文件,转换的性能比较好,转换的比较快,格式兼容性也挺好。另外服务器或PC上不用安装msoffice word软件就可以转换。
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/article/106/
更多:
FreeSpire.doc,Spire.Pdf PDF转图片,Word转图片,Txt转图片
浙公网安备 33010602011771号