最近要做一張複雜的報表,

所以必須做成二張PDF.. 再合併,

PDF合併可考倒偶們了,

還好有熱心的版大「這裡沒有天使」幫偶解題,

總之,第一步PDF合併OK..

接著再來看內容怎麼拆嚕!

Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO
Imports System.Collections
Imports System.ComponentModel
Imports System.Text

Partial Class TEST
    Inherits System.Web.UI.Page

    Private Sub mergePDFFiles(ByVal fileList() As String, ByVal outMergeFile As String)
        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

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
                                                   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

End Class

SourceForge.net: iTextSharp (←dll Download)

以上,祝大家使用愉快。


vb.net asp.net pdf合併 iTextSharp

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 張小芸 的頭像
    張小芸

    張小芸的生活記事簿 δ

    張小芸 發表在 痞客邦 留言(0) 人氣()