Example usage for com.itextpdf.text PageSize A4

List of usage examples for com.itextpdf.text PageSize A4

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.itextpdf.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:com.dandymadeproductions.myjsqlview.io.PDFDataTableDumpThread.java

License:Open Source License

public void run() {
    // Class Method Instances
    String title;/*  ww  w. j a  v  a2 s. co m*/
    PdfPTable pdfTable;
    PdfPCell titleCell, rowHeaderCell, bodyCell;
    Document pdfDocument;
    PdfWriter pdfWriter;
    ByteArrayOutputStream byteArrayOutputStream;

    int columnCount, rowNumber;
    int[] columnWidths;
    int totalWidth;
    Rectangle pageSize;

    MyJSQLView_ProgressBar dumpProgressBar;
    HashMap<String, String> summaryListTableNameTypes;
    String currentTableFieldName;
    String currentType, currentString;

    // Setup
    columnCount = summaryListTable.getColumnCount();
    rowNumber = summaryListTable.getRowCount();
    columnWidths = new int[columnCount];

    pdfTable = new PdfPTable(columnCount);
    pdfTable.setWidthPercentage(100);
    pdfTable.getDefaultCell().setPaddingBottom(4);
    pdfTable.getDefaultCell().setBorderWidth(1);

    summaryListTableNameTypes = new HashMap<String, String>();
    pdfDataExportOptions = DBTablesPanel.getDataExportProperties();

    titleFont = new Font(pdfDataExportOptions.getFont());
    titleFont.setStyle(Font.BOLD);
    titleFont.setSize((float) pdfDataExportOptions.getTitleFontSize());
    titleFont.setColor(new BaseColor(pdfDataExportOptions.getTitleColor().getRGB()));

    rowHeaderFont = new Font(pdfDataExportOptions.getFont());
    rowHeaderFont.setStyle(Font.BOLD);
    rowHeaderFont.setSize((float) pdfDataExportOptions.getHeaderFontSize());
    rowHeaderFont.setColor(new BaseColor(pdfDataExportOptions.getHeaderColor().getRGB()));
    rowHeaderBaseFont = rowHeaderFont.getCalculatedBaseFont(false);

    tableDataFont = pdfDataExportOptions.getFont();

    // Constructing progress bar.
    rowNumber = summaryListTable.getRowCount();
    dumpProgressBar = new MyJSQLView_ProgressBar(exportedTable + " Dump");
    dumpProgressBar.setTaskLength(rowNumber);
    dumpProgressBar.pack();
    dumpProgressBar.center();
    dumpProgressBar.setVisible(true);

    // Create a Title if Optioned.
    title = pdfDataExportOptions.getTitle();

    if (!title.equals("")) {
        if (title.equals("EXPORTED TABLE"))
            title = exportedTable;

        titleCell = new PdfPCell(new Phrase(title, titleFont));
        titleCell.setBorder(0);
        titleCell.setPadding(10);
        titleCell.setColspan(summaryListTable.getColumnCount());
        titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        pdfTable.addCell(titleCell);
        pdfTable.setHeaderRows(2);
    } else
        pdfTable.setHeaderRows(1);

    // Create Row Header.
    for (int i = 0; i < columnCount; i++) {
        currentTableFieldName = summaryListTable.getColumnName(i);
        rowHeaderCell = new PdfPCell(new Phrase(currentTableFieldName, rowHeaderFont));
        rowHeaderCell.setBorderWidth(pdfDataExportOptions.getHeaderBorderSize());
        rowHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        rowHeaderCell.setBorderColor(new BaseColor(pdfDataExportOptions.getHeaderBorderColor().getRGB()));
        pdfTable.addCell(rowHeaderCell);
        columnWidths[i] = Math.min(50000,
                Math.max(columnWidths[i], rowHeaderBaseFont.getWidth(currentTableFieldName + " ")));
        if (tableColumnTypeHashMap != null)
            summaryListTableNameTypes.put(Integer.toString(i),
                    tableColumnTypeHashMap.get(currentTableFieldName));
        else
            summaryListTableNameTypes.put(Integer.toString(i), "String");
    }

    // Create the Body of Data.
    int i = 0;
    while ((i < rowNumber) && !dumpProgressBar.isCanceled()) {
        dumpProgressBar.setCurrentValue(i);

        // Collecting rows of data & formatting date & timestamps
        // as needed according to the Export Properties.

        if (summaryListTable.getValueAt(i, 0) != null) {
            for (int j = 0; j < summaryListTable.getColumnCount(); j++) {
                currentString = summaryListTable.getValueAt(i, j) + "";
                currentString = currentString.replaceAll("\n", "");
                currentString = currentString.replaceAll("\r", "");
                currentType = summaryListTableNameTypes.get(Integer.toString(j));

                // Format Date & Timestamp Fields as Needed.

                if ((currentType != null) && (currentType.equals("DATE") || currentType.equals("DATETIME")
                        || currentType.indexOf("TIMESTAMP") != -1)) {
                    if (!currentString.toLowerCase().equals("null")) {
                        int firstSpace;
                        String time;

                        // Dates fall through DateTime and Timestamps try
                        // to get the time separated before formatting
                        // the date.

                        if (currentString.indexOf(" ") != -1) {
                            firstSpace = currentString.indexOf(" ");
                            time = currentString.substring(firstSpace);
                            currentString = currentString.substring(0, firstSpace);
                        } else
                            time = "";

                        currentString = MyJSQLView_Utils.convertViewDateString_To_DBDateString(currentString,
                                DBTablesPanel.getGeneralDBProperties().getViewDateFormat());
                        currentString = MyJSQLView_Utils.convertDBDateString_To_ViewDateString(currentString,
                                pdfDataExportOptions.getPDFDateFormat()) + time;
                    }
                }
                bodyCell = new PdfPCell(new Phrase(currentString, tableDataFont));
                bodyCell.setPaddingBottom(4);

                if (currentType != null) {
                    // Set Numeric Fields Alignment.
                    if (currentType.indexOf("BIT") != -1 || currentType.indexOf("BOOL") != -1
                            || currentType.indexOf("NUM") != -1 || currentType.indexOf("INT") != -1
                            || currentType.indexOf("FLOAT") != -1 || currentType.indexOf("DOUBLE") != -1
                            || currentType.equals("REAL") || currentType.equals("DECIMAL")
                            || currentType.indexOf("COUNTER") != -1 || currentType.equals("BYTE")
                            || currentType.equals("CURRENCY")) {
                        bodyCell.setHorizontalAlignment(pdfDataExportOptions.getNumberAlignment());
                        bodyCell.setPaddingRight(4);
                    }
                    // Set Date/Time Field Alignment.
                    if (currentType.indexOf("DATE") != -1 || currentType.indexOf("TIME") != -1
                            || currentType.indexOf("YEAR") != -1)
                        bodyCell.setHorizontalAlignment(pdfDataExportOptions.getDateAlignment());
                }

                pdfTable.addCell(bodyCell);
                columnWidths[j] = Math.min(50000,
                        Math.max(columnWidths[j], BASE_FONT.getWidth(currentString + " ")));
            }
        }
        i++;
    }
    dumpProgressBar.dispose();

    // Check to see if any data was in the summary
    // table to even be saved.

    if (pdfTable.size() <= pdfTable.getHeaderRows())
        return;

    // Create a document of the PDF formatted data
    // to be saved to the given output file.

    try {
        // Sizing & Layout
        totalWidth = 0;
        for (int width : columnWidths)
            totalWidth += width;

        if (pdfDataExportOptions.getPageLayout() == PDFExportPreferencesPanel.LAYOUT_PORTRAIT)
            pageSize = PageSize.A4;
        else {
            pageSize = PageSize.A4.rotate();
            pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f));
            pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f));
        }

        pdfTable.setWidths(columnWidths);

        // Document
        pdfDocument = new Document(pageSize);
        byteArrayOutputStream = new ByteArrayOutputStream();
        pdfWriter = PdfWriter.getInstance(pdfDocument, byteArrayOutputStream);
        pdfDocument.open();
        pdfTemplate = pdfWriter.getDirectContent().createTemplate(100, 100);
        pdfTemplate.setBoundingBox(new com.itextpdf.text.Rectangle(-20, -20, 100, 100));
        pdfWriter.setPageEvent(this);
        pdfDocument.add(pdfTable);
        pdfDocument.close();

        // Outputting
        WriteDataFile.mainWriteDataString(fileName, byteArrayOutputStream.toByteArray(), false);

    } catch (DocumentException de) {
        if (MyJSQLView.getDebug()) {
            System.out.println("Failed to Create Document Needed to Output Data. \n" + de.toString());
        }
    }
}

