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