2016-03-24 19 views
1

In iTextSharp, wie der Raum zwischen zwei Zellen einzustellen (PdfPCell)Wie stellt Raum zwischen zwei Zellen

Code:

var doc = new Document(); 
PdfWriter.GetInstance(doc, new FileStream("C:/Doc1.pdf", FileMode.Create)); 

doc.Open(); 

PdfPTable table = new PdfPTable(1); 

PdfPCell cell1 = new PdfPCell(new Phrase("Cell1")); 
cell1.Colspan = 1; 
table2.AddCell(cell1); 

PdfPCell cell2 = new PdfPCell(new Phrase("Cell2")); 
cell2.Colspan = 1; 
table2.AddCell(cell2); 

doc.Add(table); 

System.Diagnostics.Process.Start("C:/Doc1.pdf"); 

Hier sind zwei Zellen entstehen ( linken Rand des cell2 überlappt mit cell1s Grenze rechts). Aber ich brauche ein wenig Raum zwischen 2 Zellen.

+0

Funktioniert das? http://stackoverflow.com/a/10232822/231316 –

+0

Ich habe es schon versucht. Aber die Grenzüberschneidung ist da ... Ich habe das Ziel erreicht und als Antwort gepostet. Bitte beachten Sie das. – User1674987

Antwort

0

erreicht I durch width für die Spalten in der Tabelle Einstellung, wie folgend.

table.SetWidths(new float[] { 1f, 0.1f, 1f }); 

PdfPCell cell1 = new PdfPCell(new Phrase("Cell1")); 
table.AddCell(cell1); 

//dummy cell created to have an empty space with width `0.1f` which was declared //above. 
PdfPCell cell2 = new PdfPCell(new Phrase("")); 
table.AddCell(cell2); 

PdfPCell cell3 = new PdfPCell(new Phrase("Cell3")); 
table.AddCell(cell3); 
1

Spielen Sie ein wenig mit Cellpadding. Wie folgt aus:

var doc = new Document(); 
PdfWriter.GetInstance(doc, new FileStream("C:/Doc1.pdf", FileMode.Create)); 

doc.Open(); 

PdfPTable table = new PdfPTable(1); 

PdfPCell cell1 = new PdfPCell(new Phrase("Cell1")); 
cell1.Colspan = 1; 
cell.PaddingRight = 20f; //Here you can set padding (Top, Bottom, Right, Left) 
table2.AddCell(cell1); 

PdfPCell cell2 = new PdfPCell(new Phrase("Cell2")); 
cell2.Colspan = 1; 
table2.AddCell(cell2); 

doc.Add(table); 

System.Diagnostics.Process.Start("C:/Doc1.pdf"); 
+0

Nein. Ich habe es versucht. Die Änderungen finden innerhalb der Zellen statt. Meine Frage ist zwischen zwei Zellen, ich brauche ein Leerzeichen. – User1674987