PDF格式的问题(与页脚重叠的文字)

时间:2017-02-21 09:07:22

标签: c# itext

当我在PDF中创建报告时,如果包含大于页面,则其转到第二个并且其工作正常但在上面的页面中它与页脚重叠我正在尝试使用table.SplitLate = false;secondTable.SplitLate = false;但是没有工作,当我将secondTableCell.VerticalAlignment = Element.ALIGN_TOP;设置为触及顶级寄宿的所有单元格时,请更新我错在哪里。这里有一些PDF格式的创建报告代码和屏幕截图..

谢谢...... enter image description here

                    datePrintTable = new PdfPTable(1);
                    datePrintTable.TotalWidth = Size;
                    datePrintTable.LockedWidth = true;
                    datePrintTable.SetWidths(new float[] { 15f });

                    phrase = new Phrase();
                    phrase.Add(new Chunk("Report : " + ReportModule.Report_Module_Name, FontFactory.GetFont("Arial Unicode MS,Arial", 9, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                    cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                    cell.VerticalAlignment = Element.ALIGN_TOP;
                    //cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                    cell.FixedHeight = 15f;
                    datePrintTable.AddCell(cell);

                    phrase = new Phrase();
                    phrase.Add(new Chunk("", FontFactory.GetFont("Arial Unicode MS,Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                    cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                    cell.VerticalAlignment = Element.ALIGN_TOP;
                    //cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                    cell.FixedHeight = 15f;
                    datePrintTable.AddCell(cell);

                    document.Add(datePrintTable);

                    float[] widthArry = new float[ColWidth.Count];
                    float widthCount = 0;
                    for (int i = 0; i < ColWidth.Count; i++)
                    {
                        widthArry[i] = ColWidth[i];
                        widthCount += ColWidth[i];
                    }
                    widthArry = widthArry.Where(x => x != 0).ToArray();
                    table = new PdfPTable(widthArry);
                    table.TotalWidth = Size;
                    table.LockedWidth = true;
                    table.SplitLate = false;
                    table.SetWidths(widthArry);

                    int Srno = 1;
                    int count = 0;


                    for (int a = 0; a < colindexid.Count; a = a + 1)
                    {
                        #region addcolumnHeadeName


                        if (colindexid[a].ToString() == Convert.ToString(0))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H1, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(1))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H2, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(2))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H3, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(3))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H4, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(4))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H5, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(5))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H6, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(6))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H7, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(7))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H8, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(8))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H9, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(9))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H10, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(10))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H11, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(11))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H12, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(12))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H13, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }
                        else if (colindexid[a].ToString() == Convert.ToString(13))
                        {
                            // dt.Columns.Add(new DataColumn(H1, typeof(string)));
                            phrase = new Phrase();
                            phrase.Add(new Chunk(H14, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
                            cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            cell.FixedHeight = 15f;
                            table.AddCell(cell);

                        }


                        #endregion addcolumnHeadeName
                    }


                    document.Add(table);

                    secondTable = new PdfPTable(widthArry);
                    secondTable.TotalWidth = Size;
                    secondTable.LockedWidth = true;
                    secondTable.SplitLate = false;
                    secondTable.SetWidths(widthArry);



                    foreach (var item in resultAdmissionReuslt)
                    {
                        #region rowadd
                        int ii = 0;
                        float datacellwidth = 0;

                        if (colindexid.Contains(Convert.ToInt32(0)))
                        {

                            phrase = new Phrase();
                            phrase.Add(new Chunk(Convert.ToString(Srno), f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);

                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(1)))
                        {

                            if (!string.IsNullOrEmpty(item.AdmissionRequestNo))
                            {
                                item.AdmissionRequestNo = textInfo.ToTitleCase(item.AdmissionRequestNo.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.AdmissionRequestNo, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(2)))
                        {


                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.Date + "\n", f));
                            phrase.Add(new Chunk(item.Time, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(3)))
                        {
                             if (!string.IsNullOrEmpty(item.AttenedBy))
                            {
                                item.AttenedBy = textInfo.ToTitleCase(item.AttenedBy.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.AttenedBy, f));                               
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(4)))
                        {
                            if (!string.IsNullOrEmpty(item.Existing_Relation))
                            {
                                item.Existing_Relation = textInfo.ToTitleCase(item.Existing_Relation.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.Existing_Relation, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(5)))
                        {      

                            if (!string.IsNullOrEmpty(item.Relation))
                            {
                                item.Relation = textInfo.ToTitleCase(item.Relation.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.Relation, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {
                        }
                        if (colindexid.Contains(Convert.ToInt32(6)))
                        {

                            if (!string.IsNullOrEmpty(item.StudentName))
                            {
                                item.StudentName = textInfo.ToTitleCase(item.StudentName.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.StudentName, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(7)))
                        {

                            phrase = new Phrase();
                            phrase.Add(new Chunk((item.Gender.ToUpper() == "MALE" ? "M" : "F"), f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(8)))
                        {

                            if (!string.IsNullOrEmpty(item.ClassForDisplay))
                            {
                                item.ClassForDisplay = textInfo.ToTitleCase(item.ClassForDisplay.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.ClassForDisplay, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(9)))
                        {

                            if (!string.IsNullOrEmpty(item.ParentName))
                            {
                                item.ParentName = textInfo.ToTitleCase(item.ParentName.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.ParentName, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);

                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(10)))
                        {
                            string Contact = "";
                            if (!string.IsNullOrEmpty(item.ContactNo1))
                            {
                                Contact += item.ContactNo1 ;
                            }
                            if (!string.IsNullOrEmpty(item.contactNo2))
                            {
                                Contact +=  Environment.NewLine + item.contactNo2;
                            }


                            phrase = new Phrase();
                            phrase.Add(new Chunk(Contact, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);
                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(11)))
                        {
                            if (!string.IsNullOrEmpty(item.LandMark))
                            {
                                item.LandMark= textInfo.ToTitleCase(item.LandMark.ToLower());
                            }

                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.LandMark, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);
                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(12)))
                        {
                            phrase = new Phrase();
                            phrase.Add(new Chunk((item.Walkin_Online.ToUpper() == "ONLINE" ? "O" : "W"), f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);
                        }
                        else
                        {

                        }
                        if (colindexid.Contains(Convert.ToInt32(13)))
                        {
                            if (!string.IsNullOrEmpty(item.AdmissionStatus))
                            {
                                item.AdmissionStatus= textInfo.ToTitleCase(item.AdmissionStatus.ToLower());
                            }
                            phrase = new Phrase();
                            phrase.Add(new Chunk(item.AdmissionStatus, f));
                            secondTableCell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                            secondTableCell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
                            secondTableCell.VerticalAlignment = Element.ALIGN_TOP;
                            secondTable.AddCell(secondTableCell);
                        }
                        else
                        {

                        }


                        #endregion rowadd

                        Srno++;
                    }


                    document.Add(secondTable);
                }

0 个答案:

没有答案