删除itextshap中的左侧和右侧边框,并想要一个矩形框

时间:2016-06-23 12:30:14

标签: asp.net c#-4.0 itext

enter image description here 删除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);

1 个答案:

答案 0 :(得分:2)

这确实消除了边界:

CAPAContent.Border = 0;

但每当我看到学生这样做时,我都会减去一个点,因为使用int会使代码难以阅读。最好这样做:

CAPAContent.Border = Rectangle.NO_BORDER;

这样,您可以轻松看到0表示:不会绘制边框。

使用Rectangle类中提供的常量,还会教您还有其他选项。例如:如果您想调整屏幕截图中显示的边框,可以执行以下操作:

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",更具体地说,示例RotationAndColors.cs

额外答案:

您可能拒绝接受此答案,因为我在评论中没有回答您的后续问题。但是,你也没有回答我的问题。你想添加一个勾选框,但你没有回答这个问题:你想要一个互动的吗?即:一个复选框,它是一个实际的表单字段(AcroForm技术)。或者你想要一个复选框字符?那就是:一个Zapfdingbats字符代表一个小空方块。

我们假设您只想要一个这样的角色:

enter image description here

使用Zapfdingbats字符可以轻松完成,如TickboxCharacter示例所示:

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);