|
楼主 |
发表于 2023-4-1 12:33
|
显示全部楼层
本帖最后由 opiona 于 2023-4-5 10:51 编辑
双面打印多个PDF文件
VBA套用多个DLL函数来实现
这段代码应该是有Bug: 页码顺序,如果总数是奇数 可能会串页 没有打印机没有测试
实际最好是将这些PDF合并成一个,然后打印机双面打印
- Sub TEST_双面打印()
- Dim ARX
- Dim StrPrintName, PathXPS, PassWord, ZCM As String
-
- StrPrintName = ""
- PathXPS = ""
- PassWord = ""
- ZCM = "QQ14885553"
-
- ReDim ARX(0 To 3)
- ARX(0) = ThisWorkbook.Path & "\PDF\A14.PDF"
- ARX(1) = ThisWorkbook.Path & "\PDF\A1.PDF"
- ARX(2) = ThisWorkbook.Path & "\PDF\A2.PDF"
- ARX(3) = ThisWorkbook.Path & "\PDF\A3.PDF"
-
- Call GA_双面打印多个PDF文件(ARX, StrPrintName:=StrPrintName, PathXPS:=PathXPS, PassWord:=PassWord, ZCM:=ZCM)
-
- MsgBox "双面打印完成", vbInformation, "北极狐工作室QQ: 14885553"
-
- End Sub
- Sub GA_双面打印多个PDF文件(ByVal ARX, Optional ByVal StrPrintName As String = "", Optional ByVal PathXPS As String = "", Optional ByVal PassWord As String = "", Optional ByVal ZCM As String = "")
- Rem ARX 数组 需要打印的PDF文件全路径
- Rem StrPrintName 打印机名称 默认="" 默认打印机
- Rem PathXPS 打印机名="Microsoft XPS Document Writer" 需要指定保存文件的路径
- Rem PassWord PDF文件密码 默认="" 没有密码
- Rem ZCM 注册码
- Rem 使用方法 Call GA_双面打印多个PDF文件(ARX, StrPrintName:=StrPrintName, PathXPS:=PathXPS, PassWord:=PassWord, ZCM:=ZCM)
-
- Dim PDFDLL As Object
- Dim ERX, ZAC, ZAD
- Dim I, X, LB, INTX, IntPages As Long
- Dim StrPages As String
- Dim BL As Boolean
-
- Rem 创建函数类对象 CreateObject 不需要提前引用
- Set PDFDLL = CreateObject("GTDPDFPlugIn.PDFClass") 'DLL文件内Class的名称 现在如无意外,就可以创建一个MyDLLClass对象,YEAH!
-
- Rem 获取全部页面 正面反面
- Set ZAC = CreateObject("Scripting.Dictionary")
- Set ZAD = CreateObject("Scripting.Dictionary")
- INTX = 0
- LB = LBound(ARX)
- For X = LB + 0 To UBound(ARX)
- IntPages = PDFDLL.GetNumPagesPDF(PathPDF:=ARX(X), PassWord:=PassWord, ZCM:=ZCM)
- For I = 1 To IntPages
- INTX = INTX + 1
- If INTX Mod 2 = 1 Then
- If ZAC.EXISTS(ARX(X)) = False Then
- ZAC(ARX(X)) = I
- Else
- ZAC(ARX(X)) = ZAC(ARX(X)) & "," & I
- End If
- Else
- If ZAD.EXISTS(ARX(X)) = False Then
- ZAD(ARX(X)) = I
- Else
- ZAD(ARX(X)) = ZAD(ARX(X)) & "," & I
- End If
- End If
- Next
- Next
- Rem 打印单数页
- ERX = ZAC.KEYS
- For X = 0 To UBound(ERX)
- StrPages = ZAC(ERX(X))
- INTX = PDFDLL.PrintPagesPDF(PathPDF:=ERX(X), StrPages:=StrPages, StrPrintName:=StrPrintName, PathXPS:=PathXPS, PassWord:=PassWord, ZCM:=ZCM)
- Next
-
- Rem 打印双数页
- BL = False
- If MsgBox("所选PDF单数页 打印完成" & vbCrLf & "请将纸张翻转 准备打印双数页" & vbCrLf & vbCrLf & "请确认: 已准备好, 开始打印双数页?", vbInformation + vbDefaultButton2 + vbYesNo, "北极狐工作室QQ: 14885553") = vbYes Then
- BL = True
- Else
- If MsgBox("确认不需要打印 双数页 吗?" & vbCrLf & vbCrLf & "不打印 点击: 是 打印 点击: 否", vbInformation + vbDefaultButton2 + vbYesNo, "北极狐工作室QQ: 14885553") = vbNo Then
- BL = True
- End If
- End If
-
- If BL = True Then
- ERX = ZAD.KEYS
- For X = 0 To UBound(ERX)
- StrPages = ZAD(ERX(X))
- INTX = PDFDLL.PrintPagesPDF(PathPDF:=ERX(X), StrPages:=StrPages, StrPrintName:=StrPrintName, PathXPS:=PathXPS, PassWord:=PassWord, ZCM:=ZCM)
- Next
- End If
-
- Rem 释放对象
- Set PDFDLL = Nothing
-
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|