Word转PDF命令

开打CMD

cscript //nologo js文件路径 待转文件 转换存贮路径

启动MS-DOS,输入如下命令:
cscript //nologo c:\ConvertDoc2PDF.js c:\test.doc c:\

 

 

c#代码

strJS:脚步字符串

           Process proc = new Process();
        proc.StartInfo.FileName = "cmd.exe";
        proc.StartInfo.WorkingDirectory = @"c:\";
        proc.StartInfo.CreateNoWindow = true;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardInput = true;

           proc.StartInfo.RedirectStandardOutput = true;

        proc.Start();
        proc.StandardInput.WriteLine(strJS);
        proc.StandardInput.WriteLine("exit");
           proc.WaitForExit();
           proc.Close();

 

 

ConvertDoc2PDF.js 代码:

var files = WScript.Arguments;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var word = new ActiveXObject("Word.Application");
var PDF = new ActiveXObject("PDFDistiller.PDFDistiller6");
word.ActivePrinter = "Adobe PDF";

var docfile = files(0);
var psfile = files(1) + fso.GetBaseName(files(0)) + ".ps";
var pdffile = files(1) + fso.GetBaseName(files(0)) + ".pdf";
var logfile = files(1) + fso.GetBaseName(files(0)) + ".log";

try
{
var doc = word.Documents.Open(docfile);

word.PrintOut(false, false, 0, psfile);
doc.Close(0);

PDF.FileToPDF2(psfile,pdffile,"",true);

fso.GetFile(psfile).Delete();//删除PS脚本文件
fso.GetFile(logfile).Delete();//删除转换的日志文件

word.Quit();
WScript.Echo("isuccess");
WScript.Quit(0);
}
catch(x)
{
word.Quit();
WScript.Echo("isfail");
WScript.Quit(0);
}


 

发布了66 篇原创文章 · 获赞 2 · 访问量 6万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览