private Tbl createTable(int type) {
    rowNo = 0;

    List<Band> bands = new ArrayList<Band>();
    if (type == PRINT_PAGE_HEADER) {
      bands.add(getReportLayout().getPageHeaderBand());
    } else if (type == PRINT_PAGE_FOOTER) {
      bands.add(getReportLayout().getPageFooterBand());
    } else {
      bands = getReportLayout().getDocumentBands();
    }

    int totalRows = 0;
    int totalColumns = 0;
    for (Band band : bands) {
      totalRows += band.getRowCount();
      int cols = band.getColumnCount();
      if (cols > totalColumns) {
        totalColumns = cols;
      }
    }

    // no page header or no page footer
    if (totalColumns == 0) {
      return null;
    }

    headerwidths = new int[totalColumns];

    boolean landscape = (bean.getReportLayout().getOrientation() == LANDSCAPE);
    Padding padding = bean.getReportLayout().getPagePadding();
    int margs = pixelsToDxa(padding.getLeft() + padding.getRight());
    if (currentWidth == -1) {
      currentWidth = landscape ? (A4_LANDSCAPE_DXA - margs) : (A4_PORTRAIT_DXA - margs);
    }
    int colWidth = currentWidth / totalColumns;
    for (int i = 0; i < totalColumns; i++) {
      if (bean.getReportLayout().isUseSize()) {
        headerwidths[i] = pixelsToDxa(bean.getReportLayout().getColumnsWidth().get(i));
      } else {
        headerwidths[i] = colWidth;
      }
    }

    Tbl resultTable = factory.createTbl();

    // set table width
    TblPr tblPr = factory.createTblPr();
    TblWidth tblWidth = factory.createTblWidth();
    if (bean.getReportLayout().isUseSize()) {
      int sum = 0;
      for (int i = 0; i < totalColumns; i++) {
        sum += headerwidths[i];
      }
      currentWidth = sum;
    }
    tblWidth.setW(BigInteger.valueOf(currentWidth));
    tblWidth.setType(TblWidth.TYPE_DXA);
    tblPr.setTblW(tblWidth);
    resultTable.setTblPr(tblPr);

    return resultTable;
  }
 private void setPageMargins() {
   try {
     Body body = wordMLPackage.getMainDocumentPart().getContents().getBody();
     Padding padding = bean.getReportLayout().getPagePadding();
     PageDimensions page = new PageDimensions();
     PgMar pgMar = page.getPgMar();
     pgMar.setBottom(BigInteger.valueOf(pixelsToDxa(padding.getBottom())));
     pgMar.setTop(BigInteger.valueOf(pixelsToDxa(padding.getTop())));
     pgMar.setLeft(BigInteger.valueOf(pixelsToDxa(padding.getLeft())));
     pgMar.setRight(BigInteger.valueOf(pixelsToDxa(padding.getRight())));
     SectPr sectPr = factory.createSectPr();
     body.setSectPr(sectPr);
     sectPr.setPgMar(pgMar);
   } catch (Docx4JException e) {
     e.printStackTrace();
   }
 }