使用VBS打印PDF文件

时间:2018-06-19 03:10:42

标签: vbscript

我不熟悉VBS编码。这是我未完成的代码,用于在包含3个不同标题的文档的文件夹中打印文档," DN" " INV"和" PO"。我一直在寻找打印PDF文档的代码/方法。我尝试使用invokeverb"& print"功能,但它似乎不起作用。有人可以教我如何打印出来吗?非常感谢你:))

" DN"需要打印一次," INV"需要打印6次," PO"需要打印2次。

P.S。感谢@kajkrow使用VBA解决同样的问题。我发现我正在使用VBS重新发布。可以找到上一个问题here。 *编辑:附加链接解决了我在VBA和VBS中的问题,并使用InvokeVerbEx打印文件。

'' To set the path to the current folder

set shApp = CreateObject("shell.application")

currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") 

set shFolder = shApp.NameSpace( currentPath )

'' To set the items in the current folder as "files"

set files = shFolder.Items()

''Start of code''

'msgbox("Starting Script")

for each files in files

        ' If name contains "DN" '
        if inStr(files, "DN") then
            'print out 1 time'
        end if
        ' if name contains "INV" '
        if inStr(files, "INV") then
            'print out 6 times'
        end if
        ' if name contains "PO" '
        if inStr(files, "PO") then
            'print out 2 times'
        end if
next
MsgBox("completed")

1 个答案:

答案 0 :(得分:0)

根据文档(https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf),您可以发送命令来打印文件,但副本数量没有参数。

  

您可以使用Acrobat和Adobe Reader显示和打印PDF文件   从命令行。这些命令不受支持,但已经有效   对于一些开发人员这些命令没有文档   除了下面列出的内容。

     

注意:以下所有示例均使用Adobe   读者,但也适用于Acrobat。如果您使用的是Acrobat,   在命令行上用Acrobat.exe代替AcroRd32.exe。   AcroRd32.exe路径名 - 启动Adobe Reader并显示该文件。该   必须提供完整路径。此命令可以接受以下内容   选项。

/n Start a separate instance of Acrobat or Adobe Reader, even if one is currently open.
/s Suppress the splash screen.
/o Suppress the open file dialog box.
/h Start Acrobat or Adobe Reader in a minimized window.

AcroRd32.exe /p pathname — Start Adobe Reader and display the Print dialog box.
AcroRd32.exe /t path "printername" "drivername" "portname" — Start Adobe Reader
and print a file while suppressing the Print dialog box. The path must be fully specified.
The four parameters of the /t option evaluate to path, printername, drivername, and portname (all
strings).
printername — The name of your printer.
drivername — Your printer driver’s name, as it appears in your printer’s properties.
portname — The printer’s port. portname cannot contain any "/" characters; if it does, output is
routed to the default port for that printer

对于每个pdf的多个副本,您可以使用循环。

这样的事情:

    set shApp = CreateObject("shell.application")

currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") 

set shFolder = shApp.NameSpace( currentPath )

set files = shFolder.Items()

set oWsh = CreateObject ("Wscript.Shell")
dn = 1 
inv = 6
po = 2

for each files in files
    msgbox(files)

    if inStr(files, "DN") then
        for x = 1 to dn
          oWsh.run """AcroRd32.exe"" /t /n /h /o /s" &files,,true

        next  
    end if

    if inStr(files, "INV") then
        for x = 1 to inv
          oWsh.run """AcroRd32.exe"" /t /n /h /o /s" &files,,true
        next  
    end if

    if inStr(files, "PO") then
        for x = 1 to po
          oWsh.run """AcroRd32.exe"" /t /n /h /o /s" &files,,true
        next  
    end if

next
MsgBox("completed")

注意:仅使用XPS文档编写器进行测试