├── HEAD
├── WordConvertPDF.zip
├── WordToPDF
├── icon.ico
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── App.xaml
├── App.xaml.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
└── WordToPDF.csproj
├── Bin
├── WordConvertPDF.dll
├── Word转PDF V1.0.1.exe
└── Microsoft.Office.Interop.Word.dll
├── WordConvertPDF
├── Properties
│ └── AssemblyInfo.cs
├── WordConvertPDF.csproj
└── WordToPDFHelper.cs
├── LICENSE
├── WordConvertPDF.sln
└── .gitignore
/HEAD:
--------------------------------------------------------------------------------
1 | 昨天有一朋友让我帮忙找一款Word转PDF的软件,今天自己捣鼓出点成果封装个Helper供大家使用
2 |
3 | 明天做一个实用小软件供大家使用~
4 |
--------------------------------------------------------------------------------
/WordConvertPDF.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dunitian/WordConvertPDF/HEAD/WordConvertPDF.zip
--------------------------------------------------------------------------------
/WordToPDF/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dunitian/WordConvertPDF/HEAD/WordToPDF/icon.ico
--------------------------------------------------------------------------------
/Bin/WordConvertPDF.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dunitian/WordConvertPDF/HEAD/Bin/WordConvertPDF.dll
--------------------------------------------------------------------------------
/Bin/Word转PDF V1.0.1.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dunitian/WordConvertPDF/HEAD/Bin/Word转PDF V1.0.1.exe
--------------------------------------------------------------------------------
/Bin/Microsoft.Office.Interop.Word.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dunitian/WordConvertPDF/HEAD/Bin/Microsoft.Office.Interop.Word.dll
--------------------------------------------------------------------------------
/WordToPDF/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/WordToPDF/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/WordToPDF/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/WordToPDF/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WordToPDF
10 | {
11 | ///
12 | /// App.xaml 的交互逻辑
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/WordToPDF/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/WordToPDF/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WordToPDF.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/WordConvertPDF/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("WordConvertPDF")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("WordConvertPDF")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("3f62a100-6a59-4c65-b5be-9f7c50b3bf2e")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 dunitian
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/WordToPDF/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的常规信息通过以下
8 | // 特性集控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("WordConvertPDF")]
11 | [assembly: AssemblyDescription("Word转PDF")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("逆天有限公司")]
14 | [assembly: AssemblyProduct("WordToPDF V1.0")]
15 | [assembly: AssemblyCopyright("Copyright © DNT 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // 将 ComVisible 设置为 false 使此程序集中的类型
20 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
21 | // 则将该类型上的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请在
25 | // 中的 .csproj 文件中
26 | //设置 CultureYouAreCodingWith。 例如,如果您在源文件中
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(在页面或应用程序资源词典中
37 | // 未找到某个资源的情况下使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(在页面、应用程序或任何主题特定资源词典中
40 | // 未找到某个资源的情况下使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下面四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
52 | // 方法是按如下所示使用“*”:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/WordToPDF/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WordToPDF.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WordToPDF.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/WordConvertPDF.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordToPDF", "WordToPDF\WordToPDF.csproj", "{54E68A81-8599-4813-B31A-BB9B9430A038}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordConvertPDF", "WordConvertPDF\WordConvertPDF.csproj", "{E5FA4FB7-12CE-4507-84A8-D0A477F14118}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|Mixed Platforms = Debug|Mixed Platforms
14 | Debug|x86 = Debug|x86
15 | Release|Any CPU = Release|Any CPU
16 | Release|Mixed Platforms = Release|Mixed Platforms
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
23 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
24 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Debug|x86.ActiveCfg = Debug|Any CPU
25 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Release|Any CPU.Build.0 = Release|Any CPU
27 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
28 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Release|Mixed Platforms.Build.0 = Release|Any CPU
29 | {54E68A81-8599-4813-B31A-BB9B9430A038}.Release|x86.ActiveCfg = Release|Any CPU
30 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
33 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
34 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Debug|x86.ActiveCfg = Debug|Any CPU
35 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
38 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Release|Mixed Platforms.Build.0 = Release|Any CPU
39 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}.Release|x86.ActiveCfg = Release|Any CPU
40 | EndGlobalSection
41 | GlobalSection(SolutionProperties) = preSolution
42 | HideSolutionNode = FALSE
43 | EndGlobalSection
44 | EndGlobal
45 |
--------------------------------------------------------------------------------
/WordConvertPDF/WordConvertPDF.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E5FA4FB7-12CE-4507-84A8-D0A477F14118}
8 | Library
9 | Properties
10 | WordConvertPDF
11 | WordConvertPDF
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | False
36 | True
37 | bin\Release\Microsoft.Office.Interop.Word.dll
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
59 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 |
--------------------------------------------------------------------------------
/WordToPDF/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WordToPDF
17 | {
18 | ///
19 | /// MainWindow.xaml 的交互逻辑
20 | ///
21 | public partial class MainWindow : Window
22 | {
23 | public MainWindow()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void WordBtn_Click(object sender, RoutedEventArgs e)
29 | {
30 | #region OldCode
31 | ////打开对话框
32 | //Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
33 | ////过滤器
34 | //dialog.Filter = "文档类型|*.doc;*.docx";
35 | ////允许选多个文件
36 | //dialog.Multiselect = true;
37 | ////是否打开
38 | //var result = dialog.ShowDialog();
39 | //if (result == true)
40 | //{
41 | // //总计
42 | // int total = 0;
43 | // //保存路径
44 | // string savePath = string.Empty;
45 | // //获得文件
46 | // string[] files = dialog.FileNames;
47 | // System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
48 | // watch.Start();
49 | // for (int i = 0; i < files.Length; i++)
50 | // {
51 | // savePath = System.IO.Path.GetDirectoryName(files[0]);
52 | // //文件名
53 | // string saveName = System.IO.Path.GetFileNameWithoutExtension(files[i]) + ".pdf";
54 | // //存在就转换
55 | // if (System.IO.File.Exists(files[i]))
56 | // {
57 | // if (WordConvertPDF.WordToPDFHelper.WordToPDF(files[i], savePath + @"\" + saveName))
58 | // {
59 | // total++;
60 | // }
61 | // }
62 | // }
63 | // watch.Stop();
64 | // MessageBox.Show("成功转换了:" + total + " 个文件;耗时:" + watch.Elapsed, "逆天友情提醒");
65 | // if (!string.IsNullOrEmpty(savePath))
66 | // {
67 | // System.Diagnostics.Process.Start(savePath);
68 | // }
69 | //}
70 | #endregion
71 |
72 | #region NewCode
73 | //打开对话框
74 | Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
75 | //过滤器
76 | dialog.Filter = "文档类型|*.doc;*.docx";
77 | //允许选多个文件
78 | dialog.Multiselect = true;
79 | //是否打开
80 | var result = dialog.ShowDialog();
81 | if (result == true)
82 | {
83 | //保存路径
84 | string savePath = string.Empty;
85 | //获得文件
86 | string[] files = dialog.FileNames;
87 |
88 | savePath = System.IO.Path.GetDirectoryName(files[0]);
89 |
90 | if (!string.IsNullOrEmpty(savePath))
91 | {
92 | System.Diagnostics.Process.Start(savePath);
93 | }
94 | System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
95 | watch.Start();
96 | int total = WordConvertPDF.WordToPDFHelper.WordsToPDFs(files, savePath);
97 | watch.Stop();
98 | MessageBox.Show("成功转换了:" + total + " 个文件;耗时:" + watch.Elapsed, "逆天友情提醒");
99 | }
100 | #endregion
101 | }
102 |
103 | private void PdfBtn_Click(object sender, RoutedEventArgs e)
104 | {
105 | MessageBox.Show("V1.1版本的时候会公开~敬请期待", "逆天友情提醒");
106 | System.Diagnostics.Process.Start("http://www.dkill.net");
107 | }
108 |
109 | private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
110 | {
111 | System.Diagnostics.Process.Start("https://github.com/dunitian/WordConvertPDF");
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/WordToPDF/WordToPDF.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {54E68A81-8599-4813-B31A-BB9B9430A038}
8 | WinExe
9 | Properties
10 | WordToPDF
11 | WordToPDF
12 | v4.0
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | icon.ico
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | 4.0
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | MSBuild:Compile
58 | Designer
59 |
60 |
61 | MSBuild:Compile
62 | Designer
63 |
64 |
65 | App.xaml
66 | Code
67 |
68 |
69 | MainWindow.xaml
70 | Code
71 |
72 |
73 |
74 |
75 | Code
76 |
77 |
78 | True
79 | True
80 | Resources.resx
81 |
82 |
83 | True
84 | Settings.settings
85 | True
86 |
87 |
88 | ResXFileCodeGenerator
89 | Resources.Designer.cs
90 |
91 |
92 | SettingsSingleFileGenerator
93 | Settings.Designer.cs
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | {e5fa4fb7-12ce-4507-84a8-d0a477f14118}
103 | WordConvertPDF
104 |
105 |
106 |
107 |
108 |
109 |
110 |
117 |
--------------------------------------------------------------------------------
/WordToPDF/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/WordConvertPDF/WordToPDFHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.Office.Interop.Word;
7 | using System.IO;
8 |
9 | namespace WordConvertPDF
10 | {
11 | public static class WordToPDFHelper
12 | {
13 | ///
14 | /// Word转换成PDF(单个文件转换推荐使用)
15 | ///
16 | /// 载入完整路径
17 | /// 保存完整路径
18 | /// 初始页码(默认为第一页[0])
19 | /// 结束页码(默认为最后一页)
20 | public static bool WordToPDF(string inputPath, string outputPath, int startPage = 0, int endPage = 0)
21 | {
22 | bool b = true;
23 |
24 | #region 初始化
25 | //初始化一个application
26 | Application wordApplication = new Application();
27 | //初始化一个document
28 | Document wordDocument = null;
29 | #endregion
30 |
31 | #region 参数设置~~我去累死宝宝了~~(所谓的参数都是根据这个方法来的:ExportAsFixedFormat)
32 | //word路径
33 | object wordPath = Path.GetFullPath(inputPath);
34 |
35 | //输出路径
36 | string pdfPath = Path.GetFullPath(outputPath);
37 |
38 | //导出格式为PDF
39 | WdExportFormat wdExportFormat = WdExportFormat.wdExportFormatPDF;
40 |
41 | //导出大文件
42 | WdExportOptimizeFor wdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
43 |
44 | //导出整个文档
45 | WdExportRange wdExportRange = WdExportRange.wdExportAllDocument;
46 |
47 | //开始页码
48 | int startIndex = startPage;
49 |
50 | //结束页码
51 | int endIndex = endPage;
52 |
53 | //导出不带标记的文档(这个可以改)
54 | WdExportItem wdExportItem = WdExportItem.wdExportDocumentContent;
55 |
56 | //包含word属性
57 | bool includeDocProps = true;
58 |
59 | //导出书签
60 | WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
61 |
62 | //默认值
63 | object paramMissing = Type.Missing;
64 |
65 | #endregion
66 |
67 | #region 转换
68 | try
69 | {
70 | //打开word
71 | wordDocument = wordApplication.Documents.Open(ref wordPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);
72 | //转换成指定格式
73 | if (wordDocument != null)
74 | {
75 | wordDocument.ExportAsFixedFormat(pdfPath, wdExportFormat, false, wdExportOptimizeFor, wdExportRange, startIndex, endIndex, wdExportItem, includeDocProps, true, paramCreateBookmarks, true, true, false, ref paramMissing);
76 | }
77 | }
78 | catch (Exception ex)
79 | {
80 | b = false;
81 | }
82 | finally
83 | {
84 | //关闭
85 | if (wordDocument != null)
86 | {
87 | wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
88 | wordDocument = null;
89 | }
90 |
91 | //退出
92 | if (wordApplication != null)
93 | {
94 | wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
95 | wordApplication = null;
96 | }
97 | }
98 |
99 | return b;
100 | #endregion
101 | }
102 |
103 | ///
104 | /// Word转换成PDF(批量文件转换推荐使用)
105 | ///
106 | /// 文件完整路径
107 | /// 保存路径
108 | public static int WordsToPDFs(string[] inputPaths, string outputPath)
109 | {
110 | int count = 0;
111 |
112 | #region 初始化
113 | //初始化一个application
114 | Application wordApplication = new Application();
115 | //初始化一个document
116 | Document wordDocument = null;
117 | #endregion
118 |
119 | //默认值
120 | object paramMissing = Type.Missing;
121 |
122 | for (int i = 0; i < inputPaths.Length; i++)
123 | {
124 | #region 参数设置~~我去累死宝宝了~~(所谓的参数都是根据这个方法来的:ExportAsFixedFormat)
125 | //word路径
126 | object wordPath = Path.GetFullPath(inputPaths[i]);
127 |
128 | //获取文件名
129 | string outputName = Path.GetFileNameWithoutExtension(inputPaths[i]);
130 |
131 | //输出路径
132 | string pdfPath = Path.GetFullPath(outputPath + @"\" + outputName + ".pdf");
133 |
134 | //导出格式为PDF
135 | WdExportFormat wdExportFormat = WdExportFormat.wdExportFormatPDF;
136 |
137 | //导出大文件
138 | WdExportOptimizeFor wdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
139 |
140 | //导出整个文档
141 | WdExportRange wdExportRange = WdExportRange.wdExportAllDocument;
142 |
143 | //开始页码
144 | int startIndex = 0;
145 |
146 | //结束页码
147 | int endIndex = 0;
148 |
149 | //导出不带标记的文档(这个可以改)
150 | WdExportItem wdExportItem = WdExportItem.wdExportDocumentContent;
151 |
152 | //包含word属性
153 | bool includeDocProps = true;
154 |
155 | //导出书签
156 | WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
157 |
158 | #endregion
159 |
160 | #region 转换
161 | try
162 | {
163 | //打开word
164 | wordDocument = wordApplication.Documents.Open(ref wordPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);
165 | //转换成指定格式
166 | if (wordDocument != null)
167 | {
168 | wordDocument.ExportAsFixedFormat(pdfPath, wdExportFormat, false, wdExportOptimizeFor, wdExportRange, startIndex, endIndex, wdExportItem, includeDocProps, true, paramCreateBookmarks, true, true, false, ref paramMissing);
169 | }
170 | count++;
171 | }
172 | catch (Exception ex)
173 | {
174 | }
175 | finally
176 | {
177 | //关闭
178 | if (wordDocument != null)
179 | {
180 | wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
181 | wordDocument = null;
182 | }
183 | }
184 | }
185 |
186 | //退出
187 | if (wordApplication != null)
188 | {
189 | wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
190 | wordApplication = null;
191 | }
192 | return count;
193 | #endregion
194 | }
195 |
196 | #region 其他
197 | ///
198 | /// Word转换成PDF(带日记)
199 | ///
200 | /// 载入完整路径
201 | /// 保存完整路径
202 | /// 转换日记
203 | /// 初始页码(默认为第一页[0])
204 | /// 结束页码(默认为最后一页)
205 | public static void WordToPDFCreateLog(string inputPath, string outputPath, out string log, int startPage = 0, int endPage = 0)
206 | {
207 | log = "success";
208 |
209 | #region 初始化
210 | //初始化一个application
211 | Application wordApplication = new Application();
212 | //初始化一个document
213 | Document wordDocument = null;
214 | #endregion
215 |
216 | #region 参数设置~~我去累死宝宝了~~
217 | //word路径
218 | object wordPath = Path.GetFullPath(inputPath);
219 |
220 | //输出路径
221 | string pdfPath = Path.GetFullPath(outputPath);
222 |
223 | //导出格式为PDF
224 | WdExportFormat wdExportFormat = WdExportFormat.wdExportFormatPDF;
225 |
226 | //导出大文件
227 | WdExportOptimizeFor wdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
228 |
229 | //导出整个文档
230 | WdExportRange wdExportRange = WdExportRange.wdExportAllDocument;
231 |
232 | //开始页码
233 | int startIndex = startPage;
234 |
235 | //结束页码
236 | int endIndex = endPage;
237 |
238 | //导出不带标记的文档(这个可以改)
239 | WdExportItem wdExportItem = WdExportItem.wdExportDocumentContent;
240 |
241 | //包含word属性
242 | bool includeDocProps = true;
243 |
244 | //导出书签
245 | WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
246 |
247 | //默认值
248 | object paramMissing = Type.Missing;
249 |
250 | #endregion
251 |
252 | #region 转换
253 | try
254 | {
255 | //打开word
256 | wordDocument = wordApplication.Documents.Open(ref wordPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);
257 | //转换成指定格式
258 | if (wordDocument != null)
259 | {
260 | wordDocument.ExportAsFixedFormat(pdfPath, wdExportFormat, false, wdExportOptimizeFor, wdExportRange, startIndex, endIndex, wdExportItem, includeDocProps, true, paramCreateBookmarks, true, true, false, ref paramMissing);
261 | }
262 | }
263 | catch (Exception ex)
264 | {
265 | if (ex != null) { log = ex.ToString(); }
266 | }
267 | finally
268 | {
269 | //关闭
270 | if (wordDocument != null)
271 | {
272 | wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
273 | wordDocument = null;
274 | }
275 |
276 | //退出
277 | if (wordApplication != null)
278 | {
279 | wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
280 | wordApplication = null;
281 | }
282 | GC.Collect();
283 | GC.WaitForPendingFinalizers();
284 | GC.Collect();
285 | GC.WaitForPendingFinalizers();
286 | }
287 | #endregion
288 | }
289 | #endregion
290 | }
291 | }
292 |
--------------------------------------------------------------------------------