pdf文档中的itextsharp表宽度 [英] itextsharp table width in pdf document

查看:129
本文介绍了pdf文档中的itextsharp表宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用c#代码创建了一个pdf文档,但我有19列,我想扩展表格的宽度.
我使用了下一个代码:
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;

字体fontTitulosDeptos = FontFactory.GetFont("Arial",9,Color.WHITE);
var celda1 = new PdfPCell(new Phrase("U.F",fontTitulosDeptos));
celda1.BackgroundColor =新颜色(172,158,117);
var celda2 = new PdfPCell(new Phrase("Piso-Depto",fontTitulosDeptos));
celda2.BackgroundColor =新颜色(172,158,117);
var celda3 = new PdfPCell(new Phrase("Propietario",fontTitulosDeptos));
celda3.BackgroundColor =新颜色(172,158,117);
var celda4 = new PdfPCell(new Phrase(%A",fontTitulosDeptos));
celda4.BackgroundColor =新颜色(172,158,117);
var celda5 = new PdfPCell(new Phrase(%B",fontTitulosDeptos));
celda5.BackgroundColor =新颜色(172,158,117);
var celda6 = new PdfPCell(new Phrase(%C",fontTitulosDeptos));
celda6.BackgroundColor =新颜色(172、158、117);
var celda7 = new PdfPCell(new Phrase(%D",fontTitulosDeptos));
celda7.BackgroundColor =新颜色(172、158、117);
var celda8 = new PdfPCell(new Phrase(%E",fontTitulosDeptos));
celda8.BackgroundColor =新颜色(172、158、117);
var celda9 = new PdfPCell(new Phrase("Exp.A",fontTitulosDeptos));
celda9.BackgroundColor =新颜色(172,158,117);
var celda10 = new PdfPCell(new Phrase("Exp.B",fontTitulosDeptos));
celda10.BackgroundColor =新颜色(172、158、117);
var celda11 = new PdfPCell(new Phrase("Exp.C",fontTitulosDeptos));
celda11.BackgroundColor =新颜色(172、158、117);
var celda12 = new PdfPCell(new Phrase("Exp.D",fontTitulosDeptos));
celda12.BackgroundColor =新颜色(172、158、117);
var celda13 = new PdfPCell(new Phrase("Exp.E",fontTitulosDeptos));
celda13.BackgroundColor =新颜色(172、158、117);
var celda14 = new PdfPCell(new Phrase("Total General",fontTitulosDeptos));
celda14.BackgroundColor =新颜色(172,158,117);
var celda15 = new PdfPCell(new Phrase("Saldo Ant",fontTitulosDeptos));
celda15.BackgroundColor =新颜色(172,158,117);
var celda16 = new PdfPCell(new Phrase("Punitorios",fontTitulosDeptos));
celda16.BackgroundColor =新颜色(172,158,117);
var celda17 = new PdfPCell(new Phrase("G.Part.",fontTitulosDeptos));
celda17.BackgroundColor =新颜色(172,158,117);
var celda18 = new PdfPCell(new Phrase("Redon.",fontTitulosDeptos));
celda18.BackgroundColor =新颜色(172,158,117);
var celda19 = new PdfPCell(new Phrase("Saldo",fontTitulosDeptos));
celda19.BackgroundColor = new Color(172,158,117);

解决方案

这取决于您如何创建文档.如果您使用iTextSharp中内置的Document类,则完成此操作相对简单.初始化文档时,请尝试使用此文档.

文档doc =  Document(PageSize.LETTER_LANDSCAPE, 1  1  25  1 ); 括号中的4个数字只是您指定的边距,可以根据需要进行修补.有3种不同的PageSize.Landscape大小可供使用. LETTER_LANDSCAPE,A4_LANDSCAPE和LEGAL_LANDSCAPE.

希望这能给您正确的方向.


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 );

解决方案

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.


这篇关于pdf文档中的itextsharp表宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