Word文件转PDF命令

办公软件 学者小王 5年前 (2020-09-15) 222次浏览 已收录 0个评论

1.打开CMD

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

2.启动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);
}


IT学者 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Word文件转PDF命令
喜欢 (0)

您必须 登录 才能发表评论!