我编写了一个简短的 vb 脚本,用于打开 Word 文档、编辑一些书签并保存到新的 .doc 文件。
我现在需要将其转换为 pdf 文件,这足够简单,可以使用 CutePDF 之类的文件(通过将其发送到虚拟打印机),但我想自动化该步骤。
任何人都可以提供有关该过程所需的 vbscript 的任何想法,无论是自动化打印步骤还是其他方法。
非常感谢
Dave
我曾经写过一篇关于此事的博客文章。转换可以如下完成:
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+ 才能执行此操作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)