删除itextshap中的左侧和右侧边框,并想要一个rectanglur框 [英] 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+'\\\
'+Date Issued:+ddmmyy+'\ +'\ 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
类中可用的常量,还教会您还有其他选项。例如:如果你想调整屏幕截图中所示的边框,你可以这样做:
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;
这样可以按照你想要的方式调整边框。另请参见
这可以使用Zapfdingbats字符轻松完成,如 TickboxCharacter 示例:
段落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);
Remove the left and right side borders of Approved By and sign and also i need to draw a small rectangular box after calibration certificate no:
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);
Below code is for that certificate number with Tick box
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);
This indeed removes the border:
CAPAContent.Border = 0;
But whenever I see a student doing this, I'd subtract a point because using an int
makes the code hard to read. It's better to do this:
CAPAContent.Border = Rectangle.NO_BORDER;
This way, you can easily see the 0 means: no border will be drawn.
Using the constants that are available in the Rectangle
class, also teaches you that there are other options. For instance: If you want to tweak the borders as shown in your screen shot, you can do this:
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;
This tweaks the borders exactly the way you want to. See also Chapter 4 of "iText in Action - Second Edition", more specifically the example RotationAndColors.cs
Extra answer:
You probably refuse to accept this answer because I didn't answer your follow-up question in the comments. However, you didn't answer my question either. You want to add a tick box, but you aren't answering the question: Do you want an interactive one? That is: a check box that is an actual form field (AcroForm technology). Or do you want a check box character? That is: a Zapfdingbats character that represents a small empty square.
Let's assume that you merely want a character like this:
That can be easily done with a Zapfdingbats character as shown in the TickboxCharacter example:
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);
这篇关于删除itextshap中的左侧和右侧边框,并想要一个rectanglur框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!