【问题标题】:iTextSharp - Paragraph Line-HeightiTextSharp - 段落行高
【发布时间】:2015-04-04 23:23:55
【问题描述】:

我目前正在处理 PDF,但在尝试增加 Paragraph 的行高时遇到了问题,这是我现在拥有的代码:

var tempTable = new PdfPTable(1);

cell = new PdfPCell(new Paragraph("My Account", GetInformationalTitle()));
cell.Border = Rectangle.NO_BORDER;
tempTable.AddCell(cell);

cell = new PdfPCell(new Paragraph("http://www.google.com/", GetInformationalOblique()));
cell.Border = Rectangle.NO_BORDER;
cell.PaddingBottom = 10f;
tempTable.AddCell(cell);

var para = new Paragraph("Login to 'My Account' to access detailed information about this order. " +
"You can also change your email address, payment settings, print invoices & much more.", GetInformationalContent());
 para.SetLeading(0f, 2f);

 cell = new PdfPCell(para);
 cell.Border = Rectangle.NO_BORDER;
 tempTable.AddCell(cell);

正如你从上面看到的,我正在尝试增加para 的行高,我已经尝试过para.SetLeading(0f, 2f),但它仍然没有增加行高或前导,因为它被称为。

这可能是什么问题?

【问题讨论】:

  • 此问题与iText: maintain identing if paragraph takes new line in PdfPCell 不完全相同,但答案是相同的:您是在文本模式 中添加Paragraph,而不是在复合模式。在您的情况下,PdfPCell 的前导优先于 Paragraph 的前导(因为您已经注意到在 文本模式 中忽略了前导)。
  • 太棒了!我已经通过使用AddElement(para) 来修复它,而不是在构造函数中对其进行初始化。您可能想将其发布在答案中,以便我可以将其标记为已回答,再次感谢!

标签: c# pdf pdf-generation itextsharp typography


【解决方案1】:

您在文本模式中添加para,而不是在复合模式中添加它。文本模式意味着PdfPCell 的前导将优先于为Paragraph 定义的前导。在复合模式下,情况正好相反。

你可以通过一个小的改动来解决这个问题:

cell = new PdfPCell();
cell.addElement(para);
tempTable.AddCell(cell);

使用addElement() 方法使cell 从文本模式切换到复合模式。

【讨论】:

    猜你喜欢
    • 2012-02-24
    • 2011-02-07
    • 2015-09-11
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2011-04-20
    相关资源
    最近更新 更多