Example usage for com.itextpdf.text Font NORMAL

List of usage examples for com.itextpdf.text Font NORMAL

Introduction

In this page you can find the example usage for com.itextpdf.text Font NORMAL.

Prototype

int NORMAL

To view the source code for com.itextpdf.text Font NORMAL.

Click Source Link

Document

this is a possible style.

Usage

From source file:com.carfinance.module.common.controller.DocumentDownloadController.java

/**
 * ??/*from   w  ww  . j a  v  a  2  s .c  om*/
 * @param model
 * @param request
 * @param response
 */
@RequestMapping(value = "/pdfhunchecontrace", method = RequestMethod.GET)
public void pdfHuncheContrace(Model model, HttpServletRequest request, HttpServletResponse response) {
    String contrace_id_str = request.getParameter("contrace_id");

    String org_id = "";
    String contrace_no = "";
    String customer_name = "";
    String vehicle_id = "";
    String daily_available_km = "";

    VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService
            .getVehicleContraceInfoById(Long.valueOf(contrace_id_str));
    if (vehicleContraceInfo != null) {
        org_id = String.valueOf(vehicleContraceInfo.getOrg_id());
        contrace_no = vehicleContraceInfo.getContrace_no();
        customer_name = vehicleContraceInfo.getCustomer_name();
        daily_available_km = vehicleContraceInfo.getDaily_available_km() + "";
    } else {
        PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService
                .getPropertyContraceInfoById(Long.valueOf(contrace_id_str));
        if (propertyContraceInfo != null) {
            org_id = String.valueOf(propertyContraceInfo.getOrg_id());
            contrace_no = propertyContraceInfo.getContrace_no();
            customer_name = propertyContraceInfo.getCustomer_name();
        }
    }

    List<VehicleContraceVehsInfo> vehicleContraceVehsInfoList = this.vehicleServiceManageService
            .getVehicleContraceVehsListByContraceId(Long.valueOf(contrace_id_str));

    //1.ContentType
    response.setContentType("multipart/form-data");
    //2.????(??a.pdf)
    response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + ".pdf");

    Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
    // ?? pdf ?
    try {
        BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);

        Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK);
        Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK);
        Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK);

        FileOutputStream pdfFile = new FileOutputStream(
                new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".pdf"));
        // pdf ?
        Paragraph paragraph1 = new Paragraph("???", bold_fontChinese);
        paragraph1.setAlignment(Element.ALIGN_CENTER);

        Paragraph paragraph2 = new Paragraph(
                "???", normal_fontChinese);
        Paragraph paragraph3 = new Paragraph("" + customer_name + " (",
                normal_fontChinese);
        Paragraph paragraph4 = new Paragraph(
                "?????________________???",
                normal_fontChinese);
        Paragraph paragraph5 = new Paragraph("??????",
                normal_fontChinese);
        // table
        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100);
        table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        PdfPCell cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        // 
        cell.setPhrase(new Paragraph("?", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("?/", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("?", normal_fontChinese));
        table.addCell(cell);
        // ?
        for (VehicleContraceVehsInfo v : vehicleContraceVehsInfoList) {

            PdfPCell newcell = new PdfPCell();
            newcell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            newcell.setPhrase(new Paragraph("1", normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(v.getModel(), normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(v.getDaily_price() + "", normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(daily_available_km, normal_fontChinese));
            table.addCell(newcell);
        }

        Paragraph paragraph6 = new Paragraph(
                "??_________________________________________________________________",
                normal_fontChinese);
        Paragraph paragraph7 = new Paragraph(
                "____________________________?______",
                normal_fontChinese);
        Paragraph paragraph8 = new Paragraph("????", normal_fontChinese);
        Paragraph paragraph9 = new Paragraph(
                "???________________________???________________________",
                normal_fontChinese);
        Paragraph paragraph10 = new Paragraph("?", normal_fontChinese);
        Paragraph paragraph11 = new Paragraph(
                "???????????????",
                normal_fontChinese);
        Paragraph paragraph12 = new Paragraph("?", normal_fontChinese);
        Paragraph paragraph13 = new Paragraph(
                "??????????????",
                normal_fontChinese);
        Paragraph paragraph14 = new Paragraph(
                "?????????",
                normal_fontChinese);
        Paragraph paragraph15 = new Paragraph("?????",
                normal_fontChinese);
        Paragraph paragraph16 = new Paragraph(
                "(/)                                       (/)",
                normal_fontChinese);
        Paragraph paragraph17 = new Paragraph(
                "                                                      ??", normal_fontChinese);
        Paragraph paragraph18 = new Paragraph(
                "??                                               ??  ",
                normal_fontChinese);
        Paragraph paragraph19 = new Paragraph(
                "                                                      201          ",
                normal_fontChinese);

        //  Document ?File  PdfWriter ?
        PdfWriter.getInstance(pdfDoc, pdfFile);
        pdfDoc.open(); //  Document 

        // ??
        pdfDoc.add(paragraph1);
        pdfDoc.add(new Chunk("\n\n"));
        pdfDoc.add(paragraph2);
        pdfDoc.add(paragraph3);
        pdfDoc.add(paragraph4);
        pdfDoc.add(paragraph5);
        pdfDoc.add(table);
        pdfDoc.add(paragraph6);
        pdfDoc.add(paragraph7);
        pdfDoc.add(paragraph8);
        pdfDoc.add(paragraph9);
        pdfDoc.add(paragraph10);
        pdfDoc.add(paragraph11);
        pdfDoc.add(paragraph12);
        pdfDoc.add(paragraph13);
        pdfDoc.add(paragraph14);
        pdfDoc.add(paragraph15);
        pdfDoc.add(paragraph16);
        pdfDoc.add(paragraph17);
        pdfDoc.add(paragraph18);
        pdfDoc.add(paragraph19);

        pdfDoc.close();

        ServletOutputStream out;
        //File(?download.pdf)
        File file = new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".pdf");

        try {
            FileInputStream inputStream = new FileInputStream(file);
            //3.response?ServletOutputStream(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.?(out)
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

public PdfExportHelper(Project project) {
    super(project);
    chapterFont = FontFactory.getFont(FontFactory.TIMES, 20, Font.BOLD);
    sectionFont = FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD);
    subSectionFont = FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD);
    normalFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.NORMAL);
    boldFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.BOLD);
    fixedWidthFont = FontFactory.getFont(FontFactory.COURIER, 11, Font.NORMAL);
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printActivity(Activity act, Chapter chapter) throws Exception {
    Section section;//from   ww w. j  a  v  a 2  s. com
    String tmp = ACTIVITY + act.getLogicalId() + ": \"" + act.getName().replace('\n', ' ') + "\n";
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    section = chapter.addSection(sTitle, 2);
    String summary = act.getAttribute(WorkAttributeConstant.DESCRIPTION);
    if (summary != null && summary.length() > 0) {
        printBoldParagraphs(section, summary);
    }

    String detail = act.getAttribute(WorkAttributeConstant.DOCUMENTATION);
    if (detail != null && detail.length() > 0) {
        printHtmlParagraphs(section, detail, 2);
        section.add(new Paragraph("\n", FontFactory.getFont(FontFactory.TIMES, 4, Font.NORMAL)));
    }
    if (!act.getAttributes().isEmpty()) {
        printAttributes(section, act.getAttributes(), 2);
    }
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java

License:Open Source License

@Override
public void attach() {
    super.attach();
    try {//from w  w  w.j a  v a2s  .c  om
        logo = Image
                .getInstance(StatementStamperMainWindow.class.getResource("/resources/images/cib_logo.jpg"));
        logo.setAlignment(Image.LEFT);
        logo.scalePercent(30);
        isplogo = Image
                .getInstance(StatementStamperMainWindow.class.getResource("/resources/images/isplogo.jpg"));
        isplogo.setAlignment(Image.LEFT);
        isplogo.scalePercent(50);
        baseFontArial = BaseFont.createFont("/resources/fonts/ARIAL.TTF", BaseFont.CP1250, BaseFont.EMBEDDED);
        myFontBase = BaseFont.createFont("/resources/fonts/courbd.ttf", BaseFont.CP1250, BaseFont.EMBEDDED);
        bottomFont = new Font(baseFontArial, 7, Font.NORMAL, BaseColor.BLACK);
        bottomFontBold = new Font(baseFontArial, 7, Font.BOLD, BaseColor.BLACK);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    upload.addListener((Upload.SucceededListener) this);
    upload.addListener((Upload.StartedListener) this);
    upload.addListener((Upload.FinishedListener) this);
    upload.addListener((Upload.FailedListener) this);
    upload.setImmediate(true);
    addComponent(upload);
}

From source file:com.coderbd.pos.pdf.CodePDF.java

public boolean genCodeVer2Pdf() throws UnsupportedEncodingException {

    if (isFixedRated == true) {
        barcodeQuantity = 12;/*  w  w w.  j  a va2  s.c  o  m*/
    } else {
        barcodeQuantity = 15;
    }

    try {
        String filename = "";

        if (isFixedRated) {
            filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf";
        } else {
            filename = directory + "\\" + product.getProductBarcode() + ".pdf";
        }

        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(product.getProductBarcode());
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(7);
        pdfPTable.setWidthPercentage(98);
        float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(),
                (int) product.getProductBuyRate());

        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
        Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);

        Paragraph paragraph = new Paragraph(codeName, titleArialFont);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont);
        PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph);
        fixedRateCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                           -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            /**
             *
             */
            if (isFixedRated == true) {
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
            }
            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.add(new Paragraph(
                "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName()
                        + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(),
                titleArialFont));
        document.close();
        return true;
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
        return false;
    }
}

