【问题标题】:iTextSharp vertical page filliTextSharp 垂直页面填充
【发布时间】:2014-02-19 10:43:09
【问题描述】:

我正在尝试从 iTextSharp 中的 Latex 中找到类似 \vfill 的内容(一种在页面底部插入空格和放置文本的方法)。它只适用于一页,而不适用于页脚。

我在网上和 iText in Action 一书中搜索,但没有找到任何答案。

【问题讨论】:

    标签: c# java itextsharp itext


    【解决方案1】:

    好的,经过很长时间并尝试了很多东西,我找到了解决方案。

    我尝试了一些“有效”的方法,但还不够好:

    首先我计算了段落的高度(通过将其写入 RAM 中新文档的新表格中),然后我会添加换行符,直到有足够的空间容纳我的文本。结果:不是一个好方法,文本会偏离几个点(文档中的 y 位置,因为换行符)。

    然后我尝试使用 ColumnText 执行此操作:计算量过多(因为我的文档是动态的),我不喜欢将其定位为绝对。

    所以我的解决方案是使用 PdfPTable:

                var t = new PdfPTable(1);
                t.ExtendLastRow = true;
                t.WidthPercentage = 100; 
    
                var c = new PdfPCell();
                c.VerticalAlignment = Element.ALIGN_BOTTOM;
                c.DisableBorderSide(Rectangle.BOX);
    
                var p = new Paragraph("This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.");
                p.Alignment = Element.ALIGN_JUSTIFIED;
    
                c.AddElement(p);
    
                t.AddCell(c);
    
                doc.Add(t);
    

    很简单,但是我在这方面浪费了很多时间。我希望这对其他人也有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 2021-06-06
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多