【问题标题】:issue with table border while using itextsharp in asp.net在 asp.net 中使用 itextsharp 时出现表格边框问题
【发布时间】:2013-06-13 06:25:43
【问题描述】:

我需要使用 itextsharp 构建一个 pdf。目前我的问题是我无法将表格边框宽度设为 0px。我不想要表格或单元格边框.. 我的代码是

Document Doc = new Document();
    //PdfWriter.GetInstance(Doc, new FileStream(Environment.GetFolderPath
    //(Environment.SpecialFolder.Desktop) + "\\TTS_Bill.pdf", FileMode.Create));

    PdfWriter.GetInstance(Doc, new FileStream(Server.MapPath("~/DMSDOC/DMS_doc.pdf"), FileMode.Create));

    Doc.Open();

    PdfPTable table = new PdfPTable(1);
    table.DefaultCell.Border = PdfPCell.NO_BORDER;

    table.TotalWidth = 400f;

    table.LockedWidth = true;

    iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("~/img/val verde hospital.png");
    logo.ScaleAbsolute(40, 40);

    PdfPCell image_header = new PdfPCell(logo);
    image_header.HorizontalAlignment = Element.ALIGN_CENTER;
    table.AddCell(image_header)

如何解决或者我的代码有什么错误...

【问题讨论】:

  • 请提供一个示例 PDF 来说明问题并允许调查边界的起源。

标签: asp.net itextsharp


【解决方案1】:

前面的答案几乎是正确的。

设置DefaultCell 没问题,但仅当您将AddCell()string 值或Phrase 对象一起使用时才有效。如果你创建自己的PdfPCell,你需要这样的东西:

image_header.Border = PdfPCell.NO_BORDER;

【讨论】:

    【解决方案2】:

    试试这两个中的任何一个。

    table.borderwidth= 0; 
    

    table.DefaultCell.BorderWidth = 0 
    table.DefaultCell.Border = iText.Rectangle.NO_BORDER 
    

    希望这会有所帮助。请让我知道这是否有效。由于我现在没有安装 itext sharp,所以无法测试。

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      相关资源
      最近更新 更多