'将files中的所有pdf文件合并到newfile中
Sub JoinPDFtoFile(ByVal NewFile As String, ByVal Files As String())
Dim File As String
Dim Doc As Document = New Document()
Dim Pw As PdfWriter = PdfWriter.GetInstance(Doc, New FileStream(NewFile, FileMode.Create))
Dim Pcb As PdfContentByte
Doc.Open()
Pcb = Pw.DirectContent
For Each File In Files
Dim Pr As PdfReader = New PdfReader(File)
Dim N As Int16 = Pr.NumberOfPages
For i As Int16 = 1 To N
Dim NewPage As PdfImportedPage = Pw.GetImportedPage(Pr, i)
Dim Rec As Rectangle = Pr.GetPageSize(i)
Doc.SetPageSize(Rec)
Doc.NewPage()
Pcb.AddTemplate(NewPage, 0, 0)
Next
Next
Doc.Close()
Pw.Close()
End Sub
Sub JoinPDFtoFile(ByVal NewFile As String, ByVal Files As String())
Dim File As String
Dim Doc As Document = New Document()
Dim Pw As PdfWriter = PdfWriter.GetInstance(Doc, New FileStream(NewFile, FileMode.Create))
Dim Pcb As PdfContentByte
Doc.Open()
Pcb = Pw.DirectContent
For Each File In Files
Dim Pr As PdfReader = New PdfReader(File)
Dim N As Int16 = Pr.NumberOfPages
For i As Int16 = 1 To N
Dim NewPage As PdfImportedPage = Pw.GetImportedPage(Pr, i)
Dim Rec As Rectangle = Pr.GetPageSize(i)
Doc.SetPageSize(Rec)
Doc.NewPage()
Pcb.AddTemplate(NewPage, 0, 0)
Next
Next
Doc.Close()
Pw.Close()
End Sub
[本日志由 tiancao1001 于 2021-10-16 01:27 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |