42

iTextSharp を使用して表の境界線を非表示にするにはどうすればよいですか。次のコードを使用してファイルを生成しています。

var document = new Document(PageSize.A4, 50, 50, 25, 25);

// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);

document.Open();
PdfPTable table = new PdfPTable(3);
var bodyFont = FontFactory.GetFont("Arial", 10, Font.NORMAL);
PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
Font arial = FontFactory.GetFont("Arial", 6, BaseColor.BLUE);
cell = new PdfPCell(new Phrase("Font test is here ", arial));
cell.PaddingLeft = 5f;
cell.Colspan = 1;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("XYX"));
cell.Colspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Hello World"));
cell.PaddingLeft = 5f;
cell.Colspan = 1;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("XYX"));
cell.Colspan = 2;
table.AddCell(cell);



table.SpacingBefore = 5f;
document.Add(table);
document.Close();

Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=Receipt-test.pdf");
Response.BinaryWrite(output.ToArray());

個々のセルに境界線を指定する必要はありませんか、それともテーブル自体に境界線を指定できませんか?

ありがとうございました

4

6 に答える 6

11

これでうまくいくはずです:

table.DefaultCell.Border = Rectangle.NO_BORDER; 

また

table.borderwidth= 0;
于 2013-07-31T20:28:03.120 に答える
10

まず、すべてのセルの境界線を 0 に設定し、すべてのセルをテーブルに割り当てた後、pdfptable の外枠のみに次のコードを使用できます。

        PdfPCell cell = new PdfPCell();
        cell.AddElement(t);
        cell.BorderWidthBottom=1f;
        cell.BorderWidthLeft=1f;
        cell.BorderWidthTop=1f;
        cell.BorderWidthRight = 1f;
        PdfPTable t1 = new PdfPTable(1);
        t1.AddCell(cell);

ここでは、テーブルを 1 つのセルに追加し、境界線を設定して、そのセルを別のテーブルに再度追加し、要件に従って使用できます。

于 2014-03-26T05:39:53.647 に答える
4

PdfPTable が別の PdfPTable 内にネストされている場合、ネストされたテーブルにはテーブルの境界線が表示されます。テーブルの境界線を取り除く唯一の方法は、ネストされた PdfPTable をメインの PdfPTable の PdfPCell に配置し、そのセルの境界線の幅を 0 に設定することです。

iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(1); //<-- Main table
table.TotalWidth = 540f;
table.LockedWidth = true;
float[] widths = new float[] { 540f };
table.SetWidths(widths);
table.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.SpacingAfter = 10;

PdfPTable bodyTable = new PdfPTable(1); //<--Nested Table
bodyTable.TotalWidth = 540f;
bodyTable.LockedWidth = true;
float[] bodyWidths = new float[] { 540f };
bodyTable.SetWidths(bodyWidths);
bodyTable.HorizontalAlignment = 0;
bodyTable.SpacingAfter = 10;
bodyTable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;

var para1 = new Paragraph("This is a long paragraph", blackNormal);
para1.SetLeading(3f, 1f);
PdfPCell bodyCell1 = new PdfPCell();
bodyCell1.AddElement(para1);
bodyCell1.Border = 0;
bodyTable.AddCell(bodyCell1);

iTextSharp.text.pdf.PdfPCell cellBody = new iTextSharp.text.pdf.PdfPCell(bodyTable);
cellBody.BorderWidth = 0; //<--- This is what sets the border for the nested table
table.AddCell(cellBody);

これを理解するのに長い時間がかかりました。今はうまくいきます。

于 2016-02-25T21:17:48.510 に答える
3
PdfPTable table = new PdfPTable(4);
table.TotalWidth = 400f;
table.LockedWidth = true;
PdfPCell header = new PdfPCell(new Phrase("Header"));
header.Colspan = 4;
table.AddCell(header);
table.AddCell("Cell 1");
table.AddCell("Cell 2");
table.AddCell("Cell 3");
table.AddCell("Cell 4");
PdfPTable nested = new PdfPTable(1);
nested.AddCell("Nested Row 1");
nested.AddCell("Nested Row 2");
nested.AddCell("Nested Row 3");
PdfPCell nesthousing = new PdfPCell(nested);
nesthousing.Padding = 0f;
table.AddCell(nesthousing);
PdfPCell bottom = new PdfPCell(new Phrase("bottom"));
bottom.Colspan = 3;
table.AddCell(bottom);
doc.Add(table);

PdfPTable table = new PdfPTable(3);
table.TotalWidth = 144f;
table.LockedWidth = true;
table.HorizontalAlignment = 0;
PdfPCell left = new PdfPCell(new Paragraph("Rotated"));
left.Rotation = 90;
table.AddCell(left);
PdfPCell middle = new PdfPCell(new Paragraph("Rotated"));
middle.Rotation = -90;
table.AddCell(middle);
table.AddCell("Not Rotated");
doc.Add(table);

このリンクを確認してください

于 2014-07-11T14:10:07.647 に答える
1

このコードを試してください

 yourtable.DefaultCell.Border = 0;
于 2015-06-09T18:17:55.547 に答える