From source file:com.coderbd.pos.pdf.OrderReportPDF.java

public boolean genPdf() throws UnsupportedEncodingException {
    List<SupplierOrderProductReport> soprs = sor.getSupplierOrderProductReports();
    IDBuilder idBuilder = new IDBuilder();
    Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
    Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);
    try {//  w w w  .  j  a v  a  2 s  .  c  om
        String timestamp = idBuilder.getUniqueTimeStampID();
        String filename = sor.getSupplier().getSupplierName() + "_O" + sor.getSupplierOrderId() + "_"
                + timestamp + ".pdf";
        String filePath = directory + "\\" + filename;

        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
        document.open();

        PdfPTable pdfPTable = new PdfPTable(5);

        pdfPTable.setWidthPercentage(90);
        float[] widths = { 0.40f, 0.13f, 0.15f, 0.15f, 0.17f };
        pdfPTable.addCell(new Paragraph("Product Name", headerFont));
        pdfPTable.addCell(new Paragraph("Buy Rate", headerFont));
        pdfPTable.addCell(new Paragraph("Primary Qty", headerFont));
        pdfPTable.addCell(new Paragraph("Unsold Qty", headerFont));
        pdfPTable.addCell(new Paragraph("Unsold Amount", headerFont));

        pdfPTable.setWidths(widths);
        for (SupplierOrderProductReport sopr : soprs) {

            SupplierOrderProduct sop = sopr.getSupplierOrderProduct();
            String name = sop.getSupplierProductName();
            Double rate = sop.getSupplierRate();
            Integer pQty = sop.getSupplierProductQuantity();
            Integer unQty = sopr.getUnSoldProductQuantity();
            Double unAmount = sopr.getUnSoldProductAmount();

            Paragraph nameParag = new Paragraph(name, innerFont);
            Paragraph buyRateParag = new Paragraph(rate.toString(), innerFont);
            Paragraph primaryQuantityParag = new Paragraph(pQty.toString(), innerFont);
            Paragraph unsoldQuantityParag = new Paragraph(unQty.toString(), innerFont);
            Paragraph unsoldAmountParag = new Paragraph(unAmount.toString(), innerFont);

            PdfPCell nameCell = new PdfPCell(nameParag);
            PdfPCell buyRateCell = new PdfPCell(buyRateParag);
            PdfPCell primaryQuantityCell = new PdfPCell(primaryQuantityParag);
            PdfPCell unsoldQuantityCell = new PdfPCell(unsoldQuantityParag);
            PdfPCell unsoldAmountCell = new PdfPCell(unsoldAmountParag);

            pdfPTable.addCell(nameCell);
            pdfPTable.addCell(buyRateCell);
            pdfPTable.addCell(primaryQuantityCell);
            pdfPTable.addCell(unsoldQuantityCell);
            pdfPTable.addCell(unsoldAmountCell);
        }
        document.add(getHeader());

        document.add(pdfPTable);
        document.add(getFooter());
        document.add(new Paragraph("            Report Generated: " + new Date().toString(), innerFont));
        document.close();
        return true;
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
        return false;
    }
}

