如何使用itextsharp设置pdfptable的列宽与数据库列相同 [英] how to set widths of column of pdfptable same as database column using itextsharp

查看:373
本文介绍了如何使用itextsharp设置pdfptable的列宽与数据库列相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在用C#编写代码.
我已经使用itextsharp创建了表,并将表与数据库绑定
所以每次我都不知道有多少列.
我想要我的表中的列宽可以调整,就像我的数据来自数据库一样.

在下面的代码中,当且仅当我知道它们的列数(在下面的情况下,即2列),所以我在这里使用了2宽度,

Hi

I am doing code in C#.
I have created table using itextsharp, and binding my table with database,
so at every time i have no any idea about how many columns.
and i want my table in which column width is adjustable as par my data which is coming from database.

In below code ,if and only if, i know how much columns are their (in below case i.e 2 columns) so i used 2 width here ,

PdfPTable pdfTable = new PdfPTable(table.Columns.Count);
         iTextSharp.text.Rectangle rect = PageSize.LETTER;
               float pageWidth = rect.Width;
             if (pdfTable != null)
             {
                 pdfTable.SetWidthPercentage(
                         new float[] {
                        (float).15 * pageWidth ,
                         (float).15 * pageWidth,
                                      }, rect);
             }





但是当我们对列数没有任何了解时(即当我将pdfptable与我的数据库绑定时),我可以获取列数,但如何根据数据库中的数据将宽度设置为每个列的宽度.
所以请帮助我..





but when we have no any idea about number of columns(i.e when i binding pdfptable with my database) ,i can get count of columns , but how to set widths to each column widths as per data from database.
so plz help me..

推荐答案


这篇关于如何使用itextsharp设置pdfptable的列宽与数据库列相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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