Use a PdfPTable.
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Gavin
Sent: Tuesday, January 17, 2006 1:34 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] Tables and new pages
Hi all,
I need some help sorting out a formatting issue when creating an pdf.
Basically i'm creating a table, setting all the settings,
then from a database
going through each result and creating the cells to display the data.
What I am doing is looping through the results, and each time
adding 4 new
cells to the table, which works perfectly fine, but if the
results continue
onto a new page, the first 2 rows or sets of cells overlap each other.
Below is the code that generates the pdf document, the
results are collected
into an Arraylist of file objects.
[code]
try
{
PdfWriter writer =
PdfWriter.GetInstance
(basedoc, new FileStream(Server.MapPath() + /_files/ +
IPAddress.Replace
(.,) + .pdf, FileMode.Create));
writer.SetEncryption
(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.AllowPrinting);
basedoc.Open();
Font items_font = new
Font(1, 10f);
basedoc.Header = new
HeaderFooter(new
Phrase(File Review Report - , items_font), new Phrase( : +
DateTime.Now.ToShortDateString(), items_font));
Table main = new Table(4, 2);
main.DefaultCellBorder = 0;
main.Border = 0;
main.Cellpadding = 0;
main.Cellspacing = 0;
main.Padding = 0;
main.SetWidths(new
int[4]{ 50, 300,
100, 75});
Font Header_Font = new
Font(1, 20f);
Font List_Font = new
Font(1, 10f);
Table Header = new Table(2);
Header.DefaultCellBorder = 0;
Header.Border = 0;
Header.Cellpadding = 0;
Header.Cellspacing = 0;
Header.Padding = 0;
Paragraph
Paragraph_HDR_MainText = new
Paragraph(File Review Report - + AccountName, Header_Font);
Paragraph
Paragraph_HDR_SmallText = new
Paragraph(Created: + DateTime.Now.ToShortDateString(), List_Font);
Cell Header_MainText =
new Cell();
Header_MainText.Add
(Paragraph_HDR_MainText);
Header_MainText.Add
(Paragraph_HDR_SmallText);
iTextSharp.text.Image logo =
iTextSharp.text.Image.GetInstance(Server.MapPath(logo.gif));
logo.ScaleToFit(45f, 45f);
logo.Alignment =
iTextSharp.text.Image.ALIGN_RIGHT;
Cell Header_Logo = new Cell();
Header_Logo.Add(logo);
Header.AddCell(Header_MainText);
Header.AddCell(Header_Logo);
Paragraph
spacer_content = new Paragraph
(s , new Font(1, 20f, 1, iTextSharp.text.Color.WHITE));
Cell spacer = new
Cell(spacer_content);
spacer.Colspan = 4;
main.AddCell(spacer);
basedoc.Add(Header);
Phrase header_1_phrase
= new Phrase
(Barcode, List_Font);
Cell header_1 = new Cell
(header_1_phrase);
Phrase header_2_phrase
= new Phrase
(Reference, List_Font);
Cell header_2 = new Cell
(header_2_phrase);
Phrase header_3_phrase
= new Phrase
(Holder, List_Font);
Cell header_3 = new Cell
(header_3_phrase);
Phrase header_4_phrase
= new Phrase
(Review Date, List_Font);
Cell header_4 = new Cell
(header_4_phrase);
main.AddCell(header_1);