【问题标题】:Remove left and right side borders in itextshap and want a rectanglur box去掉itextsharp中的左右边框,想要一个矩形框
【发布时间】:2016-06-23 12:30:14
【问题描述】:

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

【问题讨论】:

    标签: asp.net c#-4.0 itext


    【解决方案1】:

    这确实删除了边框:

    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

    额外答案:

    您可能拒绝接受这个答案,因为我没有在 cmets 中回答您的后续问题。然而,你也没有回答我的问题。您想添加一个复选框,但您没有回答问题:您想要一个交互式的吗?即:作为实际表单域的复选框(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);
    

    【讨论】:

    • 边框效果很好,我需要矩形框,即 Pass + Box
    • @VinothNarayan 我不明白你的评论是什么意思:Pass + Box 是什么意思?我看到你说它运作良好,所以我假设你的问题已经解决(在这种情况下你应该接受答案)。如果问题没有解决,请更清楚并解释问题所在。
    • 边界问题已解决,感谢您的帮助...我想要一个小复选框,仅此而已
    • 你想要一个交互式的吗?即:作为实际表单域的复选框(AcroForm 技术)。或者你想要一个复选框字符?即:一个 Zapfdingbats 字符,代表一个小空方块。
    • CAPAContent = new PdfPCell(FormatPhrase("Male: " + "Tickbox" + Female: "Tickbox"); 我想在男性和女性之后的复选框
    猜你喜欢
    • 2014-08-05
    • 2016-09-23
    • 2011-01-24
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    相关资源
    最近更新 更多