AutoCAD打印的pdf文件是一个一个的,我们要将其合并起来都有借助其他软件。今天研究了一下iTextSharp,很简单
'将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