From source file:com.coderbd.pos.pdf.OrderReportPDF.java

public PdfPTable getFooter() throws DocumentException {
    Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
    Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);

    PdfPTable pdfPTableFooter = new PdfPTable(2);
    pdfPTableFooter.setWidthPercentage(90);
    float[] widthsFooter = { 0.80f, 0.20f };
    pdfPTableFooter.setWidths(widthsFooter);

    Paragraph totalSoldPara = new Paragraph("Total Sold: " + sor.getOrderTotalSoldAmount().toString(),
            headerFont);//from   w  w  w  .  j  a v a 2s.co  m
    PdfPCell totalSoldCell = new PdfPCell(totalSoldPara);
    totalSoldCell.setBorder(Rectangle.NO_BORDER);

    Paragraph totalUnSoldPara = new Paragraph("Total UnSold: " + sor.getOrderTotalUnsoldAmount().toString(),
            headerFont);
    PdfPCell totalUnSoldCell = new PdfPCell(totalUnSoldPara);
    totalUnSoldCell.setBorder(Rectangle.NO_BORDER);

    Paragraph blankPara = new Paragraph("");
    PdfPCell blankCell = new PdfPCell(blankPara);
    blankCell.setBorder(Rectangle.NO_BORDER);

    Double bill = sor.getTotalBill();
    Double paid = sor.getTotalPaid();
    Double due = bill - paid;

    Paragraph billPara = new Paragraph("BILL: " + bill.toString(), headerFont);
    PdfPCell billCell = new PdfPCell(billPara);
    billCell.setBorder(Rectangle.NO_BORDER);

    Paragraph paidPara = new Paragraph("PAID: " + paid.toString(), headerFont);
    PdfPCell paidCell = new PdfPCell(paidPara);
    paidCell.setBorder(Rectangle.NO_BORDER);

    Paragraph duePara = new Paragraph("DUE: " + due.toString(), headerFont);
    PdfPCell dueCell = new PdfPCell(duePara);
    dueCell.setBorder(Rectangle.NO_BORDER);

    pdfPTableFooter.addCell(totalSoldCell);
    pdfPTableFooter.addCell(billCell);
    pdfPTableFooter.addCell(totalUnSoldCell);
    pdfPTableFooter.addCell(paidCell);
    pdfPTableFooter.addCell(blankCell);
    pdfPTableFooter.addCell(dueCell);

    return pdfPTableFooter;
}

