删除 itextsharp 中的左右边框并想要一个矩形框
Remove left and right side borders in itextshap and want a rectanglur box
去掉Approved By的左右边框并签字,我还需要在校准证书编号后画一个小矩形框:
PdfPCell CalibrationContent = new PdfPCell(FormatPhrase("", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Colspan = 1;
CalibrationContent.BackgroundColor = BaseColor.WHITE;
CalibrationContent.NoWrap = true;
CalibrationContent.HorizontalAlignment = Element.ALIGN_CENTER;
PdfMastertable.AddCell(CalibrationContent);
CalibrationContent = new PdfPCell(FormatPhrase("Approved By", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Colspan = 1;
CalibrationContent.MinimumHeight = 20f;
CalibrationContent.BackgroundColor = BaseColor.WHITE;
CalibrationContent.NoWrap = true;
CalibrationContent.HorizontalAlignment =0;
pdfMastertable.AddCell(CalibrationContent);
CalibrationContent = new PdfPCell(FormatPhrase("Sign", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Colspan =1;
CalibrationContent.MinimumHeight = 20f;
CalibrationContent.BackgroundColor = BaseColor.WHITE;
CalibrationContent.NoWrap = true;
CalibrationContent.HorizontalAlignment = 0;
pdfMastertable.AddCell(CalibrationContent);
下面的代码是带有勾选框的证书编号
CAPAContent = new PdfPCell(FormatPhrase("Calibration Certificate No: " + "ddmmyy" + '\n' + "Date Issued : " + "ddmmyy" + '\n' + '\n' + "Monthly instrument type wise " + '\n' + "Test conducted Day wise" + '\n', 11, Font.NORMAL, BaseColor.BLACK));
CAPAContent.Colspan = 1;
CAPAContent.BackgroundColor = BaseColor.WHITE;
CAPAContent.NoWrap = true;
CAPAContent.Border = 0;
CAPAContent.HorizontalAlignment = Element.ALIGN_RIGHT;
pdfAction.AddCell(CAPAContent);
pdfAction.SpacingAfter = 20f;
pdfDoc.Add(pdfAction);
这确实删除了边框:
CAPAContent.Border = 0;
但每当我看到学生这样做时,我都会减分,因为使用 int
会使代码难以阅读。最好这样做:
CAPAContent.Border = Rectangle.NO_BORDER;
这样,你可以很容易地看出 0 表示:不绘制边框。
使用 Rectangle
class 中可用的常数,还告诉您还有其他选项。例如:如果您想调整屏幕截图中显示的边框,您可以这样做:
PdfPCell CalibrationContent = new PdfPCell(FormatPhrase("", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Border = Rectangle.TOP | Rectangle.LEFT | Rectangle.BOTTOM;
...
CalibrationContent = new PdfPCell(FormatPhrase("Approved By", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Border = Rectangle.TOP | Rectangle.BOTTOM;
...
CalibrationContent = new PdfPCell(FormatPhrase("Sign", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Border = Rectangle.TOP | Rectangle.RIGHT | Rectangle.BOTTOM;
这会完全按照您想要的方式调整边框。另见 Chapter 4 of "iText in Action - Second Edition", more specifically the example RotationAndColors.cs
补充答案:
你可能拒绝接受这个答案,因为我没有在评论中回答你的后续问题。但是,你也没有回答我的问题。您想要添加一个勾选框,但没有回答以下问题:您想要一个交互式的吗?即:作为实际表单字段的复选框(AcroForm 技术)。或者你想要一个复选框字符?即:一个Zapfdingbats字符,代表一个小的空方块。
假设您只想要这样的角色:
这可以通过 TickboxCharacter 示例中所示的 Zapfdingbats 字符轻松完成:
Paragraph p = new Paragraph("This is a tick box character: ");
Font zapfdingbats = new Font(Font.FontFamily.ZAPFDINGBATS, 14);
Chunk chunk = new Chunk("o", zapfdingbats);
p.add(chunk);
document.add(p);
PdfPCell CalibrationContent = new PdfPCell(FormatPhrase("", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Colspan = 1;
CalibrationContent.BackgroundColor = BaseColor.WHITE;
CalibrationContent.NoWrap = true;
CalibrationContent.HorizontalAlignment = Element.ALIGN_CENTER;
PdfMastertable.AddCell(CalibrationContent);
CalibrationContent = new PdfPCell(FormatPhrase("Approved By", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Colspan = 1;
CalibrationContent.MinimumHeight = 20f;
CalibrationContent.BackgroundColor = BaseColor.WHITE;
CalibrationContent.NoWrap = true;
CalibrationContent.HorizontalAlignment =0;
pdfMastertable.AddCell(CalibrationContent);
CalibrationContent = new PdfPCell(FormatPhrase("Sign", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Colspan =1;
CalibrationContent.MinimumHeight = 20f;
CalibrationContent.BackgroundColor = BaseColor.WHITE;
CalibrationContent.NoWrap = true;
CalibrationContent.HorizontalAlignment = 0;
pdfMastertable.AddCell(CalibrationContent);
下面的代码是带有勾选框的证书编号
CAPAContent = new PdfPCell(FormatPhrase("Calibration Certificate No: " + "ddmmyy" + '\n' + "Date Issued : " + "ddmmyy" + '\n' + '\n' + "Monthly instrument type wise " + '\n' + "Test conducted Day wise" + '\n', 11, Font.NORMAL, BaseColor.BLACK));
CAPAContent.Colspan = 1;
CAPAContent.BackgroundColor = BaseColor.WHITE;
CAPAContent.NoWrap = true;
CAPAContent.Border = 0;
CAPAContent.HorizontalAlignment = Element.ALIGN_RIGHT;
pdfAction.AddCell(CAPAContent);
pdfAction.SpacingAfter = 20f;
pdfDoc.Add(pdfAction);
这确实删除了边框:
CAPAContent.Border = 0;
但每当我看到学生这样做时,我都会减分,因为使用 int
会使代码难以阅读。最好这样做:
CAPAContent.Border = Rectangle.NO_BORDER;
这样,你可以很容易地看出 0 表示:不绘制边框。
使用 Rectangle
class 中可用的常数,还告诉您还有其他选项。例如:如果您想调整屏幕截图中显示的边框,您可以这样做:
PdfPCell CalibrationContent = new PdfPCell(FormatPhrase("", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Border = Rectangle.TOP | Rectangle.LEFT | Rectangle.BOTTOM;
...
CalibrationContent = new PdfPCell(FormatPhrase("Approved By", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Border = Rectangle.TOP | Rectangle.BOTTOM;
...
CalibrationContent = new PdfPCell(FormatPhrase("Sign", 8, Font.NORMAL, BaseColor.BLACK));
CalibrationContent.Border = Rectangle.TOP | Rectangle.RIGHT | Rectangle.BOTTOM;
这会完全按照您想要的方式调整边框。另见 Chapter 4 of "iText in Action - Second Edition", more specifically the example RotationAndColors.cs
补充答案:
你可能拒绝接受这个答案,因为我没有在评论中回答你的后续问题。但是,你也没有回答我的问题。您想要添加一个勾选框,但没有回答以下问题:您想要一个交互式的吗?即:作为实际表单字段的复选框(AcroForm 技术)。或者你想要一个复选框字符?即:一个Zapfdingbats字符,代表一个小的空方块。
假设您只想要这样的角色:
这可以通过 TickboxCharacter 示例中所示的 Zapfdingbats 字符轻松完成:
Paragraph p = new Paragraph("This is a tick box character: ");
Font zapfdingbats = new Font(Font.FontFamily.ZAPFDINGBATS, 14);
Chunk chunk = new Chunk("o", zapfdingbats);
p.add(chunk);
document.add(p);