是否可以在iTextSharp中的表格(PdfPTable)中有单元格间距?我无法看到任何可能的地方。我确实看到了一个使用iTextSharp.text.Table的建议,但在我的iTextSharp(5.2.1)版本中似乎没有。iTextSharp表格单元格间距可能?
6
A
回答
1
Table类已从5.x开始从iText中删除,以支持PdfPTable。
至于间距,你要找的是setPadding方法。
看一看的iText的API的更多信息:
http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfPCell.html
(这对Java版本,但C#端口维护的方法的名称)
13
如果你正在寻找对于真正的单元格间距,如HTML,则不是,PdfPTable
本身不支持。然而,PdfPCell
支持一个属性,该属性需要IPdfPCellEvent
的自定义实现,只要单元布局发生,该属性就会被调用。下面是一个简单的实现,你可能想调整它以满足你的需求。
public class CellSpacingEvent : IPdfPCellEvent {
private int cellSpacing;
public CellSpacingEvent(int cellSpacing) {
this.cellSpacing = cellSpacing;
}
void IPdfPCellEvent.CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
//Grab the line canvas for drawing lines on
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
//Create a new rectangle using our previously supplied spacing
cb.Rectangle(
position.Left + this.cellSpacing,
position.Bottom + this.cellSpacing,
(position.Right - this.cellSpacing) - (position.Left + this.cellSpacing),
(position.Top - this.cellSpacing) - (position.Bottom + this.cellSpacing)
);
//Set a color
cb.SetColorStroke(BaseColor.RED);
//Draw the rectangle
cb.Stroke();
}
}
要使用它:
//Create a two column table
PdfPTable table = new PdfPTable(2);
//Don't let the system draw the border, we'll do that
table.DefaultCell.Border = 0;
//Bind our custom event to the default cell
table.DefaultCell.CellEvent = new CellSpacingEvent(2);
//We're not changing actual layout so we're going to cheat and padd the cells a little
table.DefaultCell.Padding = 4;
//Add some cells
table.AddCell("Test");
table.AddCell("Test");
table.AddCell("Test");
table.AddCell("Test");
doc.Add(table);
-4
尝试
PdfPTable table = new PdfPTable(2);
table.getDefaultCell().setBorder(0);
table.getDefaultCell().setPadding(8);
table.addCell("Employee ID");
table.addCell("");
table.addCell("Employee Name");
table.addCell("");
table.addCell("Department");
table.addCell("");
table.addCell("Place");
table.addCell("");
table.addCell("Contact Number");
table.addCell("");
document.add(table);
相关问题
- 1. 表格单元格间距
- 2. CSS表格单元格边距,间距
- 3. 设置iTextSharp中图像网格之间的边距或单元格间距PdfPTable
- 4. Drupal单元格间距
- 5. 单元格间距问题
- 6. 使用CSS的表单元格间距
- 7. 文本间距表单元格
- 8. 在div表中的单元格间距
- 9. 表格单元格间距被空格分隔:nowrap
- 10. 在基本表格视图单元格之间添加间距
- 11. GWT listgrid单元格之间的间距
- 12. CollectionView中单元格之间的间距
- 13. 表格间距
- 14. iTextSharp的变化表单元格数据
- 15. 在iOS上缩放时禁用表格单元格间距Safari
- 16. 使用CSS/HTML的单元格表格间距
- 17. 如何在表格中只水平设置单元格间距
- 18. 间距的表格单元格的CSS/JavaScript的/ JQuery的
- 19. 1px表格单元格之间的差距
- 20. 跨表格单元格间距的浏览器支持
- 21. CSS - 边框只与表格中的单元格间距
- 22. 是否可以模拟表格单元格之间的间距,使得垂直和水平间距不同?
- 23. 表格单元格/表格/表格单元格。不能居中垂直中间元素
- 24. GWT DockLayoutPanel单元格之间的差距
- 25. CollectionView单元格中的间距
- 26. 单元格间距,插图中的CollectionView
- 27. 只添加单元格间距
- 28. 动态更改单元格间距UICollectionView
- 29. 表格单元格之间的空格
- 30. 间距HTML表格
感谢您的但是这是用于添加细胞填充(在细胞内)。我需要的是单元格间距(单元格之间)。 – 2012-04-20 11:49:32