如何将文件夹中的rtf文件转换为PDF

How to convert rtf files in folder to PDF

有谁知道如何在 RSAS 内将文件夹中的多个 .rtf(富文本文件)转换为 PDF?

我无法在我的电脑上安装任何应用程序,因此解决方案应该只在我上面提到的两个程序中。

这是@Reeza 慷慨提供的修改后的代码:

bRecursive = False
sFolder = "C:\PATH"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True

Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit

Sub ConvertFolder(oFldr)
  For Each oFile In oFldr.Files
    If LCase(oFSO.GetExtensionName(oFile.Name)) = "rtf" Then
        Set oDoc = oWord.Documents.Open(oFile.path)
        Str = left(oFile,instr(1,oFile,".")-1) 
        oWord.ActiveDocument.SaveAs Str, 17
        oDoc.Close
    End If
Next

If bRecursive Then
    For Each oSubfolder In oFldr.Subfolders
        ConvertFolder oSubfolder
    Next
End If
End Sub

上面的 .vbs 代码有效,但我在文件夹中有 50 个文件,在转换了大约 10 个文件后 rtf 执行 pdf 文档,它只是继续打开和关闭循环中的剩余文件(看起来)。有什么线索吗?谢谢。

我对此进行了测试,它在我的系统上运行良好。 Windows7家企业。 VBS 脚本保存为 .vbs,然后 SAS 可以使用 X 命令或 %SYSEXEC 调用它。

VBS 脚本是:

bRecursive = False
sFolder = "C:\_LOCALDATA\temp\_rtf_test\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True

Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit

Sub ConvertFolder(oFldr)
  For Each oFile In oFldr.Files
    If LCase(oFSO.GetExtensionName(oFile.Name)) = "rtf" Then
        Set oDoc = oWord.Documents.Open(oFile.path)
        Str = left(oFile,instr(1,oFile,".")-1) 
        oWord.ActiveDocument.SaveAs Str & ".pdf", 17
        oDoc.Close
    End If
Next

If bRecursive Then
    For Each oSubfolder In oFldr.Subfolders
        ConvertFolder oSubfolder
    Next
End If
End Sub

然后在 SAS 中:

%sysexec "C:\_LOCALdata\SAMPLE.VBS";