0

enter image description here 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);
Vinoth Narayan
  • 275
  • 2
  • 15

1 Answers1

2

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:

enter image description here

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);
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Border works well and i need the rectangular box i.e Pass + Box – Vinoth Narayan Jun 24 '16 at 05:11
  • @VinothNarayan I have no idea what you mean with your comment: what does *Pass + Box* mean? I see that you say that it works well though, so I assume that your problem is solved (in which case you should *accept* the answer). If the problem isn't solved, please be more clear and explain what is wrong. – Bruno Lowagie Jun 24 '16 at 05:48
  • Border issue got solved thanks for your help...i want a small tickbox thats all – Vinoth Narayan Jun 24 '16 at 06:43
  • 1
    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. – Bruno Lowagie Jun 24 '16 at 08:22
  • CAPAContent = new PdfPCell(FormatPhrase("Male: " + "Tickbox" + Female: "Tickbox"); i wanna a tickbox after male and female – Vinoth Narayan Jun 24 '16 at 09:02
  • I repeat 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.* – Bruno Lowagie Jun 24 '16 at 10:38
  • @VinothNarayan May I suggest that you accept this answer because your problem with the table borders is now solved **and that you create a new question for your problem with the tick box?** In that new question, please tell us if you want to add a character that looks like a tick box, or if you want a check box form field. – Bruno Lowagie Jun 24 '16 at 14:47
  • @VinothNarayan I've updated my answer, assuming that you want a character. I hope you'll now find it in your heart to accept this answer. – Bruno Lowagie Jun 26 '16 at 06:48
  • @ Bruno Lowagie i wanna tick mark with box r only tick mark in pdf – Vinoth Narayan Jul 26 '16 at 05:22
  • @VinothNarayan (1.) extra questions should be posted as a new question, not as a comment. (2.) your extra question isn't clear: it's not a correct English sentence. (3.) please provide a font that has the character you want to render. – Bruno Lowagie Jul 26 '16 at 06:28
  • @Bruno Lowagie I have implemented check box from your answer but I want it checked by default do you know how is it possible? – sodhankit Mar 13 '17 at 04:47