Domanda

I'm trying to create a simple PDF with header and table. I create the document but the table is not displayed in the document.

I followed: mikesdotnetting.com http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables

But for some reason it doesn't work for me.

I use the below code:

    Document document = new Document();
    PdfPTable table = new PdfPTable(2);
    MemoryStream ms = new MemoryStream();
    PdfWriter.GetInstance(document, ms);
    Paragraph header = new Paragraph(new Phrase("some title"));
    Phrase phrase = new Phrase("dasdasdas");
    byte[] streamBytes;

    header.Alignment = Element.ALIGN_CENTER;
    document.Open();
    document.Add(header);
    document.Add(table);

    table.AddCell("cell1");
    table.AddCell("cell2");

    document.Close();

Thanks in advance.

È stato utile?

Soluzione

You are adding the table to the document before adding anything to it. You need to fully create the table and then add it to the document.

table.AddCell("cell1");
table.AddCell("cell2");

document.Add(table);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top