From source file:com.coderbd.pos.pdf.OrderReportPDF.java

public PdfPTable getHeader() throws DocumentException {
    Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
    Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 12, Font.BOLD);

    PdfPTable tableHeader = new PdfPTable(1);
    tableHeader.setWidthPercentage(90);/*from   w ww . j  a  va  2 s  .c om*/

    Paragraph supplierNamePara = new Paragraph(sor.getSupplier().getSupplierName(), headerFont);
    Paragraph addressPara = new Paragraph(sor.getSupplier().getSupplierAddress(), innerFont);
    Paragraph mobilePara = new Paragraph("Mobile: " + sor.getSupplier().getSupplierMobile(), innerFont);
    Paragraph orderPara = new Paragraph("Order: " + sor.getSupplierOrderId() + ", Time: " + sor.getOrderTime(),
            innerFont);

    PdfPCell supplierNameCell = new PdfPCell();
    supplierNameCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
    supplierNameCell.setBorder(Rectangle.NO_BORDER);
    supplierNameCell.addElement(supplierNamePara);

    PdfPCell addressCell = new PdfPCell();
    addressCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    addressCell.setBorder(Rectangle.NO_BORDER);
    addressCell.addElement(addressPara);

    PdfPCell mobileCell = new PdfPCell(mobilePara);
    mobileCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    mobileCell.setBorder(Rectangle.NO_BORDER);
    mobileCell.addElement(mobilePara);

    PdfPCell orderCell = new PdfPCell(orderPara);
    orderCell.setBorder(Rectangle.NO_BORDER);

    PdfPCell bCell = new PdfPCell(new Paragraph(" "));
    bCell.setBorder(Rectangle.NO_BORDER);

    tableHeader.addCell(supplierNameCell);
    tableHeader.addCell(addressCell);
    tableHeader.addCell(mobileCell);
    tableHeader.addCell(orderCell);
    tableHeader.addCell(bCell);

    return tableHeader;
}

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

