iText(Sharp) - Text is different when drawn with cell event vs. directly

白昼怎懂夜的黑 提交于 2019-12-06 07:30:14
Bruno Lowagie

There is something very wrong with this snippet:

ColumnText ct = new ColumnText(canvases[0]);
ct.SetSimpleColumn(r);
ct.AddElement(new PdfPCell(new Phrase("Dude", f2)));
ct.Go();

More specifically:

ct.AddElement(new PdfPCell(new Phrase("Dude", f2)));

You can not use the PdfPCell object outside of the context of a PdfPTable.

As for the differences between content in PdfPCell and ColumnText, you may want to read the answers to these questions:

The content of a PdfPCell is actually stored in a ColumnText object, but a PdfPCell may have a padding.

There's also text mode versus composite mode. You are talking about the distance between two lines. In text mode, this distance is defined at the level of the PdfPCell/ColumnText using the setLeading() method. In composite mode, this parameter is ignored. Instead, the leading of the elements added to the PdfPCell/ColumnText is used.

For instance: if p1, p2 and p3 are three Paragraph objects, each having a different leading, then ct will have text with three different leadings if you do this:

ct.addElement(p1);
ct.addElement(p2);
ct.addElement(p3);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!