0
내 PDF를 생성하는 코드가 있습니다. 모든 페이지에 꼬리말을 추가하는 방법을 알아 내려고 노력하고 있지만 어떻게해야할지 모르겠다. C#에서 많은 예제를 보았지만 VB.net을 사용하여 바닥 글을 정확히 추가하는 방법을 찾지 못했습니다 (C# 기술은 그리 좋지 않습니다).iTextSharp VB.net을 사용하여 PDF에 바닥 글을 추가하는 방법은 무엇입니까?
올바른 방법은 OnEndPage 기능을 사용하는 것이라고 생각하지만 현재이 코드를 내 코드에 추가하는 방법을 알지 못합니다. 나는 이것에 대해 새로운 도움이 될 것입니다.
아래 코드는 지금 사용하고 있습니다.
Private Sub GeneratePDF()
Dim pdfDoc As New Document()
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("\\testserver\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 img As Image = Image.GetInstance("Resources\Offerte-NL.png")
pdfDoc.Open()
'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 = 100.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 = 100.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))
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()
End Sub
편집 : 여기
대답 :)입니다! 내 코드에 다음 코드를 추가했습니다.
Public Class itsEvents
Inherits PdfPageEventHelper
Public Overrides Sub OnEndPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal document As iTextSharp.text.Document)
Dim FontColour As BaseColor = New BaseColor(0, 0, 0)
Dim Calibri6 As Font = FontFactory.GetFont("Calibri", 6, FontColour)
Dim algemenevoorwaarden As New PdfPTable(1)
algemenevoorwaarden.HorizontalAlignment = 1
Dim cell3 As New PdfPCell(New Phrase(" "))
cell3.HorizontalAlignment = 1
cell3.Border = Rectangle.NO_BORDER
Dim cell4 As New PdfPCell(New Phrase("Textline 1", Calibri6))
cell4.HorizontalAlignment = 1
cell4.Border = Rectangle.NO_BORDER
Dim cell5 As New PdfPCell(New Phrase("Textline 2", Calibri6))
cell5.HorizontalAlignment = 1
cell5.Border = Rectangle.NO_BORDER
Dim cell6 As New PdfPCell(New Phrase("Textline 3", Calibri6))
cell6.HorizontalAlignment = 1
cell6.Border = Rectangle.NO_BORDER
algemenevoorwaarden.AddCell(cell3)
algemenevoorwaarden.AddCell(cell4)
algemenevoorwaarden.AddCell(cell5)
algemenevoorwaarden.AddCell(cell6)
document.Add(algemenevoorwaarden)
End Sub
End Class
Dag Jeffrey, Jeffrey, iText? Wafer 7 geetext 7 niet? (안녕하세요, Jeffrey, 왜 iText의 이전 버전을 사용하고 있습니까? iText 7을 사용하지 않는 이유는 무엇입니까?) –
iTextSharp 온라인을 찾았으며 YouTube에서 기본 자습서를 따랐습니다. iText 7에 swtich하면 코드를 다시 작성해야합니까? –
예, iText 7은 iText의 처음부터 완전히 다시 작성되었습니다. 코드를 다시 작성해야하지만 그만한 가치가 있습니다. AGPL 사용자를위한 자발적인 지원이 중단되었습니다. AGPL에서 iText를 사용하지 않는 사람들 (예 : 자신의 상용 프로젝트를 오픈 소스로하고 싶지 않기 때문에)과 상용 라이센스를 가지고있는 사람들은 지원 계약을 갱신하면 여전히 지원을받을 수 있습니다. –