Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I created a pdf document from c# code but I have a 19 columns and I would like to extend the width of the table.
I used the next code:
var tablaDeptos = new PdfPTable(19);
//float[] widths = new float[] { 1, 1.5F, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1.5F, 2 };
float[] widths = new float[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
tablaDeptos.SetWidths(widths);
tablaDeptos.TotalWidth = 900f;

Font fontTitulosDeptos = FontFactory.GetFont("Arial", 9, Color.WHITE);
var celda1 = new PdfPCell(new Phrase("U.F", fontTitulosDeptos));
celda1.BackgroundColor = new Color(172, 158, 117 );
var celda2 = new PdfPCell(new Phrase("Piso-Depto", fontTitulosDeptos));
celda2.BackgroundColor = new Color(172, 158, 117 );
var celda3 = new PdfPCell(new Phrase("Propietario", fontTitulosDeptos));
celda3.BackgroundColor = new Color(172, 158, 117 );
var celda4 = new PdfPCell(new Phrase("%A", fontTitulosDeptos));
celda4.BackgroundColor = new Color(172, 158, 117 );
var celda5 = new PdfPCell(new Phrase("%B", fontTitulosDeptos));
celda5.BackgroundColor = new Color(172, 158, 117 );
var celda6 = new PdfPCell(new Phrase("%C", fontTitulosDeptos));
celda6.BackgroundColor = new Color(172, 158, 117);
var celda7 = new PdfPCell(new Phrase("%D", fontTitulosDeptos));
celda7.BackgroundColor = new Color(172, 158, 117);
var celda8 = new PdfPCell(new Phrase("%E", fontTitulosDeptos));
celda8.BackgroundColor = new Color(172, 158, 117);
var celda9 = new PdfPCell(new Phrase("Exp. A", fontTitulosDeptos));
celda9.BackgroundColor = new Color(172, 158, 117 );
var celda10 = new PdfPCell(new Phrase("Exp. B", fontTitulosDeptos));
celda10.BackgroundColor = new Color(172, 158, 117);
var celda11 = new PdfPCell(new Phrase("Exp. C", fontTitulosDeptos));
celda11.BackgroundColor = new Color(172, 158, 117);
var celda12 = new PdfPCell(new Phrase("Exp. D", fontTitulosDeptos));
celda12.BackgroundColor = new Color(172, 158, 117);
var celda13 = new PdfPCell(new Phrase("Exp. E", fontTitulosDeptos));
celda13.BackgroundColor = new Color(172, 158, 117);
var celda14 = new PdfPCell(new Phrase("Total General", fontTitulosDeptos));
celda14.BackgroundColor = new Color(172, 158, 117 );
var celda15 = new PdfPCell(new Phrase("Saldo Ant", fontTitulosDeptos));
celda15.BackgroundColor = new Color(172, 158, 117 );
var celda16 = new PdfPCell(new Phrase("Punitorios", fontTitulosDeptos));
celda16.BackgroundColor = new Color(172, 158, 117 );
var celda17 = new PdfPCell(new Phrase("G. Part.", fontTitulosDeptos));
celda17.BackgroundColor = new Color(172, 158, 117 );
var celda18 = new PdfPCell(new Phrase("Redon.", fontTitulosDeptos));
celda18.BackgroundColor = new Color(172, 158, 117 );
var celda19 = new PdfPCell(new Phrase("Saldo", fontTitulosDeptos));
celda19.BackgroundColor = new Color(172, 158, 117 );
Posted
Comments
Yvan Rodrigues 15-Jul-12 17:38pm    
And what is the problem you are facing?
gabrieler 15-Jul-12 23:44pm    
I would like to extend more the width of the table or rotate the sheet because the text in the fields is long and the fields are small.

1 solution

It depends on how you are creating the document. If you are using the Document class built into iTextSharp, it's relatively simple to accomplish this. When you initiate the document, try using this.

C#
Document doc = new Document(PageSize.LETTER_LANDSCAPE, 1, 1, 25, 1);
The 4 numbers in the parentheses are simply your specified Margins, and can be tinkered with as you please. There are 3 different PageSize.Landscape sizes available to use. LETTER_LANDSCAPE, A4_LANDSCAPE, and LEGAL_LANDSCAPE.

I hope this sends you in the right direction.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900