Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:06:38+00:00 2026-05-27T03:06:38+00:00

I have a class which generate PDF dynamically, in that I have a 4-6

  • 0

I have a class which generate PDF dynamically,
in that I have a 4-6 columns..
in second column description, a Name of item is displayed dynamically,
it has about 20-40 characters.. now I want to display the row height consistently..
if any one of the description characters exceeds 30 characters I have to display all the rows height as equal heights (20f)
if the character doesn’t exceeds and ends below 30 character I have to show all the rows heights as (10f).

How can I align the same dynamically?
Here’s my code:

mainTable.addCell (PDFUtil.getBlankLine (20f));
float[] colsWidth = {0.5f,3.8f,0.9f,0.9f,1.3f,0.9f,1.3f,1.4f}; 
PdfPTable itemListTab = new PdfPTable(colsWidth);

PdfPCell slNo = PDFUtil.getTableHeaderCell(PDFUtil.S_NO,
        PDFUtil.getBoldFont());
PdfPCell itmDesc = PDFUtil.getTableHeaderCell(PDFUtil.ITEM_DESC,
        PDFUtil.getBoldFont());
PdfPCell loose = PDFUtil.getTableHeaderCell(PDFUtil.LOOSE_QTY,
        PDFUtil.getBoldFont());
PdfPCell full = PDFUtil.getTableHeaderCell(PDFUtil.FULL_QTY,
        PDFUtil.getBoldFont());
PdfPCell unitPrc = PDFUtil.getTableHeaderCell(PDFUtil.QUOTED_PRICE,
        PDFUtil.getBoldFont());
PdfPCell disc = PDFUtil.getTableHeaderCell(
        PDFUtil.ITM_DISCOUNT_PERCENT, PDFUtil.getBoldFont());
PdfPCell netAmt = PDFUtil.getTableHeaderCell(PDFUtil.NET_PRICE,
        PDFUtil.getBoldFont());
PdfPCell amt = PDFUtil.getTableHeaderCell(PDFUtil.AMOUNT_LABEL, PDFUtil
        .getBoldFont());
