javascript - 如何通过 Excel VBA 设置 Acrobat XI 打印机设置?

标签 javascript excel acrobat acrobat-sdk vba

我正在设计一个 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

感谢您的宝贵时间

最佳答案

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

对于 VBS/VBA,有两种使用方法。借助 Acro-Form API,您可以或多或少地直接执行 js 代码。这里我举了一个简单的例子:Execute Acro js from VBA/VBS

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

您可以在以下示例中看到其工作原理,其中我使用 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 

关于javascript - 如何通过 Excel VBA 设置 Acrobat XI 打印机设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47577899/

相关文章:

javascript - 在不破坏兼容性的情况下以交互方式在javascript中加载图像

javascript - 如何学习创建日期选择器

javascript - Adobe Acrobat Javascript setPageRotations 不旋转页面

javascript - 在 PDF 中输入数字后自定义字符串的自定义按键

excel - 是否可以根据条件制作数字序列?

Javascript 检测是否安装了 Adob​​e Reader

javascript - Javascript 导入的麻烦

javascript - 将字符串拆分为数组是特定方式

excel - 将工作表 1 中的特定列与工作表 2 进行比较,并返回工作表 2 中匹配行的值

sql - 如何使用 Visual Studio Express 2013 从 sql-server 2008 导入数据到 excel