If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
Hello,
I try to create a PDF with iTextSharp which reads the values out of a form and wich are inserted from a DATAGRIDVIEW.
So, after a specific amount of lines of the DATAGRIDVIEW I want to create a new page(PdfFile.NewPage).
This code writes the DATAGRIDVIEW into a Pdf:
Code:
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For j As Integer = 0 To DataGridView1.Columns.Count - 1
pdfcell = New PdfPCell(New Phrase(DataGridView1(j, i).Value.ToString(), pTable))
PdfTable.HorizontalAlignment = PdfPCell.ALIGN_LEFT
PdfTable.AddCell(pdfcell)
PdfFile.Add(PdfTable)
The reason for doing that is because the DATAGRIDVIEW overwrites the footer.
After 20 DATAGRIDVIEW lines a PdfFile.NewPage() should follow. On the second page it should continue with the 21 DATAGRIDVIEW line.
For example after 50 lines a new page...
That`s the code of the footer:
Code:
Inherits PdfPageEventHelper
Public Overrides Sub OnendPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal document As iTextSharp.text.Document)
Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim cb As PdfContentByte = writer.DirectContent
cb.BeginText()
cb.SetFontAndSize(bf, 12)
cb.SetTextMatrix(50, 30)
cb.ShowText("TEXTTEXT " & writer.PageNumber)
cb.EndText()
I already tried this it just creating the next page but still overwrites the footer:
Code:
Inherits PdfPageEventHelper
Public Overrides Sub OnendPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal document As iTextSharp.text.Document)
Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim cb As PdfContentByte = writer.DirectContent
cb.BeginText()
cb.SetFontAndSize(bf, 12)
cb.SetTextMatrix(50, 30)
cb.ShowText("TEXTTEXT " & writer.PageNumber)
cb.EndText()
Thanks in advance for your help.
Greetings
GerryGras
Code:
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For j As Integer = 0 To DataGridView1.Columns.Count - 1
pdfcell = New PdfPCell(New Phrase(DataGridView1(j, i).Value.ToString(), pTable))
PdfTable.HorizontalAlignment = PdfPCell.ALIGN_LEFT
PdfTable.AddCell(pdfcell)
Select Case i
Case 20, 30, 60, 99
PdfFile.NewPage()
End Select
PdfFile.Add(PdfTable)
Advertiser Disclosure:
Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.