通过我的Android应用程序,我正在生成报价pdf,其中正确的报价格式必须如下图所示:
但是在开发时,项目表不会分裂。相反,整个表格正在转移到下一页。以下是结果,我现在开始:
正如您所看到的,如果行数很多,表格不会在第一页上拆分。下面我发布了项目列表表的代码:
// For loop for formatting and adding individual rows for the item list
for(int i = 0; i< quoteEntryFragment.alst_queryDetailList.size(); i++)
{
String str_catalogName = quoteEntryFragment.alst_queryDetailList.get(i).getStr_CatalogName();
String str_catalogDesc = quoteEntryFragment.alst_queryDetailList.get(i).getStr_CatalogDescription();
int int_UPC_Number = quoteEntryFragment.alst_queryDetailList.get(i).getInt_UPCNumber();
Paragraph paragraph_description1 = new Paragraph("",normalFontSmaller);
paragraph_description1.add(str_catalogName+"\n");
Paragraph paragraph_description2 = new Paragraph("",normalFontSmaller);
paragraph_description2.add(str_catalogDesc+"\n");
Paragraph paragraph_description21 = new Paragraph("UPC Number:", boldFontSmaller);
Paragraph paragraph_description22 = new Paragraph("", normalFontSmaller);
if(int_UPC_Number==-1)
{
paragraph_description22.add("");
}
else
{
paragraph_description22.add(int_UPC_Number+"");
}
Paragraph paragraph_description31 = new Paragraph( "\nPackage Quantity:"+quoteEntryFragment.
alst_queryDetailList.get(i).getInt_PackageQuantity()+"\n",normalFontSmaller);
Paragraph paragraph_description32 = new Paragraph( "Min Ord Qty:"+quoteEntryFragment.
alst_queryDetailList.get(i).getInt_MinOrdQty()+"\n",normalFontSmaller );
Paragraph paragraph_description41 = new Paragraph("Quote Lead Time :", boldFontSmaller);
String str_number_of_weeks = "";
if( quoteEntryFragment.alst_queryDetailList.get(i).getInt_QuoteLeadTime()==-1)
{
str_number_of_weeks = "";
}
else
{
str_number_of_weeks = quoteEntryFragment.alst_queryDetailList.get(i).getInt_QuoteLeadTime()+"WEEKS";
}
Paragraph paragraph_desLast = new Paragraph(str_number_of_weeks+"\n" +
"Made to order item. Cancellation or restocking charges will apply", normalFontSmallest);
// Creating the value in the 2nd column of every row
Paragraph combination_item = new Paragraph();
combination_item. add(paragraph_description1);
combination_item. add(paragraph_description2);
combination_item. add(paragraph_description21);
combination_item. add(paragraph_description22);
combination_item. add(paragraph_description31);
combination_item. add(paragraph_description32);
combination_item. add(paragraph_description41);
combination_item. add(paragraph_desLast);
combination_item.setKeepTogether(false);
Paragraph np = new Paragraph((i+1)+"", normalFontSmaller);
Paragraph quantity = new Paragraph(quoteEntryFragment.alst_queryDetailList.get(i).getInt_quantity()+"", normalFontSmaller);
Paragraph UoM = new Paragraph("EA", normalFontSmaller);
Paragraph NUP = new Paragraph(quoteEntryFragment.alst_queryDetailList.get(i).getDbl_price()+"",normalFontSmaller);
double dbl_itemQuantity = (double)quoteEntryFragment.alst_queryDetailList.get(i).getInt_quantity();
double dbl_itemPrice = quoteEntryFragment.alst_queryDetailList.get(i).getDbl_price();
double dbl_totalPrice = dbl_itemPrice*dbl_itemQuantity;
DecimalFormat dformat = new DecimalFormat("#.##");
String str_formatted = dformat.format(dbl_totalPrice);
totalPrice[i] =Double.parseDouble(str_formatted);
Paragraph extPrice = new Paragraph(str_formatted, normalFontSmaller);
PdfPCell cellVal = new PdfPCell(np);
cellVal.setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell cellVal3 = new PdfPCell(combination_item);
cellVal3.setHorizontalAlignment(Element.ALIGN_LEFT);
cellVal3.setPaddingBottom(10.0f);
PdfPCell cellVal4 = new PdfPCell(quantity);
cellVal4.setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell cellVal5 = new PdfPCell(UoM);
cellVal5.setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell cellVal6 = new PdfPCell(NUP);
cellVal6.setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell cellVal7 = new PdfPCell(extPrice);
cellVal7.setHorizontalAlignment(Element.ALIGN_CENTER);
itemList.addCell(cellVal).setBorder(Rectangle.NO_BORDER);
itemList.addCell(cellVal3).setBorder(Rectangle.NO_BORDER);
itemList.addCell(cellVal4).setBorder(Rectangle.NO_BORDER);
itemList.addCell(cellVal5).setBorder(Rectangle.NO_BORDER);
itemList.addCell(cellVal6).setBorder(Rectangle.NO_BORDER);
itemList.addCell(cellVal7).setBorder(Rectangle.NO_BORDER);
itemList.setSplitLate(false);
}
double sumValue = 0;
for(int i =0; i< totalPrice.length; i++)
{
sumValue = sumValue+ totalPrice[i];
}
DecimalFormat dformat = new DecimalFormat("#.##");
String str_total_Price_formatted = dformat.format(sumValue);
PdfPCell itemlistCell = new PdfPCell(itemList);
itemlistCell.setBorder(Rectangle.NO_BORDER);
PdfPCell itemTotalCell = new PdfPCell(itemTotal);
itemTotalCell.setBorder(Rectangle.NO_BORDER);
itemInfo.addCell(itemlistCell);//here
itemInfo.addCell(itemTotalCell);
抱歉搞砸了代码。我无法在第一页中拆分表项。但是,该表从第2页开始,如果项目数量更多,则可以成功分割第2页和第3页。需要你的帮助。提前谢谢。
答案 0 :(得分:2)
通过添加以下行解决了问题:
itemInfo.setSplitLate(false);
这样的一行存在于原始代码中,但仅适用于内部表,而不适用于外部表。