Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PDF table itextsharp
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 15-Jul-12 11:55am
Comments
Yvan Rodrigues at 15-Jul-12 17:38pm
   
And what is the problem you are facing?
gabrieler at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
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.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 325
2 Richard MacCutchan 265
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411028.1 | Last Updated 18 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100