【问题标题】:How do I set Acrobat XI printer settings through excel vba?如何通过 excel vba 设置 Acrobat XI 打印机设置?
【发布时间】:2017-11-30 16:17:00
【问题描述】:

我正在设计一个 vba 代码,它允许用户输入一组技术图纸编号并从中创建一个数据包。我在处理 AutoCAD 文件时遇到了问题。因为我们公司有AutoCAD LT我无法使用api,所以我使用adobe的PDFMaker api将文件直接转换为pdf。不幸的是,pdfMaker 的设置相当有限,所以我需要解析输出的 pdf 数据包并以黑白(单色)打印。我目前有一个打开数据包并打印必要页面的子程序,但是,如果我专门打开 acrobat 并在高级设置中选择我的“单色”配置,它只会打印黑白。有没有办法发送命令(我相信它在 javascript 中?)来设置此颜色配置并设置尺寸选项以适应?这是我的代码。

Public xlBook              As Workbook
Public xlSheet             As Worksheet
Public LastRow             As Integer
Public ItemNumber          As String
Public Vin5                As String
Public Vin                 As String
Public FullPath            As String

Sub PdfFormat()

Dim strMakeFile         As String
Dim LastRow             As Integer


Set xlBook = ActiveWorkbook
Set xlSheet = xlBook.Sheets(1)
ItemNumber = Range("E1")
Vin5 = Range("F1")
Vin = ItemNumber & "0" & Vin5
FullPath = "\\eastfile\Departments\Engineering\MACROS\New Packet Output\" &     Vin & "\"


strMakeFile = FullPath & Vin & ".pdf"
LastRow = Range("A" & xlSheet.Rows.Count).End(-4162).Row

Dim AcroExchApp     As New Acrobat.AcroApp
Dim AcroExchAVDoc   As New Acrobat.AcroAVDoc
Dim AcroExchPDDoc   As Acrobat.AcroPDDoc
Dim OpenError       As Boolean
Dim PrintError      As Boolean


OpenError = AcroExchAVDoc.Open(strMakeFile, "")

!!!!!CODE FOR PRINTER SETTINGS HERE!!!!!

PrintError = AcroExchAVDoc.PrintPagesSilentEx(0, 5, 3, 1, 1, 0, 0, 0, -5)

Debug.Print "Open Error: " & Not (OpenError)
Debug.Print "Print Error: " & Not (PrintError)
Debug.Print Vin

AcroExchApp.CloseAllDocs


End Sub

感谢您的宝贵时间

【问题讨论】:

    标签: javascript excel acrobat acrobat-sdk vba


    【解决方案1】:

    您可以在 Acro-js 帮助文件中找到 Acrobat 中的打印参数,例如:Acro JS setting print options

    对于 VBS/VBA,有两种使用方式。在 Acro-Form API 的帮助下,您可以或多或少地直接执行 js-code。这里我举个简单的例子:Execute Acro js from VBA/VBS

    另一种方法是使用 JS-Object,它允许您通过 VBA/VBS Ole 连接使用转换后的 js 代码。 Adobe Acrobat IAC 参考中对此进行了记录。

    你可以在下面的例子中看到它是如何工作的,我使用 jso 来设置一些打印参数。将给定的打印参数更改为您需要的或在 Acro JS 帮助文件中搜索其他示例并通过上述方式直接执行它。祝你好运,莱因哈德

    '// print dropped files with printParameter
    set WshShell = CreateObject ("Wscript.Shell")
    set fs = CreateObject("Scripting.FileSystemObject")
    Set objArgs = WScript.Arguments
    
    if objArgs.Count < 1 then
        msgbox("Please drag a file on the script")
        WScript.quit
    end if
        'contact Acrobat
    Set gApp = CreateObject("AcroExch.App")
    gApp.show 'comment or take out to work in hidden mode
    
      'open via Avdoc and print
    for i=0 to objArgs.Count - 1
        FileIn = ObjArgs(i)
        Set AVDoc = CreateObject("AcroExch.AVDoc")
        If AVDoc.Open(FileIn, "") Then
            Set PDDoc = AVDoc.GetPDDoc()
            Set JSO = PDDoc.GetJSObject
            jso.print false, 0, 0, true
            set pp = jso.getPrintParams
            pp.printerName = "hp deskjet 990c"
            pp.firstPage = 0  '-> Zero based (firstPage = 0)
            pp.lastPage = 5   '-> Zero based (pageCount - 1)
            pp.interactive = pp.constants.interactionLevel.automatic  '-> no print dialog
            pp.pageHandling = pp.constants.handling.booklet
            pp.booklet.duplexMode = pp.constants.bookletDuplexModes.BothSides
            pp.booklet.binding = pp.constants.bookletBindings.LeftTall
            jso.print(pp)
            gApp.CloseAllDocs
        end if
    next
    
    gApp.hide
        gApp.exit
        MsgBox "Done!"
        Quit()
    
    Sub Quit()
          Set JSO  =  Nothing
          Set PDDoc = Nothing
          Set gApp =  Nothing
          Wscript.quit
    End Sub 
    

    【讨论】:

      猜你喜欢
      • 2020-03-14
      • 2021-07-26
      • 2019-02-24
      • 1970-01-01
      • 2017-04-12
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多