VB.net itextsharp创建第二个PDF会导致错误

时间:2018-01-17 13:10:53

标签: c# vb.net pdf itext

我正在尝试使用iTextSharp创建PDF。 在创建第一个PDF时,我没有遇到任何问题。 一旦我想创建第二个PDF文件,我就会收到无法访问该文件的错误。我想我没有正确处理文件。 您将在下面找到PDF生成代码的副本。

Private Sub GeneratePDF()

    Try



        Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("\\verkoop\offerte v2\Offerte " & offertenummer2 & "-" & offertenummer & " " & TextBox2.Text & ".pdf", FileMode.Create))

        Dim FontColour As BaseColor = New BaseColor(35, 31, 32)
        Dim Calibri8 As Font = FontFactory.GetFont("Calibri", 10, FontColour)
        Dim Calibri6 As Font = FontFactory.GetFont("Calibri", 6, FontColour)

        Dim img As Image = Image.GetInstance("Resources\Offerte-NL.png")

        MessageBox.Show("Stap2 gelukt")

        Dim ev As New itsEvents
        pdfWrite.PageEvent = ev

        pdfDoc.Open()
        MessageBox.Show("Stap3 gelukt")
        'witte lijn

        Dim whiteline As New PdfPCell(New Phrase(" "))
        whiteline.Colspan = 2
        whiteline.HorizontalAlignment = 0
        whiteline.Border = Rectangle.NO_BORDER

        'foto inladen

        If RadioButton5.Checked = True Then

            img = Image.GetInstance("Resources\Offerte-NL.png")
            img.ScalePercent(18.0F, 18.0F)
            img.Alignment = 0
            pdfDoc.Add(img)

        ElseIf RadioButton4.Checked = True Then

            img = Image.GetInstance("Resources\Offerte-BE.png")
            img.ScalePercent(18.0F, 18.0F)
            img.Alignment = 0
            pdfDoc.Add(img)

        End If


        'Eerste table in PDF voor klantgegevens

        Dim klanttable As New PdfPTable(2)
        klanttable.TotalWidth = 350.0F
        klanttable.LockedWidth = True
        klanttable.HorizontalAlignment = 0
        'klanttable.DefaultCell.Border = Rectangle.NO_BORDER

        Dim sglTblHdWidths(1) As Single
        sglTblHdWidths(0) = 120
        sglTblHdWidths(1) = 230
        klanttable.SetWidths(sglTblHdWidths)

        Dim kollommatenproduct(5) As Single
        kollommatenproduct(0) = 45
        kollommatenproduct(1) = 45
        kollommatenproduct(2) = 200
        kollommatenproduct(3) = 65
        kollommatenproduct(4) = 60
        kollommatenproduct(5) = 55


        klanttable.SetWidths(sglTblHdWidths)




        Dim cell As New PdfPCell(New Phrase("Debiteur gegevens"))

        cell.Colspan = 2
        cell.HorizontalAlignment = 0
        cell.Border = Rectangle.NO_BORDER

        Dim debnr As String = TextBox1.Text
        Dim bn As String = TextBox2.Text
        Dim adr As String = TextBox3.Text
        Dim pcwp As String = TextBox4.Text
        Dim cp As String = TextBox5.Text
        Dim km As String = TextBox6.Text

        klanttable.AddCell(cell)
        klanttable.AddCell(whiteline)
        klanttable.AddCell(New Phrase("Debiteur nr.: ", Calibri8))
        klanttable.AddCell(New Phrase(debnr, Calibri8))
        klanttable.AddCell(New Phrase("(Bedrijfs)naam:", Calibri8))
        klanttable.AddCell(New Phrase(bn, Calibri8))
        klanttable.AddCell(New Phrase("Adres:", Calibri8))
        klanttable.AddCell(New Phrase(adr, Calibri8))
        klanttable.AddCell(New Phrase("Postcode & woonplaats:", Calibri8))
        klanttable.AddCell(New Phrase(pcwp, Calibri8))
        klanttable.AddCell(New Phrase("Contactpersoon", Calibri8))
        klanttable.AddCell(New Phrase(cp, Calibri8))
        klanttable.AddCell(New Phrase("Kenmerk:", Calibri8))
        klanttable.AddCell(New Phrase(km, Calibri8))
        klanttable.SpacingBefore = 50.0F
        klanttable.SpacingAfter = 75.0F


        pdfDoc.Add(klanttable)

        'Offerte nummer tabel

        Dim offerteinfotable As New PdfPTable(2)
        offerteinfotable.TotalWidth = 350.0F
        offerteinfotable.LockedWidth = True
        offerteinfotable.HorizontalAlignment = 0
        'offerteinfotable.DefaultCell.Border = Rectangle.NO_BORDER

        offerteinfotable.SetWidths(sglTblHdWidths)


        Dim cell2 As New PdfPCell(New Phrase("Offerte informatie"))
        cell2.Colspan = 2
        cell2.HorizontalAlignment = 0
        cell2.Border = Rectangle.NO_BORDER

        offerteinfotable.AddCell(cell2)
        offerteinfotable.AddCell(whiteline)
        offerteinfotable.AddCell(New Phrase("Offertenummer:", Calibri8))
        offerteinfotable.AddCell(New Phrase(offertenummer2.ToString + "-" + offertenummer.ToString, Calibri8))
        offerteinfotable.AddCell(New Phrase("Datum:", Calibri8))
        offerteinfotable.AddCell(New Phrase(DateTime.Now.Date.ToShortDateString, Calibri8))
        offerteinfotable.AddCell(New Phrase("Contactpersoon:", Calibri8))
        offerteinfotable.AddCell(New Phrase(Login.TextBox3.Text.ToString, Calibri8))
        offerteinfotable.SpacingAfter = 75.0F

        pdfDoc.Add(offerteinfotable)


        'Extra informatie offerte

        Dim offerteextrainfotable As New PdfPTable(2)
        offerteextrainfotable.TotalWidth = 350.0F
        offerteextrainfotable.LockedWidth = True
        offerteextrainfotable.HorizontalAlignment = 0
        'offerteinfotable.DefaultCell.Border = Rectangle.NO_BORDER

        offerteextrainfotable.SetWidths(sglTblHdWidths)


        Dim cell3 As New PdfPCell(New Phrase("Leverings informatie"))
        cell3.Colspan = 2
        cell3.HorizontalAlignment = 0
        cell3.Border = Rectangle.NO_BORDER

        offerteextrainfotable.AddCell(cell3)
        offerteextrainfotable.AddCell(whiteline)
        offerteextrainfotable.AddCell(New Phrase("Betalingscondities:", Calibri8))
        offerteextrainfotable.AddCell(New Phrase(ComboBox3.Text.ToString, Calibri8))
        offerteextrainfotable.AddCell(New Phrase("Levertermijn:", Calibri8))
        offerteextrainfotable.AddCell(New Phrase(ComboBox4.Text.ToString, Calibri8))
        offerteextrainfotable.AddCell(New Phrase("Extra informatie:", Calibri8))
        offerteextrainfotable.AddCell(New Phrase(TextBox7.Text.ToString, Calibri8))
        offerteextrainfotable.SpacingAfter = 150.0F

        pdfDoc.Add(offerteextrainfotable)

        'pagina 2
        pdfDoc.NewPage()

        'Header invoegen

        pdfDoc.Add(img)

        'producten invoegen

        Dim productentable As New PdfPTable(6)
        productentable.TotalWidth = 530.0F
        productentable.LockedWidth = True
        productentable.HorizontalAlignment = 0
        productentable.DefaultCell.PaddingBottom = 5
        productentable.DefaultCell.PaddingTop = 5


        productentable.SetWidths(kollommatenproduct)

        productentable.AddCell(New Phrase("Aantal", Calibri8))
        productentable.AddCell(New Phrase("Art. Nr.", Calibri8))
        productentable.AddCell(New Phrase("Omschrijving", Calibri8))
        productentable.AddCell(New Phrase("Capaciteit", Calibri8))
        productentable.AddCell(New Phrase("Prijs per stuk", Calibri8))
        productentable.AddCell(New Phrase("Prijs totaal", Calibri8))

        Dim totaalincbtw As Decimal = 0.00
        Dim totaalexbtw As Decimal = 0.00


        For Each Row In DataGridView1.Rows

            If Not Row.IsNewRow Then

                Dim aantal As String = Row.Cells(0).Value.ToString
                Dim artikelnummer As String = Row.Cells(1).Value.ToString
                Dim omschrijving As String = Row.Cells(5).Value.ToString
                Dim capaciteit As String = Row.Cells(2).Value.ToString + Row.Cells(3).Value.ToString
                Dim prijsperstukinc As Decimal = Row.Cells(4).Value.ToString
                Dim prijsperstuk As Decimal = Math.Round(prijsperstukinc / 1.21, 2)
                Dim tot1 As Decimal = Row.Cells(0).Value.ToString
                Dim tot2 As Decimal = Row.Cells(4).Value.ToString
                Dim totaalprijsex As Decimal = Math.Round(tot1 * tot2 / 1.21, 2)
                Dim totaalprijsinc As Decimal = Math.Round(tot1 * tot2, 2)

                totaalincbtw = totaalincbtw + totaalprijsinc
                totaalexbtw = totaalexbtw + totaalprijsex

                productentable.AddCell(New Phrase(aantal, Calibri8))
                productentable.AddCell(New Phrase(artikelnummer, Calibri8))
                productentable.AddCell(New Phrase(omschrijving, Calibri8))
                productentable.AddCell(New Phrase(capaciteit, Calibri8))
                productentable.AddCell(New Phrase("€ " + prijsperstuk.ToString, Calibri8))
                productentable.AddCell(New Phrase("€ " + totaalprijsex.ToString, Calibri8))

            End If

        Next


        'totaal bedragen toevoegen

        Dim btw As Decimal = totaalincbtw - totaalexbtw

        Dim blankcell As New PdfPCell(New Phrase(" "))
        blankcell.Colspan = 3
        blankcell.HorizontalAlignment = 0
        blankcell.Border = Rectangle.NO_BORDER

        Dim subtotaalcell As New PdfPCell(New Phrase("Subtotaal:", Calibri8))
        subtotaalcell.UseVariableBorders = True
        subtotaalcell.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER + Rectangle.LEFT_BORDER


        Dim btw21cell As New PdfPCell(New Phrase("BTW 21%", Calibri8))
        btw21cell.UseVariableBorders = True
        btw21cell.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER + Rectangle.LEFT_BORDER



        Dim totaalbedragcell As New PdfPCell(New Phrase("Totaalbedrag:", Calibri8))
        totaalbedragcell.UseVariableBorders = True
        totaalbedragcell.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER + Rectangle.LEFT_BORDER



        Dim tussencel As New PdfPCell(New Phrase(" ", Calibri8))
        tussencel.UseVariableBorders = True
        tussencel.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER
        tussencel.PaddingBottom = 5



        Dim subtotaalcell2 As New PdfPCell(New Phrase("€ " + totaalexbtw.ToString, Calibri8))
        subtotaalcell2.UseVariableBorders = True
        subtotaalcell2.Border = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER + Rectangle.TOP_BORDER



        Dim btw21cell2 As New PdfPCell(New Phrase("€ " + btw.ToString, Calibri8))
        btw21cell2.UseVariableBorders = True
        btw21cell2.Border = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER + Rectangle.TOP_BORDER



        Dim totaalbedragcell2 As New PdfPCell(New Phrase("€ " + totaalincbtw.ToString, Calibri8))
        totaalbedragcell2.UseVariableBorders = True
        totaalbedragcell2.Border = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER + Rectangle.TOP_BORDER



        productentable.AddCell(blankcell)
        productentable.AddCell(blankcell)

        productentable.AddCell(blankcell)
        productentable.AddCell(subtotaalcell)
        productentable.AddCell(tussencel)
        productentable.AddCell(subtotaalcell2)


        productentable.AddCell(blankcell)
        productentable.AddCell(btw21cell)
        productentable.AddCell(tussencel)
        productentable.AddCell(btw21cell2)

        productentable.AddCell(blankcell)
        productentable.AddCell(totaalbedragcell)
        productentable.AddCell(tussencel)
        productentable.AddCell(totaalbedragcell2)



        pdfDoc.Add(productentable)


        pdfDoc.Close()
        pdfDoc.Dispose()

        pdfWrite.Dispose()


    Catch ex As Exception
        MessageBox.Show(ex.ToString())

    End Try

