原文:https://www.cnblogs.com/qiwu1314/p/5899545.html?utm_source=itdadao&utm_medium=referral
下載Aspose.Words .dll http://pan.baidu.com/s/1c8659k
在vs2010中新建窗體應用程序,命名為 wordtopdf
添加Aspose.Words .dll 引用
編寫代碼
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Linq;
8 using System.Windows.Forms;
9 using System.IO;
10 using Aspose.Words;
11
12 namespace wordtopdf
13 {
14 public partial class Form1 : Form
15 {
16 public Form1()
17 {
18 InitializeComponent();
19 }
20
21 private void button1_Click(object sender, EventArgs e)
22 {
23 //讀取doc文檔
24 Document doc = new Document(@"C:\Users\Administrator\Desktop\123\123.doc");
25 //保存為PDF文件,此處的SaveFormat支持很多種格式,如圖片,epub,rtf 等等
26 doc.Save(@"C:\Users\Administrator\Desktop\temp.pdf", SaveFormat.Pdf);
27 }
28 }
29 }
點擊生成wordtopdf
其中遇到以下錯誤

原來是框架(.NET Framework 4 Client Profile)不合適,故換一種框架(點擊項目---wordtopdf屬性---目標框架---選擇.NET Framework 4)再次運行沒有錯誤

運行效果:


