|
本帖最后由 worryd1 于 2023-11-14 22:10 编辑 因工作需要打印大量的发票,两张打印一张A4纸正好,而合并软件收费居多而且不方便,所以自己做了一个(也都是网上查和总结的)希望对大家有帮助
1,先安装 Adobe Acrobat 软件,然后添加acrobat access 3.0 Type Libarry 引用
2,分别设置了合并文件夹内所有PDF文件,和选择PDF文件合并两种方式3,因为级别不够不能发附件,把源码直接发出来 [free]
- Private Sub 合并PDF1_Click()
- 'On Error GoTo ErrorHandler:
- Dim PDFdoc As Object, TempPDFdoc As Object
- Dim PageNum As Long
- Dim PDFFolder As String, PDFFileName As String
- If Len(Nz(Me.SaveFile, "")) = 0 Then
- Call SaveFile_Click
- Exit Sub
- End If
- PDFFolder = Me.SaveFile & ""
- Set PDFdoc = CreateObject("AcroExch.PDDoc")
- Set TempPDFdoc = CreateObject("AcroExch.PDDoc")
- TempPDFdoc.Create
- For i = 0 To Me.plist.ListCount - 1
- PDFFileName = Me.plist.ItemData(i)
- If PDFdoc.Open(PDFFileName) Then
- PageNum = PDFdoc.GetNumPages
- TempPDFdoc.InsertPages TempPDFdoc.GetNumPages - 1, PDFdoc, 0, PageNum, 0
- PDFdoc.Close
- End If
- Next
- With TempPDFdoc
- .Save PDSaveFull, PDFFolder & "合并.pdf"
- .Close
- End With
- Exithere:
- Exit Sub
- ErrorHandler:
- MsgBox Err.Description, vbInformation, "提示"
- Resume Exithere
- End Sub
- Private Sub PDF选择按钮_Click()
- With Application.FileDialog(3)
- .AllowMultiSelect = False
- .Filters.Clear
- .Filters.Add *.pdf"
- If .Show Then Me.plist.AddItem .SelectedItems(1)
- End With
- End Sub
- Sub 合并PDF文件()
- Dim PDFdoc As Object, TempPDFdoc As Object
- Dim PageNum As Long
- Dim PDFFolder As String, PDFFileName As String
- PDFFolder = Me.SourceFile & ""
- Set PDFdoc = CreateObject("AcroExch.PDDoc")
- Set TempPDFdoc = CreateObject("AcroExch.PDDoc")
- TempPDFdoc.Create
- PDFFileName = Dir(PDFFolder & "*.pdf")
- Do
- If PDFdoc.Open(PDFFolder & PDFFileName) Then
- PageNum = PDFdoc.GetNumPages
- TempPDFdoc.InsertPages TempPDFdoc.GetNumPages - 1, PDFdoc, 0, PageNum, 0
- PDFdoc.Close
- End If
- PDFFileName = Dir
- Loop Until PDFFileName = ""
- With TempPDFdoc
- .Save PDSaveFull, PDFFolder & "合并.pdf"
- .Close
- End With
- Set PDFdoc = Nothing
- Set TempPDFdoc = Nothing
- End Sub
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|