• <bdo id='XV5IT'></bdo><ul id='XV5IT'></ul>

    <tfoot id='XV5IT'></tfoot>
    <i id='XV5IT'><tr id='XV5IT'><dt id='XV5IT'><q id='XV5IT'><span id='XV5IT'><b id='XV5IT'><form id='XV5IT'><ins id='XV5IT'></ins><ul id='XV5IT'></ul><sub id='XV5IT'></sub></form><legend id='XV5IT'></legend><bdo id='XV5IT'><pre id='XV5IT'><center id='XV5IT'></center></pre></bdo></b><th id='XV5IT'></th></span></q></dt></tr></i><div id='XV5IT'><tfoot id='XV5IT'></tfoot><dl id='XV5IT'><fieldset id='XV5IT'></fieldset></dl></div>
  • <small id='XV5IT'></small><noframes id='XV5IT'>

        <legend id='XV5IT'><style id='XV5IT'><dir id='XV5IT'><q id='XV5IT'></q></dir></style></legend>
      1. PdfPTable 作为 iTextSharp 中的标题

        时间:2023-08-26
          <bdo id='6LFiu'></bdo><ul id='6LFiu'></ul>

            <tbody id='6LFiu'></tbody>
          <tfoot id='6LFiu'></tfoot>
          • <legend id='6LFiu'><style id='6LFiu'><dir id='6LFiu'><q id='6LFiu'></q></dir></style></legend>
                <i id='6LFiu'><tr id='6LFiu'><dt id='6LFiu'><q id='6LFiu'><span id='6LFiu'><b id='6LFiu'><form id='6LFiu'><ins id='6LFiu'></ins><ul id='6LFiu'></ul><sub id='6LFiu'></sub></form><legend id='6LFiu'></legend><bdo id='6LFiu'><pre id='6LFiu'><center id='6LFiu'></center></pre></bdo></b><th id='6LFiu'></th></span></q></dt></tr></i><div id='6LFiu'><tfoot id='6LFiu'></tfoot><dl id='6LFiu'><fieldset id='6LFiu'></fieldset></dl></div>

                  <small id='6LFiu'></small><noframes id='6LFiu'>

                  本文介绍了PdfPTable 作为 iTextSharp 中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要一个包含大约 12 个单元格的表格来显示为标题.以下代码无法做到这一点.我知道 table2 没有 12 个单元格.在第二页上,只显示测试".我错过了什么?

                  I need a table with about 12 cells to display as a header. The following code fails to do this. I am aware table2 does not have 12 cells. On the second page, only "testing" is displayed. What am I missing?

                  提前致谢!

                  Document document = new Document();
                  
                          try
                          {
                              PdfWriter.GetInstance(document, new FileStream("TableTest.pdf", FileMode.Create));
                              document.Open();
                  
                              PdfPTable table = new PdfPTable(1);
                              table.WidthPercentage = 100;
                              PdfPTable table2 = new PdfPTable(2);
                  
                              //logo
                              PdfPCell cell2 = new PdfPCell(Image.GetInstance(@"C:path	ofile.gif"));
                              cell2.Colspan = 2;
                              table2.AddCell(cell2);
                  
                              //title
                              cell2 = new PdfPCell(new Phrase("
                  TITLE TEXT", new Font(Font.HELVETICA, 16, Font.BOLD | Font.UNDERLINE)));
                              cell2.HorizontalAlignment = Element.ALIGN_CENTER;
                              cell2.Colspan = 2;
                              table2.AddCell(cell2);
                  
                              PdfPCell cell = new PdfPCell(table2);
                              table.HeaderRows = 1;
                              table.AddCell(cell);
                              table.AddCell(new PdfPCell(new Phrase("")));
                  
                              document.Add(table);
                  
                              document.Add(new Phrase("
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  testing"));
                          }
                          catch (DocumentException de)
                          {
                              Console.Error.WriteLine(de.Message);
                          }
                          catch (IOException ioe)
                          {
                              Console.Error.WriteLine(ioe.Message);
                          }
                  
                          document.Close();
                  

                  推荐答案

                  Bingo!PdfPageEventHandler 类对我有用.

                  Bingo! PdfPageEventHandler class worked for me.

                  我使用 PdfPageEventHelper 覆盖 OnEndPage 方法:

                  I used the PdfPageEventHelper overriding the OnEndPage method:

                  class _events : PdfPageEventHelper
                  {
                      public override void OnEndPage(PdfWriter writer, Document document)
                      {
                          PdfPTable table = new PdfPTable(1);
                          //table.WidthPercentage = 100; //PdfPTable.writeselectedrows below didn't like this
                          table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //this centers [table]
                          PdfPTable table2 = new PdfPTable(2);
                  
                          //logo
                          PdfPCell cell2 = new PdfPCell(Image.GetInstance(@"C:path	ofile.gif"));
                          cell2.Colspan = 2;
                          table2.AddCell(cell2);
                  
                          //title
                          cell2 = new PdfPCell(new Phrase("
                  TITLE", new Font(Font.HELVETICA, 16, Font.BOLD | Font.UNDERLINE)));
                          cell2.HorizontalAlignment = Element.ALIGN_CENTER;
                          cell2.Colspan = 2;
                          table2.AddCell(cell2);
                  
                          PdfPCell cell = new PdfPCell(table2);
                          table.AddCell(cell);
                  
                          table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);
                      }
                  }
                  

                  然后,构建 pdf

                  Document document = new Document(PageSize.A4, 36, 36, 36 + <height of table>, 36); // note height should be set here
                  _events e = new _events();
                  PdfWriter pw = PdfWriter.GetInstance(document, new FileStream("TableTest.pdf", FileMode.Create));
                  pw.PageEvent = e;
                  document.Open();
                  
                  for(int i=0;i<100;i++)
                  {
                      document.Add(new Phrase("TESTING
                  "));
                  }
                  
                  document.Close();
                  

                  这篇关于PdfPTable 作为 iTextSharp 中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:WPF:如何冻结 ListView 标题行,使其不会滚动到屏幕 下一篇:ASP.NET 中的缓存控制标头

                  相关文章

                  最新文章

                    • <bdo id='VtFnY'></bdo><ul id='VtFnY'></ul>
                    <legend id='VtFnY'><style id='VtFnY'><dir id='VtFnY'><q id='VtFnY'></q></dir></style></legend>
                    <tfoot id='VtFnY'></tfoot>
                  1. <i id='VtFnY'><tr id='VtFnY'><dt id='VtFnY'><q id='VtFnY'><span id='VtFnY'><b id='VtFnY'><form id='VtFnY'><ins id='VtFnY'></ins><ul id='VtFnY'></ul><sub id='VtFnY'></sub></form><legend id='VtFnY'></legend><bdo id='VtFnY'><pre id='VtFnY'><center id='VtFnY'></center></pre></bdo></b><th id='VtFnY'></th></span></q></dt></tr></i><div id='VtFnY'><tfoot id='VtFnY'></tfoot><dl id='VtFnY'><fieldset id='VtFnY'></fieldset></dl></div>

                      <small id='VtFnY'></small><noframes id='VtFnY'>