locked
I TEXT Sharp RRS feed

  • Question

  • User608832087 posted

    Hi All

    I'm trying to create a PDF for the below table structure using itext sharp

    i'm using the below code

    Table is getting created with 2 coumns and 4 rows

    please help me out.

    thanks

    Sunday, December 14, 2014 2:32 AM

All replies

  • User622904130 posted

    I would make my first table 1 row with 2 columns, then I would create another table in my second column with 1 column and 4 rows.  basically nest your tables. 

    public static void createDemoPDF()
    {
    	iTextSharp.text.Document doc = new iTextSharp.text.Document();
    	MemoryStream ms = new MemoryStream();
    	PdfWriter writer = null;
    	writer = PdfWriter.GetInstance(doc, ms);
    
    	doc.Open();
    
    	PdfContentByte cb = writer.DirectContent;
    
    	// set table style properties
    	PdfPTable newTable = new PdfPTable(2) { WidthPercentage = 100 };
    	// set *column* widths
    	newTable.SetWidths(new float[] {
    		0.6,
    		0.4
    	});
    
    	newTable.AddCell("right");
    
    	PdfPTable childTbl = new PdfPTable(1) { WidthPercentage = 100 };
    	for (int i = 1; i <= 4; i++) {
    		childTbl.AddCell(string.Format("row_{0}", i));
    	}
    
    	newTable.AddCell(childTbl);
    
    	doc.Add(newTable);
    
    	doc.Close();
    
    	byte[] fbytes = ms.GetBuffer;
    
    	string reportPath = string.Format("U:\\EmailDropFolder\\Test_{0}.pdf", Strings.Format(Now, "yyyyMMdd_hhmmss"));
    
    	using (FileStream fs = new FileStream(reportPath, FileMode.Create)) {
    		fs.Write(fbytes, 0, fbytes.Length);
    	}
    
    }
    

    Monday, December 15, 2014 10:51 AM