Good afternoon,
I solved this question because the width was in percentage and the column width with F.
So, i give the totalwidth 500F or something like that. It's OK
PdfTable2.WidthPercentage = 590F
PdfTable2.LockedWidth = True
but now i passed to header and footer code and i have the same error 1.4% using this code to draw table master detail perfectelly but the method of header and footer don't respond perfectelly.
Please help me to correct this. i use itextsharp 5
VB.Net
Code
Public Class headerfooter
Inherits iTextSharp.text.pdf.PdfPageEventHelper
Public Overrides Sub OnStartPage(writer As iTextSharp.text.pdf.PdfWriter, document As iTextSharp.text.Document)
Dim pdfDoc As iTextSharp.text.Document = New iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0.3F, 0.3F, 0.3F, 0.5F)
Dim bf As iTextSharp.text.pdf.BaseFont = iTextSharp.text.pdf.BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + "\fonts\calibrib.ttf", iTextSharp.text.pdf.BaseFont.IDENTITY_H, True)
Dim font As New iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL)
Dim font1 As New iTextSharp.text.Font(bf, 13, iTextSharp.text.Font.NORMAL)
Try
Dim writer As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
Dim hf As New headerfooter
writer.PageEvent = hf
Dim PdfTable2 As iTextSharp.text.pdf.PdfPTable = New iTextSharp.text.pdf.PdfPTable(8)
PdfTable2.TotalWidth = 590.0F
PdfTable2.LockedWidth = True
PdfTable2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER
PdfTable2.SetWidths(New Single() {0.7F, 0.7F, 0.5F, 0.7F, 1.0F, 1.0F, 1.0F, 0.7F})
PdfTable2.SpacingBefore = 3.0F
PdfTable1.SpacingAfter = 3.0F
For columns As Integer = 0 To dt1.Columns.Count - 1
Dim Cell As iTextSharp.text.pdf.PdfPCell = Nothing
Cell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Phrase(dt1.Columns(columns).ColumnName, font))
Cell.RunDirection = iTextSharp.text.pdf.PdfWriter.RUN_DIRECTION_RTL
Cell.HorizontalAlignment = iText.Layout.Properties.HorizontalAlignment.LEFT
Cell.BackgroundColor = New iTextSharp.text.pdf.CMYKColor(0, 20, 60, 0)
PdfTable2.AddCell(Cell)
Next
For row As Integer = 0 To dt1.Rows.Count - 1
For Columns As Integer = 0 To dt1.Columns.Count - 1
PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Phrase(dt1.Rows(row)(Columns).ToString(), font))
PdfPCell.RunDirection = iTextSharp.text.pdf.PdfWriter.RUN_DIRECTION_RTL
PdfPCell.HorizontalAlignment = iText.Layout.Properties.HorizontalAlignment.LEFT
PdfTable2.AddCell(PdfPCell)
Next
Next
pdfDoc.Add(PdfTable2)
pdfDoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=جدول الجلسات.pdf")
Response.ContentEncoding = Encoding.UTF8
System.Web.HttpContext.Current.Response.Write(pdfDoc)
Response.Flush()
Response.End()
Catch de As iTextSharp.text.DocumentException
Catch ioEx As System.IO.IOException
Catch ex As Exception
End Try
End Using
End Sub
Dim PdfTableh As iTextSharp.text.pdf.PdfPTable = New iTextSharp.text.pdf.PdfPTable(1)
PdfTableh.SpacingBefore = 10.0F
'Dim imageURLh As String = Server.MapPath("~/Styles/entete.bmp")
'Dim jpgh As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageURLh)
'jpgh.ScaleToFit(500.0F, 800.0F)
'jpgh.SpacingBefore = 1.0F
'jpgh.SpacingAfter = 1.0F
'Dim PdfPCellh As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Jpeg(jpgh))
Dim PdfPCellh As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Phrase("جدول الجلسات "))
PdfPCellh.HorizontalAlignment = iText.Layout.Properties.HorizontalAlignment.CENTER
PdfPCellh.Border = iTextSharp.text.Rectangle.NO_BORDER
PdfTableh.AddCell(PdfPCellh)
'Dim PdfPCell As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Phrase("جدول الجلسات " & DateTime.Now.ToString() & " من " & date_d & " إلى " & date_a, font1))
Dim PdfPCell As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Phrase("جدول الجلسات "))
PdfPCell.BackgroundColor = New iTextSharp.text.pdf.CMYKColor(60, 40, 0, 0)
PdfPCell.Border = iTextSharp.text.Rectangle.NO_BORDER
PdfPCell.RunDirection = iTextSharp.text.pdf.PdfWriter.RUN_DIRECTION_RTL
PdfPCell.HorizontalAlignment = iText.Layout.Properties.HorizontalAlignment.CENTER
PdfTableh.AddCell(PdfPCell)
PdfTableh.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetTop(document.TopMargin), writer.DirectContent)
End Sub
Public Overrides Sub OnEndPage(writer As iTextSharp.text.pdf.PdfWriter, document As iTextSharp.text.Document)
Dim PdfTablef As iTextSharp.text.pdf.PdfPTable = New iTextSharp.text.pdf.PdfPTable(3)
PdfTablef.SpacingBefore = 10.0F
'Dim imageURLf As String = Server.MapPath("~/Styles/piedpage.bmp")
'Dim jpgf As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageURLf)
'jpgf.ScaleToFit(500.0F, 800.0F)
'jpgf.SpacingBefore = 1.0F
'jpgf.SpacingAfter = 1.0F
'Dim PdfPCellf As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Jpeg(jpgf))
Dim PdfPCellf As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New iTextSharp.text.Phrase("جدول الجلسات "))
PdfPCellf.HorizontalAlignment = iText.Layout.Properties.HorizontalAlignment.CENTER
PdfPCellf.Border = iTextSharp.text.Rectangle.NO_BORDER
PdfTablef.AddCell(PdfPCellf)
PdfTablef.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetBottom(document.BottomMargin), writer.DirectContent)
End Sub
End Class