2017-02-20 9 views
1

itextsharpを使用してPDFを作成する際にレポートをバインドするときに、レポートが80行または100行を超える場合、2ページ目から開始しますが、その作品は最初のページから。ここで問題画面短Record bind from second pageで コードレポートを追加する私のコード:バインドレポートの取得itextsharpを使用したPDFの作成

   table = new PdfPTable(2); 
       table.TotalWidth = Size; 
       table.LockedWidth = true; 
       table.DefaultCell.Border = Rectangle.NO_BORDER; 
       table.SetWidths(new float[] { 265f, 265f }); 



       insideTable1 = new PdfPTable(1); 
       insideTable1.TotalWidth = 260f; 
       insideTable1.LockedWidth = true; 
       insideTable1.DefaultCell.Border = Rectangle.NO_BORDER; 
       insideTable1.SetWidths(new float[] { 260f }); 

       insideTable11 = new PdfPTable(widthArry); 
       insideTable11.TotalWidth = 260f; 
       insideTable11.LockedWidth = true; 
       insideTable11.SetWidths(widthArry); 



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


        if (colindexid[a].ToString() == Convert.ToString(0)) 
        { 

         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; 
         insideTable11.AddCell(cell); 


        } 
        else if (colindexid[a].ToString() == Convert.ToString(1)) 
        { 

         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; 
         insideTable11.AddCell(cell); 



        } 
        else if (colindexid[a].ToString() == Convert.ToString(2)) 
        { 

         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; 
         insideTable11.AddCell(cell); 


        } 
        else if (colindexid[a].ToString() == Convert.ToString(3)) 
        { 
         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; 
         insideTable11.AddCell(cell); 



        } 
        #endregion addcolumnHeadeName 
       } 


       for (int i = 1; i <= 51; i++) 
       { 
        cnt++; 
        string Name = ""; 


        #region addrow 

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


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

         insideTable11.AddCell(cell); 

        } 
        else 
        { 

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

         phrase = new Phrase(); 
         phrase.Add(new Chunk("E1", f)); 
         cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
         cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 
         insideTable11.AddCell(cell); 
        } 
        else 
        { 

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

         phrase = new Phrase(); 
         //string SName = ""; 
         //if (!string.IsNullOrEmpty(Name.ToLower())) 
         //{ 
         // SName = textInfo.ToTitleCase(Name.ToLower()); 
         //} 
         phrase.Add(new Chunk("Ravi Shah", f)); 
         cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT); 
         cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 
         insideTable11.AddCell(cell); 


        } 
        else 
        { 

        } 
        if (colindexid.Contains(Convert.ToInt32(3))) 
        { 
         //string SC = ""; 
         //if (!string.IsNullOrEmpty(itm.ServiceCategory.ToLower())) 
         //{ 
         // SC = textInfo.ToTitleCase(itm.ServiceCategory.ToLower()); 
         //} 
         //string ST = ""; 
         //if (!string.IsNullOrEmpty(itm.ServiceType.ToLower())) 
         //{ 
         // ST = textInfo.ToTitleCase(itm.ServiceType.ToLower()); 
         //} 
         phrase = new Phrase(); 
         phrase.Add(new Chunk("Teacher" + "\n", f)); 
         phrase.Add(new Chunk("" + "\n", FontFactory.GetFont("Arial Unicode MS,Arial", 5, iTextSharp.text.Color.BLACK))); 
         cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
         cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 
         insideTable11.AddCell(cell); 


        } 
        else 
        { 

        } 


        #endregion addrow 
       } 


       insideTable1.AddCell(insideTable11); 
       table.AddCell(insideTable1); 



        insideTable2 = new PdfPTable(1); 
        insideTable2.TotalWidth = 260f; 
        insideTable2.LockedWidth = true; 
        insideTable2.DefaultCell.Border = Rectangle.NO_BORDER; 
        insideTable2.SetWidths(new float[] { 260f }); 




        insideTable22 = new PdfPTable(widthArry); 
        insideTable22.TotalWidth = 260f; 
        insideTable22.LockedWidth = true; 
        insideTable22.SetWidths(widthArry); 


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


         if (colindexid[a].ToString() == Convert.ToString(0)) 
         { 

          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; 
          insideTable22.AddCell(cell); 


         } 
         else if (colindexid[a].ToString() == Convert.ToString(1)) 
         { 

          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; 
          insideTable22.AddCell(cell); 



         } 
         else if (colindexid[a].ToString() == Convert.ToString(2)) 
         { 

          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; 
          insideTable22.AddCell(cell); 


         } 
         else if (colindexid[a].ToString() == Convert.ToString(3)) 
         { 
          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; 
          insideTable22.AddCell(cell); 



         } 

         #endregion addcolumnHeadeName 
        } 

        for (int i = 1; i <= 50; i++) 
        { 
         cnt++; 
         string Name = ""; 


         #region addrow 

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


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

          insideTable22.AddCell(cell); 

         } 
         else 
         { 

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

          phrase = new Phrase(); 
          phrase.Add(new Chunk("M1", f)); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 
          insideTable22.AddCell(cell); 
         } 
         else 
         { 

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

          phrase = new Phrase(); 
          //string SName = ""; 
          //if (!string.IsNullOrEmpty(Name.ToLower())) 
          //{ 
          // SName = textInfo.ToTitleCase(Name.ToLower()); 
          //} 
          phrase.Add(new Chunk("Raj Patel", f)); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 
          insideTable22.AddCell(cell); 


         } 
         else 
         { 

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

          //string SC = ""; 
          //if (!string.IsNullOrEmpty(itm.ServiceCategory.ToLower())) 
          //{ 
          // SC = textInfo.ToTitleCase(itm.ServiceCategory.ToLower()); 
          //} 
          //string ST = ""; 
          //if (!string.IsNullOrEmpty(itm.ServiceType.ToLower())) 
          //{ 
          // ST = textInfo.ToTitleCase(itm.ServiceType.ToLower()); 
          //} 
          phrase = new Phrase(); 
          phrase.Add(new Chunk("Sir" + "\n", f)); 
          phrase.Add(new Chunk("" + "\n", FontFactory.GetFont("Arial Unicode MS,Arial", 5, iTextSharp.text.Color.BLACK))); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 
          insideTable22.AddCell(cell); 

         } 
         else 
         { 

         } 


         #endregion addrow 

        } 
        if (result11.Count == result22.Count + 1) 
        { 
         #region addrow 

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


          phrase = new Phrase(); 
          phrase.Add(new Chunk("", f)); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 

          insideTable22.AddCell(cell); 

         } 
         else 
         { 

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

          phrase = new Phrase(); 
          phrase.Add(new Chunk("", f)); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 

          insideTable22.AddCell(cell); 
         } 
         else 
         { 

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

          phrase = new Phrase(); 
          phrase.Add(new Chunk("", f)); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 

          insideTable22.AddCell(cell); 
         } 
         else 
         { 

         } 
         if (colindexid.Contains(Convert.ToInt32(3))) 
         { 
          phrase = new Phrase(); 

          phrase.Add(new Chunk("", f)); 
          cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT); 
          cell.BorderColor = new iTextSharp.text.Color(229, 229, 229); 

          insideTable22.AddCell(cell); 

         } 
         else 
         { 

         } 

         #endregion addrow 
        } 




        insideTable2.AddCell(insideTable22); 
        table.AddCell(insideTable2); 

       document.Add(table); 

はありがとうを...

+0

テーブル内のテーブルをテーブル内に入れずに、1レベルのテーブルのみを使用してこれを試しましたか? – mkl

+0

1つのテーブルレベルでの作業が必要ですが、私の必要性は1ページあたり2行に分かれています。なぜなら、私はこれを行うのです – Herry

答えて

1

は、この行を追加します。

table.SplitLate = false; 

SplitLateのデフォルトがあることを意味しtrueですiTextSharpはページに完全な行を追加しようとします。行が収まらない場合は、次のページにスキップします。これは気づいた動作を説明しています。

+0

その作品...そのこと...ありがとうございます..... – Herry

関連する問題