From source file:com.devox.GUI.PDF.CrearReporteApto.java

@Override
public void crear(File file) {
    try {//  w w  w. jav a2  s . c  o m
        document = new Document(PageSize.A4.rotate());
        file.createNewFile();
        writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        writer.setPageEvent(event);
        document.setMargins(30, 30, 40, 360);
        document.newPage();
        Paragraph p = new Paragraph("RELACIN DE PRODUCTO APTO", FUENTE_TITULO_APTO);
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);
        document.add(configurarInformacion());
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.close();

    } catch (IOException | DocumentException ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}

From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java

@Override
public void crear(File file) {
    try {//from  w  w  w  . ja v a  2s.  c  om
        document = new Document(PageSize.A4, 50f, 50f, 100f, 220f);
        file.createNewFile();
        writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        writer.setPageEvent(event);
        document.newPage();
        Paragraph p = new Paragraph("RELACIN DE PRODUCTOS PARA DESTRUCCIN", FUENTE_TITULO_APTO);
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);
        document.add(configurarInformacion());
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.close();
    } catch (IOException | DocumentException ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}

From source file:com.devox.GUI.PDF.CrearReportePorEstado.java

@Override
public void crear(File file) {
    try {//from   w ww. ja  va 2s  . c om
        Document document = new Document(PageSize.A4, 50f, 50f, 65f, 100f);
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        w.setPageEvent(event);
        document.newPage();
        document.add(configurarInformacion());
        document.add(new Paragraph("\n"));
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.add(new Paragraph("\n"));
        document.add(new Paragraph("TOTAL: " + data.length + "FOLIOS.", FUENTE_FOLIO_CHICA));
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}

From source file:com.devox.GUI.PDF.CrearReporteTarimas.java

@Override
public void crear(File file) {
    try {/*from ww w  . j a v a  2  s .  c  om*/
        Document document = new Document(PageSize.A4.rotate());
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        w.setPageEvent(event);
        document.setMargins(50, 50, 100, 50);
        document.newPage();
        document.add(configurarInformacion());
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

public void crearDestruccion(File file) {
    try {/*from  w w  w . j  a v  a 2 s.c  o  m*/
        Document document = new Document(PageSize.A4);
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        w.setPageEvent(event);
        document.setMargins(50, 50, 100, 220);
        document.newPage();
        document.add(setUpInformation());
        PdfPTable t = createTable();
        addProductos(model, t);
        document.add(t);
        //
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
        Log.print(ex);
    }
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

public void crearApto(File file) {
    try {// w  w w .  j  ava 2 s  .  co m
        Document document = new Document(PageSize.A4);
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        w.setPageEvent(event);
        document.setMargins(50, 50, 100, 220);
        document.newPage();
        document.add(setUpInformationTarimas());
        //            PdfPTable t = createTable();
        //            addProductos(model, t);
        //            document.add(t);
        //
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
        Log.print(ex);
    }
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

public void crearTarimas(File file) {
    try {/*from  w w  w  . jav a 2 s  .  c o m*/
        Document document = new Document(PageSize.A4.rotate());
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina2 event = new CabeceraPieDePagina2();
        w.setPageEvent(event);
        document.setMargins(50, 50, 100, 50);
        document.newPage();
        document.add(setUpInformationTarimas());
        PdfPTable t = createTableTarimas();
        addProductosTarimas(t);
        document.add(t);
        //
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
        Log.print(ex);
    }
}

From source file:com.dexter.fms.mbean.ReportsMBean.java

@SuppressWarnings("unchecked")
public void createPDF(int type, String filename, int pageType) {
    try {/*ww  w.  j a v  a2  s . co m*/
        FacesContext context = FacesContext.getCurrentInstance();
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FMS");
        document.addCreationDate();
        document.addCreator("FMS");
        document.addSubject("Report");
        document.addTitle(getReport_title());

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("partner", dashBean.getUser().getPartner());
        GeneralDAO gDAO = new GeneralDAO();
        Object pSettingsObj = gDAO.search("PartnerSetting", params);
        PartnerSetting setting = null;
        if (pSettingsObj != null) {
            Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj;
            for (PartnerSetting e : pSettingsList) {
                setting = e;
            }
        }
        gDAO.destroy();

        PdfPCell c = null;
        if (setting != null && setting.getLogo() != null) {
            Image logoImg = Image.getInstance(setting.getLogo());
            logoImg.scaleToFit(212, 51);
            c = new PdfPCell(logoImg);
        } else
            c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(getReport_title(), font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (getReport_start_dt() != null && getReport_end_dt() != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = exportPDFTable(type);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();
        String fileName = filename + ".pdf";

        writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf");

        context.responseComplete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dexter.fuelcard.mbean.UtilMBean.java

public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType,
        String chargeAmount, String total) {
    try {//from   ww w .  ja  va 2 s .  com
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FUELCARD");
        document.addCreationDate();
        document.addCreator("FUELCARD");
        document.addSubject("Invoice");
        document.addTitle(title);

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        PdfPCell c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(title, font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (dateperiod != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("For " + dateperiod, font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = new PdfPTable(4);
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license
        pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting

        if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) {
            pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting
        } else {
            pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting
        }
        //pdfTable.addCell(new Paragraph("Description", font)); // the 
        pdfTable.addCell(new Paragraph("Amount Due", font));

        font = new Font(helvetica, 8, Font.NORMAL);
        pdfTable.addCell(new Paragraph(chargeType, font));
        pdfTable.addCell(new Paragraph(chargeAmount, font));
        pdfTable.addCell(new Paragraph(total, font));
        pdfTable.addCell(new Paragraph(amount, font));

        pdfTable.setWidthPercentage(100);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();

        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}