amt.setHorizontalAlignment(Element.ALIGN_RIGHT);
itemListTab.addCell(slNo);
itemListTab.addCell(itmDesc);
itemListTab.addCell(full);
itemListTab.addCell(loose);
itemListTab.addCell(unitPrc);
itemListTab.addCell(disc);
itemListTab.addCell(netAmt);
itemListTab.addCell(amt);
ArrayList aList = vendPOVO.getItemList();
if (aList != null)
{
    Object[] iList = aList.toArray();
    Arrays.sort(iList, new ItemSNoComparator(aList));
    int len = iList.length;
    InventoryLogger.logDebug("After sorting the item list by SNo");
    InventoryLogger.logDebug("length"+len);
    for (int i = 0; i < len; i++)
    {
        InventoryLogger.logDebug("inside for");
        ItemMasterVO itmMstrVO = (ItemMasterVO) iList[i];
        if (InventoryConstants.TRUE.equals(itmMstrVO
            .getVendPurOrdInd()))
        {
            String ctry = " ";
            InventoryLogger.logDebug ("Country of origin"+itmMstrVO.getCtryOfOrigin());
            if(itmMstrVO.getCtryOfOrigin() != null)
            {
                ctry =  InventoryUtil.getStaticElementDescription(
                        itmMstrVO.getCtryOfOrigin(),InventoryConstants.STATIC_ELE_CTRY);
            }
            String uomDesc = "";
            String looseUomTemp = "";
            if(itmMstrVO.getUomDesc().matches(InventoryConstants.UOM_KGGM) )
            {
                uomDesc = "1 KG ";
                looseUomTemp = "KG";
            }
            else
            {
                uomDesc = itmMstrVO.getUomDesc();
                looseUomTemp = itmMstrVO.getLooseUOM();
            }
            String flFlagCheck = "";
            InventoryLogger.logDebug("fl"+itmMstrVO.getFullLooseInd());
            if(itmMstrVO.getFullLooseInd().matches(InventoryConstants.FULL_LOOSE_IND_F))
            {
                flFlagCheck = itmMstrVO.getFullUOM();
            }
            else
            {
                flFlagCheck = itmMstrVO.getLooseUOM();
            }

            itemListTab.addCell(new PdfPCell(new Phrase(itmMstrVO
                .getCusQuoSerialNo(), PDFUtil
                .getNormalFont())));

            itemListTab.addCell(new PdfPCell(new Phrase(itmMstrVO
                .getItemDisplayName()+ " / " + uomDesc + "/" + ctry , PDFUtil
                .getNormalFont())));

            itemListTab.addCell(new PdfPCell(new Phrase(Long
                .toString(itmMstrVO.getQuoFull())+" "+itmMstrVO.getFullUOM(), PDFUtil
                .getNormalFont())));
            PdfPCell cellone = new PdfPCell(new Phrase(Long.toString(itmMstrVO.getQuoLoose())+" "+itmMstrVO.getLooseUOM(), PDFUtil.getNormalFont()));
            cellone.setFixedHeight(25f);
            itemListTab.addCell(cellone);itemListTab.addCell(new PdfPCell(new Phrase(InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getDiscUnitPrice())+"/"+flFlagCheck, PDFUtil
                .getNormalFont())));

            itemListTab.addCell(new PdfPCell(new Phrase(InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getDiscPercent()), PDFUtil
                .getNormalFont())));
            itemListTab.addCell(new PdfPCell(new Phrase((InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getDiscUnitPrice()))+"/" +flFlagCheck, PDFUtil.getNormalFont())));
            itemListTab.addCell(new PdfPCell(new Phrase(InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getAmount()), PDFUtil
                .getNormalFont())));
        }
    }
}
PdfPCell addCell = new PdfPCell(itemListTab);
addCell.setBorder(0);
mainTable.addCell(addCell);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:06:39+00:00Added an answer on May 27, 2026 at 3:06 am

    Hey Guys finally i found out the solution for this:

      mainTable.addCell(PDFUtil.getBlankLine(20f));
      float[] colsWidth = {0.5f,3.8f,0.9f,0.9f,1.3f,0.9f,1.3f,1.4f}; 
      PdfPTable itemListTab = new PdfPTable(colsWidth);
    
      PdfPCell slNo = PDFUtil.getTableHeaderCell(PDFUtil.S_NO,
            PDFUtil.getBoldFont());
    
      PdfPCell itmDesc = PDFUtil.getTableHeaderCell(PDFUtil.ITEM_DESC,
            PDFUtil.getBoldFont());
    
      PdfPCell loose = PDFUtil.getTableHeaderCell(PDFUtil.LOOSE_QTY,
            PDFUtil.getBoldFont());
      PdfPCell full = PDFUtil.getTableHeaderCell(PDFUtil.FULL_QTY,
            PDFUtil.getBoldFont());
      PdfPCell unitPrc = PDFUtil.getTableHeaderCell(PDFUtil.QUOTED_PRICE,
            PDFUtil.getBoldFont());
    
      PdfPCell disc = PDFUtil.getTableHeaderCell(
            PDFUtil.ITM_DISCOUNT_PERCENT, PDFUtil.getBoldFont());
      PdfPCell netAmt = PDFUtil.getTableHeaderCell(PDFUtil.NET_PRICE,
            PDFUtil.getBoldFont());
      PdfPCell amt = PDFUtil.getTableHeaderCell(PDFUtil.AMOUNT_LABEL, PDFUtil
            .getBoldFont());
      amt.setHorizontalAlignment(Element.ALIGN_RIGHT);
      itemListTab.addCell(slNo);
    
      itemListTab.addCell(itmDesc);
    
      itemListTab.addCell(full);
      itemListTab.addCell(loose);
      itemListTab.addCell(unitPrc);
    
      itemListTab.addCell(disc);
      itemListTab.addCell(netAmt);
      itemListTab.addCell(amt);ArrayList aList = vendPOVO.getItemList();
      if (aList != null)
      {
        Object[] iList = aList.toArray();
        Arrays.sort(iList, new ItemSNoComparator(aList));
        int len = iList.length;
        InventoryLogger.logDebug("After sorting the item list by SNo");
        InventoryLogger.logDebug("length"+len);
    
    
    
        int lenthChr = 0;
        int lineLength = 34;
        float maxLineLength = 34;
        for (int j = 0; j < len; j++)
        {
            ItemMasterVO itmMstrVO = (ItemMasterVO) iList[j];
            if (InventoryConstants.TRUE.equals(itmMstrVO.getVendPurOrdInd()))
            {
    
        String ctry = " ";
        if(itmMstrVO.getCtryOfOrigin() != null)
        {
            ctry =  InventoryUtil.getStaticElementDescription(itmMstrVO.getCtryOfOrigin(),InventoryConstants.STATIC_ELE_CTRY);
        }
        String uomDesc = "";
        String looseUomTemp = "";
        String Space = "";
        if(itmMstrVO.getUomDesc().matches(InventoryConstants.UOM_KGGM) )
        {
            uomDesc = "1 KG ";
            looseUomTemp = "KG";
        }
        else
        {
            uomDesc = itmMstrVO.getUomDesc();
            looseUomTemp = itmMstrVO.getLooseUOM();
        }
    
        int lenthChrTmp = (itmMstrVO.getItemDesc1() + " / " + itmMstrVO.getItemDesc2() + " / " + uomDesc+ "/" + ctry).length() ;
    
        lenthChr = (lenthChr > lenthChrTmp)?lenthChr:lenthChrTmp;
    
    
            }
        }
    
    
    
        int mod = ((lenthChr % lineLength)> 0)?1:0;
        maxLineLength = ((lenthChr/lineLength) + mod) * 13;
    
        for (int i = 0; i < len; i++)
        {
            InventoryLogger.logDebug("inside for");
            ItemMasterVO itmMstrVO = (ItemMasterVO) iList[i];
            if (InventoryConstants.TRUE.equals(itmMstrVO
            .getVendPurOrdInd()))
            {
        String ctry = " ";
        InventoryLogger.logDebug("Country of origin"+itmMstrVO.getCtryOfOrigin());
        if(itmMstrVO.getCtryOfOrigin() != null)
        {
            ctry =  InventoryUtil.getStaticElementDescription(
          itmMstrVO.getCtryOfOrigin(),InventoryConstants.STATIC_ELE_CTRY);
        }
        String uomDesc = "";
        String looseUomTemp = "";
        if(itmMstrVO.getUomDesc().matches(InventoryConstants.UOM_KGGM) )
        {
            uomDesc = "1 KG ";
            looseUomTemp = "KG";
        }
        else
        {
            uomDesc = itmMstrVO.getUomDesc();
            looseUomTemp = itmMstrVO.getLooseUOM();
        }
        String flFlagCheck = "";
        InventoryLogger.logDebug("fl"+itmMstrVO.getFullLooseInd());
        if(itmMstrVO.getFullLooseInd().matches(InventoryConstants.FULL_LOOSE_IND_F))
        {
            flFlagCheck = itmMstrVO.getFullUOM();
        }
        else
        {
            flFlagCheck = itmMstrVO.getLooseUOM();
        }
    
        itemListTab
                .addCell(new PdfPCell(new Phrase(itmMstrVO
            .getCusQuoSerialNo(), PDFUtil
            .getNormalFont())));
    
        PdfPCell descCell = new  PdfPCell(new Phrase(itmMstrVO
                .getItemDisplayName()+ " / " + uomDesc + "/" + ctry , PDFUtil
                .getNormalFont()));
        descCell.setFixedHeight(maxLineLength);
        itemListTab.addCell(descCell);
    
        itemListTab.addCell(new PdfPCell(new Phrase(Long
                .toString(itmMstrVO.getQuoFull())+" "+itmMstrVO.getFullUOM(), PDFUtil
                .getNormalFont())));
        PdfPCell cellone = new PdfPCell(new Phrase(Long.toString(itmMstrVO.getQuoLoose())+" "+itmMstrVO.getLooseUOM(), PDFUtil.getNormalFont()));itemListTab.addCell(cellone);itemListTab.addCell(new PdfPCell(new Phrase(InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getDiscUnitPrice())+"/"+flFlagCheck, PDFUtil
                .getNormalFont())));
    
        itemListTab.addCell(new PdfPCell(new Phrase(InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getDiscPercent()), PDFUtil
                .getNormalFont())));
        itemListTab.addCell(new PdfPCell(new Phrase((InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getDiscUnitPrice()))+"/" +flFlagCheck, PDFUtil.getNormalFont())));
        itemListTab.addCell(new PdfPCell(new Phrase(InventoryUtil.getTwoDecDigPrecisionMin(itmMstrVO.getAmount()), PDFUtil
                .getNormalFont())));
            }
        }
      }
      PdfPCell addCell = new PdfPCell(itemListTab);
      addCell.setBorder(0);
      mainTable.addCell(addCell);
    

    I have introduced a line length check and some calculations for fixing the height. After calculating the height I set the fixedheight property for the pdfpcell below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dll which I disassemble in Reflector, I then generate a class.
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a project which needs to generate PDF documents. I am using iTextSharp.
I have a Java class which uses Apache POI to generate reports in Excel.
i have a script which generate the following HTML code : <table class=table> <tr><td
I need a Class which has an semi-automatic 'to_s' method (to generate XML in
I have a Random into a class which aims to generate random sequences in
My situation is essentially this: I have a class called Foo which has dependencies
Suppose (for the sake of argument) that I have a view class which contains
What I have: LINQ to SQL auto generated class, which corresponds to the shape

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.