最近要做一張複雜的報表,
所以必須做成二張PDF.. 再合併,
PDF合併可考倒偶們了,
還好有熱心的版大「這裡沒有天使」幫偶解題,
總之,第一步PDF合併OK.. Partial Class TEST Private Sub mergePDFFiles(ByVal fileList() As String, ByVal outMergeFile As String) Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ End Class
接著再來看內容怎麼拆嚕!
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO
Imports System.Collections
Imports System.ComponentModel
Imports System.Text
Inherits System.Web.UI.Page
outMergeFile = Server.MapPath(outMergeFile)
Dim reader As PdfReader
Dim document As Document = New Document()
Dim writer As PdfWriter = PdfWriter.GetInstance( _
document, New FileStream(outMergeFile, FileMode.Create))
document.Open()
Dim cb As PdfContentByte = writer.DirectContent
Dim NewPage As PdfImportedPage
Dim i As Integer
For i = 0 To fileList.Length - 1 Step i + 1
reader = New PdfReader(Server.MapPath(fileList(i)).ToString)
Dim iPageNum As Integer = reader.NumberOfPages
Dim j As Integer
For j = 1 To iPageNum
document.NewPage()
NewPage = writer.GetImportedPage(reader, j)
cb.AddTemplate(NewPage, 0, 0)
Next
Next
Document.Close()
End Sub
Handles Button1.Click
Dim pdflist(1) As String
pdflist(0) = "pdf/Qty1.pdf"
pdflist(1) = "pdf/Qty2.pdf"
mergePDFFiles(pdflist, "pdf/newpdf.pdf")
End Sub
以上,祝大家使用愉快。
vb.net asp.net pdf合併 iTextSharp
留言列表