End Sub

当导致错误时,我收到以下消息。

error

此错误标记第602行,即该部分代码“pdfDoc.Open()”的行

我猜不知道某些东西没有妥善处理。

如果有人有一个很棒的想法:D

编辑:

忘记提及我有这条线我的班级

Shared pdfDoc As New Document()

Edit2:解决方案!

我刚刚移动了共享pdfDoc作为新文档()的行

之前到我的私人子GeneratePDF
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("\\verkoop\offerte v2\Offerte " & offertenummer2 & "-" & offertenummer & " " & TextBox2.Text & ".pdf", FileMode.Create))

当前代码正常运行,如下所示:

 Private Sub GeneratePDF()

    Try

        Dim pdfDoc As New Document()

        Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("\\moab.drsys.nl\verkoop\offerte v2\Offerte " & offertenummer2 & "-" & offertenummer & " " & TextBox2.Text & ".pdf", FileMode.Create))

        Dim FontColour As BaseColor = New BaseColor(35, 31, 32)
        Dim Calibri8 As Font = FontFactory.GetFont("Calibri", 10, FontColour)
        Dim Calibri6 As Font = FontFactory.GetFont("Calibri", 6, FontColour)

        Dim img As Image = Image.GetInstance("Resources\Offerte-NL.png")

        MessageBox.Show("Stap2 gelukt")

        Dim ev As New itsEvents
        pdfWrite.PageEvent = ev

        pdfDoc.Open()
        MessageBox.Show("Stap3 gelukt")
        'witte lijn

        Dim whiteline As New PdfPCell(New Phrase(" "))
        whiteline.Colspan = 2
        whiteline.HorizontalAlignment = 0
        whiteline.Border = Rectangle.NO_BORDER

        'foto inladen

        If RadioButton5.Checked = True Then

            img = Image.GetInstance("Resources\Offerte-NL.png")
            img.ScalePercent(18.0F, 18.0F)
            img.Alignment = 0
            pdfDoc.Add(img)

        ElseIf RadioButton4.Checked = True Then

            img = Image.GetInstance("Resources\Offerte-BE.png")
            img.ScalePercent(18.0F, 18.0F)
            img.Alignment = 0
            pdfDoc.Add(img)

        End If


        'Eerste table in PDF voor klantgegevens

        Dim klanttable As New PdfPTable(2)
        klanttable.TotalWidth = 350.0F
        klanttable.LockedWidth = True
        klanttable.HorizontalAlignment = 0
        'klanttable.DefaultCell.Border = Rectangle.NO_BORDER

        Dim sglTblHdWidths(1) As Single
        sglTblHdWidths(0) = 120
        sglTblHdWidths(1) = 230
        klanttable.SetWidths(sglTblHdWidths)

        Dim kollommatenproduct(5) As Single
        kollommatenproduct(0) = 45
        kollommatenproduct(1) = 45
        kollommatenproduct(2) = 200
        kollommatenproduct(3) = 65
        kollommatenproduct(4) = 60
        kollommatenproduct(5) = 55


        klanttable.SetWidths(sglTblHdWidths)




        Dim cell As New PdfPCell(New Phrase("Debiteur gegevens"))

        cell.Colspan = 2
        cell.HorizontalAlignment = 0
        cell.Border = Rectangle.NO_BORDER

        Dim debnr As String = TextBox1.Text
        Dim bn As String = TextBox2.Text
        Dim adr As String = TextBox3.Text
        Dim pcwp As String = TextBox4.Text
        Dim cp As String = TextBox5.Text
        Dim km As String = TextBox6.Text

        klanttable.AddCell(cell)
        klanttable.AddCell(whiteline)
        klanttable.AddCell(New Phrase("Debiteur nr.: ", Calibri8))
        klanttable.AddCell(New Phrase(debnr, Calibri8))
        klanttable.AddCell(New Phrase("(Bedrijfs)naam:", Calibri8))
        klanttable.AddCell(New Phrase(bn, Calibri8))
        klanttable.AddCell(New Phrase("Adres:", Calibri8))
        klanttable.AddCell(New Phrase(adr, Calibri8))
        klanttable.AddCell(New Phrase("Postcode & woonplaats:", Calibri8))
        klanttable.AddCell(New Phrase(pcwp, Calibri8))
        klanttable.AddCell(New Phrase("Contactpersoon", Calibri8))
        klanttable.AddCell(New Phrase(cp, Calibri8))
        klanttable.AddCell(New Phrase("Kenmerk:", Calibri8))
        klanttable.AddCell(New Phrase(km, Calibri8))
        klanttable.SpacingBefore = 50.0F
        klanttable.SpacingAfter = 75.0F


        pdfDoc.Add(klanttable)

        'Offerte nummer tabel

        Dim offerteinfotable As New PdfPTable(2)
        offerteinfotable.TotalWidth = 350.0F
        offerteinfotable.LockedWidth = True
        offerteinfotable.HorizontalAlignment = 0
        'offerteinfotable.DefaultCell.Border = Rectangle.NO_BORDER

        offerteinfotable.SetWidths(sglTblHdWidths)


        Dim cell2 As New PdfPCell(New Phrase("Offerte informatie"))
        cell2.Colspan = 2
        cell2.HorizontalAlignment = 0
        cell2.Border = Rectangle.NO_BORDER

        offerteinfotable.AddCell(cell2)
        offerteinfotable.AddCell(whiteline)
        offerteinfotable.AddCell(New Phrase("Offertenummer:", Calibri8))
        offerteinfotable.AddCell(New Phrase(offertenummer2.ToString + "-" + offertenummer.ToString, Calibri8))
        offerteinfotable.AddCell(New Phrase("Datum:", Calibri8))
        offerteinfotable.AddCell(New Phrase(DateTime.Now.Date.ToShortDateString, Calibri8))
        offerteinfotable.AddCell(New Phrase("Contactpersoon:", Calibri8))
        offerteinfotable.AddCell(New Phrase(Login.TextBox3.Text.ToString, Calibri8))
        offerteinfotable.SpacingAfter = 75.0F

        pdfDoc.Add(offerteinfotable)


        'Extra informatie offerte

        Dim offerteextrainfotable As New PdfPTable(2)
        offerteextrainfotable.TotalWidth = 350.0F
        offerteextrainfotable.LockedWidth = True
        offerteextrainfotable.HorizontalAlignment = 0
        'offerteinfotable.DefaultCell.Border = Rectangle.NO_BORDER

        offerteextrainfotable.SetWidths(sglTblHdWidths)


        Dim cell3 As New PdfPCell(New Phrase("Leverings informatie"))
        cell3.Colspan = 2
        cell3.HorizontalAlignment = 0
        cell3.Border = Rectangle.NO_BORDER

        offerteextrainfotable.AddCell(cell3)
        offerteextrainfotable.AddCell(whiteline)
        offerteextrainfotable.AddCell(New Phrase("Betalingscondities:", Calibri8))
        offerteextrainfotable.AddCell(New Phrase(ComboBox3.Text.ToString, Calibri8))
        offerteextrainfotable.AddCell(New Phrase("Levertermijn:", Calibri8))
        offerteextrainfotable.AddCell(New Phrase(ComboBox4.Text.ToString, Calibri8))
        offerteextrainfotable.AddCell(New Phrase("Extra informatie:", Calibri8))
        offerteextrainfotable.AddCell(New Phrase(TextBox7.Text.ToString, Calibri8))
        offerteextrainfotable.SpacingAfter = 150.0F

        pdfDoc.Add(offerteextrainfotable)

        'pagina 2
        pdfDoc.NewPage()

        'Header invoegen

        pdfDoc.Add(img)

        'producten invoegen

        Dim productentable As New PdfPTable(6)
        productentable.TotalWidth = 530.0F
        productentable.LockedWidth = True
        productentable.HorizontalAlignment = 0
        productentable.DefaultCell.PaddingBottom = 5
        productentable.DefaultCell.PaddingTop = 5


        productentable.SetWidths(kollommatenproduct)

        productentable.AddCell(New Phrase("Aantal", Calibri8))
        productentable.AddCell(New Phrase("Art. Nr.", Calibri8))
        productentable.AddCell(New Phrase("Omschrijving", Calibri8))
        productentable.AddCell(New Phrase("Capaciteit", Calibri8))
        productentable.AddCell(New Phrase("Prijs per stuk", Calibri8))
        productentable.AddCell(New Phrase("Prijs totaal", Calibri8))

        Dim totaalincbtw As Decimal = 0.00
        Dim totaalexbtw As Decimal = 0.00


        For Each Row In DataGridView1.Rows

            If Not Row.IsNewRow Then

                Dim aantal As String = Row.Cells(0).Value.ToString
                Dim artikelnummer As String = Row.Cells(1).Value.ToString
                Dim omschrijving As String = Row.Cells(5).Value.ToString
                Dim capaciteit As String = Row.Cells(2).Value.ToString + Row.Cells(3).Value.ToString
                Dim prijsperstukinc As Decimal = Row.Cells(4).Value.ToString
                Dim prijsperstuk As Decimal = Math.Round(prijsperstukinc / 1.21, 2)
                Dim tot1 As Decimal = Row.Cells(0).Value.ToString
                Dim tot2 As Decimal = Row.Cells(4).Value.ToString
                Dim totaalprijsex As Decimal = Math.Round(tot1 * tot2 / 1.21, 2)
                Dim totaalprijsinc As Decimal = Math.Round(tot1 * tot2, 2)

                totaalincbtw = totaalincbtw + totaalprijsinc
                totaalexbtw = totaalexbtw + totaalprijsex

                productentable.AddCell(New Phrase(aantal, Calibri8))
                productentable.AddCell(New Phrase(artikelnummer, Calibri8))
                productentable.AddCell(New Phrase(omschrijving, Calibri8))
                productentable.AddCell(New Phrase(capaciteit, Calibri8))
                productentable.AddCell(New Phrase("€ " + prijsperstuk.ToString, Calibri8))
                productentable.AddCell(New Phrase("€ " + totaalprijsex.ToString, Calibri8))

            End If

        Next


        'totaal bedragen toevoegen

        Dim btw As Decimal = totaalincbtw - totaalexbtw

        Dim blankcell As New PdfPCell(New Phrase(" "))
        blankcell.Colspan = 3
        blankcell.HorizontalAlignment = 0
        blankcell.Border = Rectangle.NO_BORDER

        Dim subtotaalcell As New PdfPCell(New Phrase("Subtotaal:", Calibri8))
        subtotaalcell.UseVariableBorders = True
        subtotaalcell.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER + Rectangle.LEFT_BORDER


        Dim btw21cell As New PdfPCell(New Phrase("BTW 21%", Calibri8))
        btw21cell.UseVariableBorders = True
        btw21cell.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER + Rectangle.LEFT_BORDER



        Dim totaalbedragcell As New PdfPCell(New Phrase("Totaalbedrag:", Calibri8))
        totaalbedragcell.UseVariableBorders = True
        totaalbedragcell.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER + Rectangle.LEFT_BORDER



        Dim tussencel As New PdfPCell(New Phrase(" ", Calibri8))
        tussencel.UseVariableBorders = True
        tussencel.Border = Rectangle.BOTTOM_BORDER + Rectangle.TOP_BORDER
        tussencel.PaddingBottom = 5



        Dim subtotaalcell2 As New PdfPCell(New Phrase("€ " + totaalexbtw.ToString, Calibri8))
        subtotaalcell2.UseVariableBorders = True
        subtotaalcell2.Border = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER + Rectangle.TOP_BORDER



        Dim btw21cell2 As New PdfPCell(New Phrase("€ " + btw.ToString, Calibri8))
        btw21cell2.UseVariableBorders = True
        btw21cell2.Border = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER + Rectangle.TOP_BORDER



        Dim totaalbedragcell2 As New PdfPCell(New Phrase("€ " + totaalincbtw.ToString, Calibri8))
        totaalbedragcell2.UseVariableBorders = True
        totaalbedragcell2.Border = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER + Rectangle.TOP_BORDER



        productentable.AddCell(blankcell)
        productentable.AddCell(blankcell)

        productentable.AddCell(blankcell)
        productentable.AddCell(subtotaalcell)
        productentable.AddCell(tussencel)
        productentable.AddCell(subtotaalcell2)


        productentable.AddCell(blankcell)
        productentable.AddCell(btw21cell)
        productentable.AddCell(tussencel)
        productentable.AddCell(btw21cell2)

        productentable.AddCell(blankcell)
        productentable.AddCell(totaalbedragcell)
        productentable.AddCell(tussencel)
        productentable.AddCell(totaalbedragcell2)



        pdfDoc.Add(productentable)


        pdfDoc.Close()
        pdfDoc.Dispose()

        pdfWrite.Dispose()


    Catch ex As Exception
        MessageBox.Show(ex.ToString())

    End Try

End Sub

谢谢你的帮助!!! :d

1 个答案:

答案 0 :(得分:6)

由于您未在代码中创建新实例,因此您似乎可以重复使用Document pdfDoc对象。这不起作用,iText Document对象只是一次性的。

因此,添加

pdfDoc = New Document

Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("\\verkoop\offerte v2\Offerte " & offertenummer2 & "-" & offertenummer & " " & TextBox2.Text & ".pdf", FileMode.Create))