vbscript 将word doc 转换为pdf [英] vbscript to convert word doc to pdf
问题描述
我写了一个简短的 vbscript,可以打开一个 word 文档,编辑一些书签并保存到一个新的 .doc 文件中.
I have written a short vbscript that opens a word document, edits a few bookmarks and saves to a new .doc file.
我现在需要将其转换为 pdf 文件,这对于使用诸如 cutPDF 之类的文件(通过将其发送到虚拟打印机)来说非常简单,但我想自动执行该步骤.
I now need to convert this to a pdf file, which is straightforward enough to do with something like cutePDF (by sending it to a virtual printer), but I would like to automate that step.
任何人都可以提供有关该过程所需的 vbscript 的任何想法的帮助,无论是自动化打印步骤还是其他方法.
Could anyone help with any ideas on the vbscript necessary for that process, either automating the print step, or another method.
非常感谢
戴夫
推荐答案
我曾经写过一个有关此问题的博客文章.可以按如下方式进行转换:
I once wrote a blog article on this matter. The conversion can be done as follows:
Function DocToPdf( docInputFile, pdfOutputFile )
Dim fileSystemObject
Dim wordApplication
Dim wordDocument
Dim wordDocuments
Dim baseFolder
Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
Set wordApplication = CreateObject("Word.Application")
Set wordDocuments = wordApplication.Documents
docInputFile = fileSystemObject.GetAbsolutePathName(docInputFile)
baseFolder = fileSystemObject.GetParentFolderName(docInputFile)
If Len(pdfOutputFile) = 0 Then
pdfOutputFile = fileSystemObject.GetBaseName(docInputFile) + ".pdf"
End If
If Len(fileSystemObject.GetParentFolderName(pdfOutputFile)) = 0 Then
pdfOutputFile = baseFolder + "\" + pdfOutputFile
End If
' Disable any potential macros of the word document.
wordApplication.WordBasic.DisableAutoMacros
Set wordDocument = wordDocuments.Open(docInputFile)
' See http://msdn2.microsoft.com/en-us/library/bb221597.aspx
wordDocument.SaveAs pdfOutputFile, wdFormatPDF
wordDocument.Close WdDoNotSaveChanges
wordApplication.Quit WdDoNotSaveChanges
Set wordApplication = Nothing
Set fileSystemObject = Nothing
End Function
不过关闭文件很重要.请注意,您需要使用带有 PDF 插件的 Word 2007 或 Word 2010+ 才能执行此操作.
It is important to close the files though. Note that you require Word 2007 with PDF plugin or Word 2010+ for doing this.
这篇关于vbscript 将word doc 转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!