- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 iText 的新手,我正在尝试构建一个表格。但由于某种原因 table.getDefaultCell().setBorder(PdfPCell.NO_BORDER)
没有效果,我的表格仍然有边框。
这是我的代码:
PdfPTable table = new PdfPTable(new float[] { 1, 1, 1, 1, 1 });
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
Font tfont = new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD);
table.setWidthPercentage(100);
PdfPCell cell;
cell = new PdfPCell(new Phrase("Menge", tfont));
table.addCell(cell);
cell = new PdfPCell(new Phrase("Beschreibung", tfont));
table.addCell(cell);
cell = new PdfPCell(new Phrase("Einzelpreis", tfont));
table.addCell(cell);
cell = new PdfPCell(new Phrase("Gesamtpreis", tfont));
table.addCell(cell);
cell = new PdfPCell(new Phrase("MwSt", tfont));
table.addCell(cell);
document.add(table);
你知道我做错了什么吗?
最佳答案
您正在混合两个不同的概念。
概念 1:您手动定义每个 PdfPCell
,例如:
PdfPCell cell = new PdfPCell(new Phrase("Menge", tfont));
cell.setBorder(Rectangle.NO_BORDER);
table.addCell(cell);
在这种情况下,您可以在单元格本身上定义单元格的每个方面、每个属性。
概念 2:您允许 iText 隐式创建 PdfPCell
,例如:
table.addCell("Adding a String");
table.addCell(new Phrase("Adding a phrase"));
在这种情况下,您可以在默认单元格 级别定义属性。当 iText 在您的位置创建 PdfPCell
时,这些属性将在内部使用。
结论:
要么单独为所有 PdfPCell
实例定义边框,要么让 iText 创建 PdfPCell
实例,在这种情况下,您可以在默认单元格。
如果您选择第二个选项,您可以像这样调整您的代码:
PdfPTable table = new PdfPTable(new float[] { 1, 1, 1, 1, 1 });
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
Font tfont = new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD);
table.setWidthPercentage(100);
table.addCell(new Phrase("Menge", tfont));
table.addCell(new Phrase("Beschreibung", tfont));
table.addCell(new Phrase("Einzelpreis", tfont));
table.addCell(new Phrase("Gesamtpreis", tfont));
table.addCell(new Phrase("MwSt", tfont));
document.add(table);
这个决定是根据经验通过设计做出的:它提供了最灵活的单元格和属性。
关于java - iText 5 getDefaultCell().setBorder(PdfPCell.NO_BORDER) 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27212695/
我试图弄清楚如何让 PdfPCell 中的文本显示在中间。我尝试了很多不同的选择,例如: myCell.VerticalAlignment = Element.ALIGN_MIDDLE;myCell.
我正在使用 itext 的 pdfptable 做一个包含 1000 多条记录的报告。查找特定记录并不容易,所以我想知道是否有任何方法可以在 pdfpcell 中添加书签。 最佳答案 要使用 iTex
我有这部分代码: //Staff // Title font BaseFont titleBf = null; try { titleBf = BaseFont.createFont(BaseFont
我正在使用这段代码水平对齐。 cell = New PdfPCell(); p = New Phrase("value"); cell.AddElement(p); cell.HorizontalAl
我有一个生成 PDF 发票的 C# 应用程序。这张发票中有一个项目和价格表。这是使用 PdfPTable 和 PdfPCell 生成的。 我希望能够右对齐价格列,但我似乎做不到 - 文本在单元格中总是
我正在使用 iTextSharp 创建 PDF,如何将 textField 添加到 PdfPCell 中? 最佳答案 您不会真正向 PdfPCell 添加“文本字段”,而是创建一个 PdfPCell
我有一个使用 PDFPTable 生成的图表,如下所示。 -------------------------------------- |Caption|Figure Title
我在设置颜色时遇到了一个奇怪的问题。以下代码有效: Font nameFont=new Font(FontFamily.TIMES_ROMAN, 20.f, Font.BOLD,new BaseCol
我有一个使用 PDFPTable 生成的图表,如下所示。 -------------------------------------- |Caption|Figure Title
我正在使用 iText 2.1.7 生成 PDF 文档。我对嵌套列表有疑问。将嵌套列表添加到文档时它可以正常工作。但是,如果将相同的嵌套列表添加到 PdfPCell(其本身是 PdfPTable 的一
在页面上我有表格,在页面末尾我有一个段落,如果行包含少量行,则段落仍必须保留在页面末尾,但如果行太多且表格占用多个段落页段必须紧接在表格末尾之后。起初,这对我来说看起来很简单,我只是为包含表格的 Pd
我想将文本引入 PdfPCell 并且我希望部分文本缩进。这是我尝试过的: PdfPCell cell21 = new PdfPCell(new Phrase("TO:\n\n name"));
我有这个 iTextSharp 代码可以为 PDF 文件中的单元格提供绿色背景: PdfPCell cellSec2 = new PdfPCell(parSectionHeading2); cellS
我有一个可以生成 PDF 发票的 C# 应用程序。此发票中有一个项目和价格表。这是使用 PdfPTable 和 PdfPCell 生成的。 我希望能够右对齐价格列,但我似乎无法做到 - 文本在单元格中
我正在尝试使用 iTextSharp 在段落句子的中间添加一个 TextField (acrofield)。一个例子是“生效日期是 [月] 日,[年] 日,这将开始。” 我尝试过的事情: Paragr
如何使用 itextsharp 将具有特定宽度、高度和背景颜色的矩形添加到 PdfPCell 中? 像这样: PdfPCell cell = new PdfPC
我正在构建一个垂直的月份列表,每个月都有一个水平的天数列表。我每天都添加一个大小和颜色的矩形;大小和颜色取决于来自数据库查询的值。 我正在使用 this answer 中提供的 PdfPTable、P
我想要一个 PdfPCell 类的单元格表,每个单元格都有一个小标题、主字符串和小页脚。我找不到插入它们的方法,因为不允许将 HeaderandFooter 元素添加到单元格,一个段落覆盖另一个段落等
我想在一个 PdfPCell 中添加多个 Phrase。我担心的是,我想展示在一个单元格中,“创建日期:”为灰色字体,而“日期”为黑色字体。 那么,有没有办法做到这一点?请帮忙。 代码就像, PdfP
当我使用单元格的对齐方式时,它会起作用: PdfPCell cell1 = new PdfPCell(new Phrase("Text" , Font)); cell1.HorizontalAlign
我是一名优秀的程序员,十分优秀!