合并两个PDF文件

时间:2018-10-14 20:59:26

标签: asp.net vb.net pdf itext

我正在使用iTextsharp创建pdf。 我的代码读取了一个模板文件并在上面写。 现在,我需要使用另一个模板文件将第二页添加到PDF。 找不到任何样本来做。 我该怎么办?

     Response.Charset = "utf-8"
            Response.AddHeader("Last-Modified", DateTime.Now.ToString("r"))
            Response.CacheControl = "public"
            Response.AddHeader("Content-Disposition", "attachment; filename=Attestato.pdf")
            Response.ContentType = "application/pdf"

            Dim outputPdfStream As Stream = Response.OutputStream
            Dim strTemplateStampa As String
            Dim ListaMarche As List(Of String) = Prot.ListaMarche
            Dim ListaModelli As List(Of String) = Prot.ListaModelli
            Dim NrAttestato As String = Prot.NrAttestato
            Dim IdProd As Integer = Prot.GetIdProduttore
            Dim Produttore As Produttore = Produttore.Carica(IdProd)

            Dim myProd As Produttore = Produttore.Carica(IdProd)
            strTemplateStampa = Server.MapPath("~/Template/Template.pdf")

            Dim reader As New iTextSharp.text.pdf.PdfReader(strTemplateStampa)


            Dim mb As iTextSharp.text.Rectangle = reader.GetPageSize(1)

            Dim stamper As New iTextSharp.text.pdf.PdfStamper(reader, outputPdfStream)

            Dim bf As iTextSharp.text.pdf.BaseFont = iTextSharp.text.pdf.BaseFont.CreateFont(Request.PhysicalApplicationPath + "Fonts" + "\Arial.ttf", iTextSharp.text.pdf.BaseFont.WINANSI, iTextSharp.text.pdf.BaseFont.EMBEDDED)
            Dim cb As iTextSharp.text.pdf.PdfContentByte = stamper.GetOverContent(1)

            WriteToPdf(cb, bf, 10, 125, 150, NrAttestato)

            Dim riga As Integer = 440
            For Each MarcaProt As String In ListaMarche
                WriteToPdf(cb, bf, 8, 60, riga, MarcaProt)
                riga += 11
            Next

            riga = 440
            For Each ModelloProt As String In ListaModelli
                WriteToPdf(cb, bf, 8, 300, riga, ModelloProt)
                riga += 11
            Next
            WriteToPdf(cb, bf, 8, 120, 645, Prot.Protocollo)


            WriteToPdf(cb, bf, 16, Diff, 340, Prot.GetName)

            stamper.Close()

            Response.End()

0 个答案:

没有答案