@SuppressWarnings("unchecked")
public void createPDF(int type, String filename, int pageType) {
    try {// w w w  .j  a v a2s.c o 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.fms.mbean.ReportsMBean.java

@SuppressWarnings("deprecation")
private PdfPTable exportPDFTable(int type) {
    int numberOfColumns = 0;
    PdfPTable pdfTable = null;/*from   w  w  w .  ja  va 2 s. c  o  m*/
    switch (type) {
    case 1: // all users report
    {
        numberOfColumns = 7;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("User name", font));
        pdfTable.addCell(new Paragraph("Full name", font));
        pdfTable.addCell(new Paragraph("Email", font));
        pdfTable.addCell(new Paragraph("Department", font));
        pdfTable.addCell(new Paragraph("Region", font));
        pdfTable.addCell(new Paragraph("Phone", font));
        pdfTable.addCell(new Paragraph("Position", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getAllUsers() != null) {
            for (PartnerUser e : getAllUsers()) {
                pdfTable.addCell(new Paragraph(e.getUsername(), font));
                pdfTable.addCell(new Paragraph(
                        e.getPersonel().getFirstname() + " " + e.getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getPersonel().getEmail(), font));
                pdfTable.addCell(new Paragraph(
                        (e.getPersonel().getDepartment() != null) ? e.getPersonel().getDepartment().getName()
                                : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(
                        (e.getPersonel().getRegion() != null) ? e.getPersonel().getRegion().getName() : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(e.getPersonel().getPhone(), font));
                pdfTable.addCell(new Paragraph(e.getPersonel().getPosition(), font));
            }
        }
        break;
    }
    case 2: // due driver's license
    {
        numberOfColumns = 6;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Full Name", font));
        pdfTable.addCell(new Paragraph("Dept", font));
        pdfTable.addCell(new Paragraph("Region", font));
        pdfTable.addCell(new Paragraph("Phone", font));
        pdfTable.addCell(new Paragraph("Position", font));
        pdfTable.addCell(new Paragraph("License Due Date", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getDueDriversLic() != null) {
            for (DriverLicense e : getDueDriversLic()) {
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getFirstname() + " "
                        + e.getDriver().getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getDepartment() != null
                        ? e.getDriver().getPersonel().getDepartment().getName()
                        : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getRegion() != null
                        ? e.getDriver().getPersonel().getRegion().getName()
                        : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPhone(), font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPosition(), font));
                pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font));
            }
        }
        break;
    }
    case 3: // accidents
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Accident Date", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Driver", font));
        pdfTable.addCell(new Paragraph("Driver Comment", font));
        pdfTable.addCell(new Paragraph("Police Officer", font));
        pdfTable.addCell(new Paragraph("Police Station", font));
        pdfTable.addCell(new Paragraph("Police Comment", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getVehicleAccidents() != null) {
            for (VehicleAccident e : getVehicleAccidents()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font));
                pdfTable.addCell(new Paragraph(e.getDriver_name(), font));
                pdfTable.addCell(new Paragraph(e.getDriverComment(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceStation(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceComment(), font));
            }
        }
        break;
    }
    case 4: // vehicles by brand
    {
        numberOfColumns = 4;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Make", font));
        pdfTable.addCell(new Paragraph("Model", font));
        pdfTable.addCell(new Paragraph("Year", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getVehiclesByBrand() != null) {
            for (Vehicle e : getVehiclesByBrand()) {
                pdfTable.addCell(new Paragraph(e.getModel().getMaker().getName(), font));
                pdfTable.addCell(new Paragraph(e.getModel().getName(), font));
                pdfTable.addCell(new Paragraph(e.getModel().getYear(), font));
                pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font));
            }
        }
        break;
    }
    case 5: // routine maintenance
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Requester", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Start Date", font));
        pdfTable.addCell(new Paragraph("Initial Cost", font));
        pdfTable.addCell(new Paragraph("Status", font));
        pdfTable.addCell(new Paragraph("Close Date", font));
        pdfTable.addCell(new Paragraph("Final Cost", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getRmaints() != null) {
            for (VehicleRoutineMaintenance e : getRmaints()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " "
                        + e.getCreatedBy().getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getDescription(), font));
                pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getInitial_amount().toPlainString(), font));
                pdfTable.addCell(new Paragraph(e.getStatus(), font));
                pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getClosed_amount().toPlainString(), font));
            }
        }
        break;
    }
    case 6: // ad hoc maintenance
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Requester", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Start Date", font));
        pdfTable.addCell(new Paragraph("Initial Cost", font));
        pdfTable.addCell(new Paragraph("Status", font));
        pdfTable.addCell(new Paragraph("Close Date", font));
        pdfTable.addCell(new Paragraph("Final Cost", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getAdhocmaints() != null) {
            for (VehicleAdHocMaintenance e : getAdhocmaints()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " "
                        + e.getCreatedBy().getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getDescription(), font));
                pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getInitial_cost().toPlainString(), font));
                pdfTable.addCell(new Paragraph(e.getStatus(), font));
                pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getClosed_cost().toPlainString(), font));
            }
        }
        break;
    }
    case 7: // active accidents
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Accident Date", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Driver Name", font));
        pdfTable.addCell(new Paragraph("Driver Comment", font));
        pdfTable.addCell(new Paragraph("Police Name", font));
        pdfTable.addCell(new Paragraph("Station Name", font));
        pdfTable.addCell(new Paragraph("Police Comment", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getActiveAccidents() != null) {
            for (VehicleAccident e : getActiveAccidents()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font));
                pdfTable.addCell(new Paragraph(e.getDriver_name(), font));
                pdfTable.addCell(new Paragraph(e.getDriverComment(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceStation(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceComment(), font));
            }
        }
        break;
    }
    case 8: // coporate trips
    {
        numberOfColumns = 9;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 6, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Requester", font));
        pdfTable.addCell(new Paragraph("Department", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Departure Location", font));
        pdfTable.addCell(new Paragraph("Arrival Location", font));
        pdfTable.addCell(new Paragraph("Departure Date and Time", font));
        pdfTable.addCell(new Paragraph("Est. Arrival Date and Time", font));
        pdfTable.addCell(new Paragraph("Act. Arrival Date and Time", font));
        pdfTable.addCell(new Paragraph("Status", font));

        font = new Font(helvetica, 6, Font.NORMAL);

        if (getCorTrips() != null) {
            for (CorporateTrip e : getCorTrips()) {
                pdfTable.addCell(
                        new Paragraph(e.getStaff().getFirstname() + " " + e.getStaff().getLastname(), font));
                pdfTable.addCell(new Paragraph(
                        (e.getStaff().getDepartment() != null) ? e.getStaff().getDepartment().getName() : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(
                        e.getVehicle() != null ? e.getVehicle().getRegistrationNo() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getDepartureLocation(), font));
                pdfTable.addCell(new Paragraph(e.getArrivalLocation(), font));
                pdfTable.addCell(new Paragraph(e.getDepartureDateTime().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getEstimatedArrivalDateTime().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(
                        e.getCompleteRequestDateTime() != null ? e.getCompleteRequestDateTime().toLocaleString()
                                : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(e.getTripStatus(), font));
            }
        }
        break;
    }
    case 9: // expense report
    {
        numberOfColumns = 4;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Type", font));
        pdfTable.addCell(new Paragraph("Date", font));
        pdfTable.addCell(new Paragraph("Amount", font));
        pdfTable.addCell(new Paragraph("Detail", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getExpenses() != null) {
            for (Expense e : getExpenses()) {
                pdfTable.addCell(new Paragraph(e.getType().getName(), font));
                pdfTable.addCell(new Paragraph(e.getExpense_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph("" + e.getAmount(), font));
                pdfTable.addCell(new Paragraph(e.getRemarks(), font));
            }
        }
        break;
    }
    case 10: // vehicle ages
    {
        numberOfColumns = 6;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Make", font));
        pdfTable.addCell(new Paragraph("Model", font));
        pdfTable.addCell(new Paragraph("Year", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Date of Purchase", font));
        pdfTable.addCell(new Paragraph("Age (in years)", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getVehiclesAges() != null) {
            for (Vehicle e : getVehiclesAges()) {
                pdfTable.addCell(new Paragraph(
                        e.getModel().getMaker() != null ? e.getModel().getMaker().getName() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getName() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getYear() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(
                        e.getPurchaseDate() != null ? e.getPurchaseDate().toLocaleString() : "N/A", font));
                pdfTable.addCell(new Paragraph("" + e.getAge(), font));
            }
        }
        break;
    }
    case 11: // vehicle fuelings
    {
        numberOfColumns = 5;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Date", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Litres", font));
        pdfTable.addCell(new Paragraph("Amount", font));
        pdfTable.addCell(new Paragraph("Source", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getFuelings() != null) {
            for (VehicleFueling e : getFuelings()) {
                pdfTable.addCell(new Paragraph(e.getCaptured_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph("" + e.getLitres(), font));
                pdfTable.addCell(new Paragraph("" + e.getAmt(), font));
                pdfTable.addCell(new Paragraph(e.getSource(), font));
            }
        }
        break;
    }
    case 12: // due vehicle licenses
    {
        numberOfColumns = 5;
        pdfTable = new PdfPTable(numberOfColumns);

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

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Fleet", font));
        pdfTable.addCell(new Paragraph("Make", font));
        pdfTable.addCell(new Paragraph("Model", font));
        pdfTable.addCell(new Paragraph("License Due Date", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getDueVehicleLicenses() != null) {
            for (VehicleLicense e : getDueVehicleLicenses()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getVehicle().getFleet().getName(), font));
                pdfTable.addCell(new Paragraph(
                        e.getVehicle().getModel() != null ? e.getVehicle().getModel().getMaker().getName()
                                : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(
                        e.getVehicle().getModel() != null ? e.getVehicle().getModel().getName() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font));
            }
        }
        break;
    }
    }

    pdfTable.setWidthPercentage(100);

    return pdfTable;
}