資源簡介
首先安裝WPS,然后運行代碼就可。
代碼片段和文件信息
using?System;
using?System.IO;
namespace?WpsToPdf
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????//?顯示Logo
????????????Version();
????????????//?如果不帶參數(shù),輸出幫助信息
????????????if?(args.Length?==?0)
????????????{
????????????????Help();
????????????????Environment.Exit(9);
????????????????return;
????????????}
????????????//?判斷第1個參數(shù)是否-v或-h,如果是,輸出相應的信息
????????????switch?(args[0].ToLower().Substring(0?2))
????????????{
????????????????case?“-v“:
????????????????????Environment.Exit(0);
????????????????????return;
????????????????case?“-h“:
????????????????????Help();
????????????????????Environment.Exit(0);
????????????????????return;
????????????}
????????????//?解析文件名
????????????string?wpsFilename?=?null;
????????????string?pdfFilename?=?null;
????????????try
????????????{
????????????????wpsFilename?=?Path.GetFullPath(args[0]);
????????????????if?(args.Length?>?1)?{?pdfFilename?=?Path.GetFullPath(args[1]);?}
????????????}
????????????catch?(Exception?e)
????????????{
????????????????Console.WriteLine(“參數(shù)中包含不正確的文件名“);
????????????????Environment.Exit(2);
????????????????return;
????????????}
????????????//?判斷輸入文件是否存在
????????????if?(!File.Exists(wpsFilename))
????????????{
????????????????Console.WriteLine(“錯誤:指定文件不存在“);
????????????????Environment.Exit(1);
????????????????return;
????????????}
????????????//?轉換
????????????int?exitCode?=?0;
????????????Wps2Pdf?wps2pdf?=?null;
????????????try
????????????{
????????????????wps2pdf?=?new?Wps2Pdf();
????????????????wps2pdf.ToPdf(wpsFilename?pdfFilename);
????????????}
????????????catch?(Exception?e)
????????????{
????????????????Console.WriteLine(e);
????????????????exitCode?=?13;
????????????}
????????????finally
????????????{
????????????????//?不管轉換是否成功都退出WPS
????????????????if?(wps2pdf?!=?null)?{?wps2pdf.Dispose();?}
????????????}
????????????if?(exitCode?!=?0)?Environment.Exit(exitCode);
????????}
????????static?void?Version()
????????{
????????????Console.WriteLine(@“wps2pdf?-?將WPS文檔(含DOC/DOCX)轉換為PDF
Copyright?(c)?2012?FancyIdea
版本:2.0?(WPS?API?V9)
“);
????????}
????????static?void?Help()
????????{
????????????Console.WriteLine(@“
命令:wps2pdf?WPS文件?[PDF文件]
??????將指定的WPS文件轉換為PDF文件,若未指定PDF文件,
??????生成的PDF文件與WPS文件同名,且擴展名改為PDF。
“);
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-08-08?11:36??wps2pdf\
?????文件????????2661??2014-08-08?11:32??wps2pdf\Program.cs
?????目錄???????????0??2014-08-08?11:36??wps2pdf\Properties\
?????文件????????1402??2014-08-08?11:34??wps2pdf\Properties\AssemblyInfo.cs
?????文件????????1049??2014-08-08?11:32??wps2pdf\Wps2Pdf.cs
?????文件????????3528??2014-08-08?11:21??wps2pdf\wps2pdf.csproj
?????文件?????????855??2013-11-13?11:01??wps2pdf\wps2pdf.sln
- 上一篇:xm
l操作類(xm lProcess.cs) - 下一篇:WPF Task 多任務
評論
共有 條評論