Dynamic row add
Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1828
Printed Date: 16 Jul 25 at 8:02PM Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com
Topic: Dynamic row add
Posted By: pdfinfo411
Subject: Dynamic row add
Date Posted: 14 May 11 at 10:23PM
Hi, I used the code on the below lines to draw the table rows. The issue is there will be data overruns. so i use the api AppendTableRows(). This also does not seem to help prevent data overruns.
Please advise.
QuickPDFAX0724.PDFLibraryClass qp base.Library();
{ int fontID = qp.AddTrueTypeFont("Arial", 1);
qp.SetTextSize(8); qp.SelectFont(fontID);
qp.SetHTMLNormalFont("Default", fontID);
qp.SetPageSize("Letter"); qp.SetOrigin(0); }
DataTable dtAllData = getTable(); //with 200 rows of data. int ipages = qp.NewPages(20); int totalPages = qp.PageCount();
int FirstRow = 1; int FirstColumn = 1; int LastRow = dtAllData.Rows.Count; int LastColumn = dtAllData.Columns.Count; int tableID = qp.CreateTable(LastRow, LastColumn);
qp.SetTableBorderColor(tableID, 0, 1, 1, 1); qp.SetTableBorderWidth(tableID, 0, 0.1);
qp.SetTableCellTextSize(tableID, FirstRow, FirstColumn, LastRow, LastColumn, 8);
qp.SetTableCellBorderWidth(tableID, FirstRow, FirstColumn, LastRow, LastColumn, 0, 0);
qp.SetTableRowHeight(tableID, FirstRow, LastRow, 0);
QReport.RPTParam rptParam = new QReport.RPTParam(); for (int idx = 1; idx <= LastColumn; ++idx) { DataColumn dcc = dtAllData.Columns[idx - 1]; if (dcc != null) { Int32 iwidth = rptParam.GetColumnWidth(dcc); qp.SetTableColumnWidth(tableID, idx, idx, iwidth); } else {
LogMessage("Create(DataTable dtAllData, List<DataRow> lrow):
using DefaultReportColumnWidth:" +
QReport.RPTParam.DefaultReportColumnWidth.ToString()); qp.SetTableColumnWidth(tableID, idx, idx, QReport.RPTParam.DefaultReportColumnWidth); } }
qp.SetTableCellBackgroundColor(tableID, FirstRow, FirstColumn, FirstRow, LastColumn, 0.4, 0.4, 0.4);
qp.SetTableCellTextColor(tableID, FirstRow, FirstColumn, 1, LastColumn, 1, 1, 1);
qp.SetTableCellAlignment(tableID, FirstRow, FirstColumn, 1, LastColumn, 4);
for (int idx = 1; idx <= LastColumn; ++idx) { DataColumn dcc = dtAllData.Columns[idx - 1]; Int32 iAllignID = rptParam.GetDataAlignment(dcc);
qp.SetTableCellAlignment(tableID, 2, idx, LastRow, idx, iAllignID); } Func<DataRow, DataColumn, String> CDataType = delegate(DataRow drow, DataColumn dc) { { if (drow[dc].ToString().Trim().Length > 0) { if (dc.DataType == System.Type.GetType("System.DateTime")) { return Convert.ToDateTime(drow[dc]).ToShortDateString(); } else { return Convert.ToString(drow[dc]).Trim(); } } } return String.Empty; }; for (int idxr = 1; idxr <= LastRow; ++idxr) { if (idxr == 1) //column header { for (int idx = 1; idx <= dtAllData.Columns.Count; ++idx) //foreach (DataColumn column in thisTable.Columns) { DataColumn dcc = dtAllData.Columns[idx - 1]; qp.SetTableCellContent(tableID, 1, idx, dcc.ColumnName); } } else { //DataRow drow = lrow[idxr - 1]; DataRow drow = dtAllData.Rows[idxr - 1]; int trow = qp.AppendTableRows(tableID, idxr); LogMessage("QuickPDFRptTEST.PDFTest(): trow: " + trow.ToString()); if (trow == 0) { throw new NotImplementedException("Rows could not be added"); }
for (int idx = 1; idx <= dtAllData.Columns.Count; ++idx) { DataColumn dcol = dtAllData.Columns[idx - 1]; String rdata = CDataType(drow, dcol);
qp.SetTableCellContent(tableID, idxr, idx, rdata); } } } double totalheightofalltherows = qp.DrawTableRows(tableID, PDF_LEFT, PDF_TOP, PDF_HEIGHT, 1, 0);
qp.SaveToFile(outputfile);
|
Replies:
Posted By: Ingo
Date Posted: 15 May 11 at 4:17PM
Hi pdfinfo411!
What do you mean with data overrun? The text per row was cut or what? If this is the case you have to calculate by your own before using a string. What font height (pixel)? How many characters? ... to determine before how long a row should be for the string?
Cheers and welcome here, Ingo
BTW: I've deleted the other thread 'cause it's the same content ;-)
|
Posted By: pdfinfo411
Date Posted: 15 May 11 at 10:51PM
Hi, Overrun i mean as below. lets say I have a structure of 200 rows of data. I like to display lets say 40 rows of data in page 1 - now content of each row is one line. also if the content of data increases to 8 lines per row, it display only first 20 rows and the remaining 21-40 will not be show. it will be cut off. Does not automatically display in next page.
I tried using appendtablerows, but did not help. Is there a solution to this issue ?
Thanks
|
Posted By: Ingo
Date Posted: 15 May 11 at 11:01PM
So you have to set up the initial page to be large enough for 40 rows. Your pagesize "letter" together with fontsize 8 can't work! "Letter" doesn't mean the page of a letter but the envelope! Perhaps 50 rows with fontsize 8 and pagesize "A4" could be a success... Try a bigger pagesize and it will work.
Cheers, Ingo
|
|