2009-09-26 9 views
16

Próbuję dodać tabelę do dokumentu za pomocą iTextSharp. Oto przykład:iTextSharp szerokość stołu 100% strony

Document document = new Document(PageSize.LETTER,72, 72, 72, 72); 
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C:\\test.pdf", FileMode.Create)); 

document.Open(); 
Table table = new Table (2, 1); 
table.Width = document.RightMargin - document.LeftMargin; 

// Cell placeholder 
Cell cell = new Cell (new Paragraph ("Some Text")); 
table.AddCell (cell); 
cell = new Cell (new Paragraph ("More Text")); 
table.AddCell (cell); 
document.Add (table); 
document.Close (); 

Ustawiam szerokość stołu tak, aby rozszerzyć margines strony. Ale po utworzeniu pliku PDF tabela zajmuje tylko około 80% przestrzeni między marginesami. Czy robię coś niepoprawnie tutaj?

Odpowiedz

50

W najnowszej wersji iTextSharp (5.0.4) PdfPTable ma właściwość WidthPercentage. Aby uzyskać wartość statyczną, właściwość ta to TotalWidth.

+1

[5.5.9] TotalWidth nie jest statyczną wartością - jest to po prostu właściwość obiektu. – MaLiN2223

30

Wyliczyłem to. Podobno table.Width to procent, a nie szerokość w pikselach. Więc używając:

table.Width = 100; 

Pracował jak urok.

2

Użytkownicy mogą również ustawić szerokość stołu według wartości procentowej.

t.WidthPercentage = 100f; 
+2

Przyjęta odpowiedź już to mówi. – Kyle

Powiązane problemy