如何通过excel vba设置Acrobat XI打印机设置?

时间:2017-11-30 16:17:01

标签: javascript excel-vba acrobat acrobat-sdk vba

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

感谢您的时间

1 个答案:

答案 0 :(得分:1)

您可以在Acrobat-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-code。这些内容记录在Adobe Acrobat IAC Reference。

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

'// 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