Example usage for com.itextpdf.text Element ALIGN_RIGHT

List of usage examples for com.itextpdf.text Element ALIGN_RIGHT

Introduction

In this page you can find the example usage for com.itextpdf.text Element ALIGN_RIGHT.

Prototype

int ALIGN_RIGHT

To view the source code for com.itextpdf.text Element ALIGN_RIGHT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public PdfPTable getShoppingBasketForAuthor(Author a, PdfContentByte cb) {
    int position = 0;
    float subtotal_CHF = 0.0f;
    float shipping_CHF = 0.0f;
    float vat25_CHF = 0.0f;
    float vat80_CHF = 0.0f;

    String author = a.getShortName();

    BarcodeEAN codeEAN = new BarcodeEAN();

    // Pos | Menge | Eancode | Bezeichnung | MwSt | Preis
    PdfPTable table = new PdfPTable(new float[] { 1, 2, 3, 6, 1, 2 });
    table.setWidthPercentage(100f);//from   w ww . j  a va  2  s .  c o  m
    table.getDefaultCell().setPadding(5);
    table.setSpacingAfter(5f);

    PdfPCell cell = new PdfPCell();

    table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("vat"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_RIGHT, 1));
    table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10,
            Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1));

    if (m_shopping_basket.size() > 0 && !author.isEmpty()) {
        for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) {
            Article article = entry.getValue();
            if (article.getAuthor().trim().toLowerCase().contains(author)) {
                String price_pruned = "";
                String total_price_CHF = "";
                if (article.getCode() != null && article.getCode().equals("ibsa")) {
                    float cr = article.getCashRebate();
                    if (article.getDraufgabe() > 0) {
                        price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f));
                        total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(0.0f));
                    } else {
                        price_pruned = String.format("%.2f", article.getBuyingPrice(cr));
                        total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(cr));
                    }
                } else {
                    price_pruned = article.getCleanExfactoryPrice();
                    total_price_CHF = String.format("%.2f", article.getTotExfactoryPrice());
                }

                if (!price_pruned.isEmpty() && !price_pruned.equals("..")) {
                    // Index
                    table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));
                    // Anzahl
                    table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
                    // EAN code
                    codeEAN.setCode(article.getEanCode());
                    Image img = codeEAN.createImageWithBarcode(cb, null, null);
                    img.scalePercent(120);
                    cell = new PdfPCell(img);
                    cell.setBorder(Rectangle.NO_BORDER);
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    cell.setUseBorderPadding(true);
                    cell.setBorderWidth(5);
                    if (position == 1)
                        cell.setPaddingTop(8);
                    else
                        cell.setPaddingTop(0);
                    cell.setPaddingBottom(8);
                    table.addCell(cell);
                    // Artikelbezeichnung
                    table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));
                    // MwSt                  
                    table.addCell(getStringCell(String.format("%.1f%%", article.getVat()), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1));
                    // Preis (exkl. MwSt)
                    // float price_CHF = article.getQuantity()*Float.parseFloat(price_pruned);
                    table.addCell(getStringCell(total_price_CHF, font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_RIGHT, 1));
                }
            }
        }

        subtotal_CHF = a.getSubtotal();
        shipping_CHF = a.getShippingCosts();
        vat25_CHF = a.getVat25();
        vat80_CHF = a.getVat80() + a.getShippingCosts() * 0.08f;

        float fulltotal_CHF = subtotal_CHF + shipping_CHF + vat25_CHF + vat80_CHF;

        table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", subtotal_CHF), font_bold_10, Rectangle.TOP,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("shipping"), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", shipping_CHF), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", vat25_CHF), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("vat") + " (8.0%)", font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", vat80_CHF), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", fulltotal_CHF), font_bold_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));
    }
    return table;
}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public PdfPTable getFullShoppingBasket(PdfContentByte cb, String mode) {
    int position = 0;
    float sub_total_CHF = 0.0f;

    BarcodeEAN codeEAN = new BarcodeEAN();

    // Pos | Menge | Eancode | Bezeichnung | Preis
    PdfPTable table = new PdfPTable(new float[] { 1, 1, 3, 6, 2 });
    table.setWidthPercentage(100f);/*  w  w  w .  j  a  va  2 s.  c o m*/
    table.getDefaultCell().setPadding(5);
    table.setSpacingAfter(5f);

    PdfPCell cell = new PdfPCell();

    table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10,
            Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1));

    if (m_shopping_basket.size() > 0) {
        for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) {
            Article article = entry.getValue();

            if (mode.equals("all") || (mode.equals("rest") && (m_map_of_authors == null
                    || !anyElemIsContained(m_map_of_authors, article.getAuthor().trim().toLowerCase())))) {
                String price_pruned = "";
                if (article.getCode() != null && article.getCode().equals("ibsa")) {
                    float cr = article.getCashRebate();
                    if (article.getDraufgabe() > 0)
                        price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f));
                    else
                        price_pruned = String.format("%.2f", article.getBuyingPrice(cr));
                } else {
                    price_pruned = article.getCleanExfactoryPrice();
                }

                if (!price_pruned.isEmpty() && !price_pruned.equals("..")) {
                    table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));
                    table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));

                    codeEAN.setCode(article.getEanCode());
                    Image img = codeEAN.createImageWithBarcode(cb, null, null);
                    img.scalePercent(120);
                    cell = new PdfPCell(img);
                    cell.setBorder(Rectangle.NO_BORDER);
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    cell.setUseBorderPadding(true);
                    cell.setBorderWidth(5);
                    if (position == 1)
                        cell.setPaddingTop(8);
                    else
                        cell.setPaddingTop(0);
                    cell.setPaddingBottom(8);
                    table.addCell(cell);

                    table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));

                    float price_CHF = article.getQuantity() * Float.parseFloat(price_pruned);
                    sub_total_CHF += price_CHF;
                    table.addCell(getStringCell(String.format("%.2f", price_CHF), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1));
                }
            }
        }

        table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", sub_total_CHF), font_bold_10, Rectangle.TOP,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 0.025f), font_norm_10,
                PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 1.025f), font_bold_10,
                PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2));
    }
    return table;
}

From source file:com.microware.intrahealth.Createpdf2.java

public static Paragraph mypara(String ab, int flag) {
    Paragraph preface1 = new Paragraph(ab, subFont);
    if (flag == 1)
        preface1.setAlignment(Element.ALIGN_CENTER);
    if (flag == 2)
        preface1.setAlignment(Element.ALIGN_LEFT);
    if (flag == 3)
        preface1.setAlignment(Element.ALIGN_RIGHT);
    return preface1;
}

From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java

License:Open Source License

public int handle(final User user, final User manager, final ExpenseNote en)
        throws MalformedURLException, IOException, DocumentException {

    log.info("Building list of expenses ...");
    List<Expense> expenses = Expense.list(en);
    log.info("Retrieved " + expenses.size() + " expenses from the datastore");

    log.info("Creating ExpenseNoteDocOutputStream");
    ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en);

    Document document = new Document();
    PdfWriter.getInstance(document, stream);
    document.open();//  w w w.j a va  2  s . co  m

    document.addTitle("Expense note " + en.id + " of " + user.name);
    document.addSubject("Expense note generated by Rogerthat Enterprise!");
    document.addKeywords("expense note");
    document.addAuthor(user.name);
    document.addCreator("Rogerthat OneApp Enterprise Mobility");

    Paragraph preface = new Paragraph();

    preface.add(new Paragraph("TP Vision expense note", titleFont));
    preface.add(new Paragraph(" "));

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Date date = new Date();
    preface.add(new Paragraph("Date: " + dateFormat.format(date)));
    preface.add(new Paragraph("Requestor: " + user.name));
    preface.add(new Paragraph("Approver: " + manager.name));
    preface.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(110);
    table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 });
    addHeader(table, "Id");
    addHeader(table, "Date");
    addHeader(table, "Nature");
    addHeader(table, "Description");
    addHeader(table, "Account");
    addHeader(table, "Amount");
    addHeader(table, "Voucher");
    table.setHeaderRows(1);

    Collections.sort(expenses, new Comparator<Expense>() {
        @Override
        public int compare(Expense e1, Expense e2) {
            return (int) (e1.date - e2.date);
        }
    });
    int i = 0;
    double total = 0;
    for (Expense expense : expenses) {
        PdfPCell c1 = new PdfPCell(new Phrase("" + ++i));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.addCell(dateFormat.format(new Date(expense.date * 1000)));
        table.addCell(expense.nature);
        table.addCell(expense.description);
        table.addCell("" + expense.account);
        c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency));
        c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(c1);
        table.addCell(expense.voucher);
        total += expense.amount;
    }

    preface.add(table);

    preface.add(new Paragraph(" "));
    preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont));

    document.add(preface);

    i = 0;
    for (Expense expense : expenses) {
        i++;
        if (expense.receipt == null)
            continue;

        document.newPage();
        Paragraph receipt = new Paragraph();
        receipt.add(new Paragraph("Attachment " + i, titleFont));
        document.add(receipt);
        Image image = Image.getInstance(new URL(expense.receipt));
        image.setRotationDegrees(-90);
        float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100;

        image.scalePercent(scaler);
        document.add(image);
    }

    document.close();
    stream.close();

    return stream.getSize();

}

From source file:com.myapp.struts.transaction.transactionAction.java

public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, Exception {
    if (Constants.isSessionActive(request)) {
        transactionForm transactionForm = (transactionForm) form;
        try {//from ww  w .  j  av a2s.  c  o m
            Date utilDate = new Date();
            java.sql.Date date = new java.sql.Date(utilDate.getTime());
            Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD,
                    BaseColor.BLACK);
            Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12,
                    Font.BOLD | Font.UNDERLINE, BaseColor.BLACK);
            Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD);

            Document document = new Document();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);
            document.open();

            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs.

            Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont);
            para1.setAlignment(Element.ALIGN_CENTER);
            document.add(para1);

            para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont);
            para1.setAlignment(Element.ALIGN_CENTER);
            document.add(para1);

            para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont);
            para1.setAlignment(Element.ALIGN_LEFT);
            document.add(para1);

            para1 = new Paragraph(
                    transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont);
            para1.setAlignment(Element.ALIGN_LEFT);
            document.add(para1);
            Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + "");
            if (obj != null) {
                para1 = new Paragraph("Group : " + obj.getGroupname(), font);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont);
                para1.setAlignment(Element.ALIGN_RIGHT);
                document.add(para1);

                if (transactionForm.getStatus().equalsIgnoreCase("Settled")) {
                    para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont);
                    para1.setAlignment(Element.ALIGN_RIGHT);
                    document.add(para1);
                }

                String dateStr = sdf.format(date);
                para1 = new Paragraph("DATED:" + dateStr, font);
                para1.setAlignment(Element.ALIGN_RIGHT);
                document.add(para1);

                // add a couple of blank lines
                document.add(Chunk.NEWLINE);

                if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) {
                    PdfPTable table2 = new PdfPTable(7);
                    float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f };

                    table2.setWidthPercentage(100);
                    table2.setWidths(columnWidths);

                    para1 = new Paragraph("Sl No.", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    PdfPCell cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Term", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Receipt No.", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Receipt Date", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Payment Mode", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Remarks", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Paid Amount", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    int x = 1;
                    double total = 0;
                    //Iterator it = hmPayments.entrySet().iterator();
                    //while (it.hasNext()) {
                    if (hmPayments.size() > 0) {
                        for (int i = 1; i <= obj.getNoofinstallment(); i++) {
                            //float f = columnWidths[i];
                            Payment f1 = (Payment) hmPayments.get(i + "");
                            //}
                            //Map.Entry pairs = (Map.Entry) it.next();
                            //Payment f1 = (Payment) pairs.getValue();
                            String term = i + "";

                            para1 = new Paragraph(Integer.toString(x), font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);
                            x++;

                            para1 = new Paragraph(term, font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(f1.getPaymentid() + "", font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(sdf.format(f1.getPaiddate()), font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(f1.getRemarks(), font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            //para1 = new Paragraph(f1.getPaidamount() + "", boldfont);
                            para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);
                            total = total + obj.getInstallmentamount();
                            if (hmPayments.size() == i) {
                                break;
                            }
                        }

                        para1 = new Paragraph("Total", boldfont);
                        para1.setAlignment(Element.ALIGN_LEFT);
                        cell = new PdfPCell(para1);
                        cell.setColspan(6);
                        table2.addCell(cell);

                        //String numberStr = String.format("%.2f", total + "");
                        para1 = new Paragraph(total + "", boldfont);
                        para1.setAlignment(Element.ALIGN_CENTER);
                        cell = new PdfPCell(para1);
                        //cell.setColspan(7);
                        table2.addCell(cell);

                        table2.setHorizontalAlignment(Element.ALIGN_LEFT);
                        document.add(table2);
                    } else {
                        para1 = new Paragraph("NO PAYMENTS FOUND", boldfont);
                        para1.setAlignment(Element.ALIGN_CENTER);
                        document.add(para1);
                    }

                } else {
                    para1 = new Paragraph("NO RECORDS FOUND", boldfont);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    document.add(para1);
                }
                document.add(Chunk.NEWLINE);

                //document.close();
                //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf"));
                document.close();
                ServletOutputStream outputStream = response.getOutputStream();
                baos.writeTo(outputStream);
                response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\"");
                response.setContentType("application/pdf");
                outputStream.flush();
                outputStream.close();
                return mapping.findForward("display");
            } else {
                para1 = new Paragraph("NO RECORDS FOUND", boldfont);
                para1.setAlignment(Element.ALIGN_CENTER);
                document.add(para1);
                document.close();
                ServletOutputStream outputStream = response.getOutputStream();
                baos.writeTo(outputStream);
                response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\"");
                response.setContentType("application/pdf");
                outputStream.flush();
                outputStream.close();
                return mapping.findForward("display");
            }
        } catch (DocumentException i) {
            System.out.println(i);
            return mapping.findForward("fail");
        } catch (IOException i) {
            System.out.println(i);
            return mapping.findForward("fail");
        }
    } else {
        return mapping.findForward("exp");
    }
}

From source file:com.pdfwriter.PrintInventoryReport.java

public void create(ObservableList list, String totalSales) {
    try {// ww w.ja  v a  2  s.  c o m
        Document document = new Document(PageSize.LETTER);
        document.setMargins(1, 1, 1, 1);

        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        Font font2 = new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD);
        PdfPTable table = new PdfPTable(5);
        table.setWidthPercentage(95);
        table.setWidths(new int[] { 40, 40, 40, 40, 40 });
        PdfPCell cell;

        cell = new PdfPCell(new Phrase("", font2));
        cell.setBorder(0);
        cell.setColspan(8);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(0);

        cell.setBorderWidthBottom(0);
        table.addCell(cell);

        cell = new PdfPCell(
                new Phrase("KELNOVI SHOPPING BOTIQUE", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(
                new Phrase("Pondol,Loon, Bohol", new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD)));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(
                new Phrase("Phone/Fax#:000-000-000", new Font(Font.FontFamily.UNDEFINED, 9, Font.UNDERLINE)));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(10);
        cell.setRowspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("SALES REPORT", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("NO."));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(14);
        cell.setBackgroundColor(BaseColor.GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("PRODUCT NAME"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(14);
        cell.setBackgroundColor(BaseColor.GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("PRICE"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(14);
        cell.setBackgroundColor(BaseColor.GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("QUANTITY"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(14);
        cell.setBackgroundColor(BaseColor.GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("AMOUNT PAYABLE"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(14);
        cell.setBackgroundColor(BaseColor.GRAY);
        table.addCell(cell);

        for (int i = 0; i < list.size(); i++) {
            it = (ProductClass) list.get(i);

            cell = new PdfPCell(new Phrase("" + it.idProperty().get()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(14);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("" + it.productDescriptionProperty().get()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(14);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("" + it.productPriceProperty().get()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(14);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("" + it.productQtyProperty().get()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(14);
            table.addCell(cell);
            //totalSales.setText(String.format("%,.2f",globalSales));

            cell = new PdfPCell(new Phrase(
                    String.format("%,.2f", Double.parseDouble(it.productTotalSalesProperty().get()))));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(14);
            table.addCell(cell);

        }

        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("TOTAL AMOUNT PAYABLE:"));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(
                new Phrase("Php " + totalSales, new Font(Font.FontFamily.UNDEFINED, 14, Font.UNDERLINE)));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Approved by:"));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("MICHAEL NOVI MALUENDA II",
                new Font(Font.FontFamily.UNDEFINED, 14, Font.UNDERLINE)));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("General Manager"));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        table.addCell(cell);

        document.add(table);
        document.close();
        openFile();

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

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds title section.//from w  w  w .ja  v  a  2  s.c o m
 * @param info the project info object
 * @return PDF input stream
 * @throws PhrescoException 
 */
public static InputStream getTitleSection(ApplicationInfo info) throws PhrescoException {
    if (isDebugEnabled) {
        S_LOGGER.debug(" Entering Method DocumentUtil.getTitleSection(ProjectInfo info)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("getTitleSection() projectCode=" + info.getCode());
    }
    try {
        //create output stream
        com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PdfWriter.getInstance(docu, os);
        docu.open();

        //add standard title section with supplied info object
        Paragraph paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setFont(DocConstants.TITLE_FONT);
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        paragraph.add(info.getName());
        addBlankLines(paragraph, MAGICNUMBER.BLANKLINESFOUR);
        docu.add(paragraph);

        paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_CENTER);
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        String techName = info.getTechInfo().getName();
        if (StringUtils.isNotEmpty(info.getTechInfo().getVersion())) {
            paragraph.add(techName + " - " + info.getTechInfo().getVersion());
        } else {
            paragraph.add(techName);
        }
        docu.add(paragraph);

        paragraph = new Paragraph();
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.add(DocumentMessages.getString("Documents.version.name") + getVersion(info)); //$NON-NLS-1$
        addBlankLines(paragraph, MAGICNUMBER.BLANKLINESSEVEN);
        docu.add(paragraph);

        if (StringUtils.isNotEmpty(info.getDescription())) {
            paragraph = new Paragraph();
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            paragraph.setFont(DocConstants.DESC_FONT);
            paragraph.setFirstLineIndent(MAGICNUMBER.BLANKLINESEIGHT);
            docu.add(paragraph);

        }

        docu.close();

        //Create an inputstream to return.
        return new ByteArrayInputStream(os.toByteArray());
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }

}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds title section./*w  ww. j  ava2 s  .  com*/
 * @param info the project info object
 * @return PDF input stream
 * @throws DocumentException
 */
public static InputStream getTitleSection(ProjectInfo info) throws DocumentException {
    if (isDebugEnabled) {
        S_LOGGER.debug(" Entering Method DocumentUtil.getTitleSection(ProjectInfo info)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("getTitleSection() projectCode=" + info.getCode());
    }
    //create output stream
    com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PdfWriter.getInstance(docu, os);
    docu.open();

    //add standard title section with supplied info object
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setFont(DocConstants.TITLE_FONT);
    addBlankLines(paragraph, 10);
    paragraph.add(info.getName());
    addBlankLines(paragraph, 4);
    docu.add(paragraph);

    paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    addBlankLines(paragraph, 10);
    String techName = info.getTechnology().getName();
    if (info.getTechnology().getVersions() != null) {
        paragraph.add(techName + " - " + info.getTechnology().getVersions().get(0));
    } else {
        paragraph.add(techName);
    }
    docu.add(paragraph);

    paragraph = new Paragraph();
    addBlankLines(paragraph, 10);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(DocumentMessages.getString("Documents.version.name") + getVersion(info)); //$NON-NLS-1$
    addBlankLines(paragraph, 7);
    docu.add(paragraph);
    paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    paragraph.setFont(DocConstants.DESC_FONT);
    paragraph.setFirstLineIndent(8);
    paragraph.add(info.getDescription());
    docu.add(paragraph);

    docu.close();

    //Create an inputstream to return.
    return new ByteArrayInputStream(os.toByteArray());

}

From source file:com.photoshop.misc.Factuurgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);//from   w w w.  j  a  va 2s . co  m

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(this.Getspringmessage("Date") + ": " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + ": " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ":", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(
            this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam() + ",", subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(this.Getspringmessage("paymentvieuw"), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);
    //Overzicht bwt bedrag
    addEmptyLine(preface, 1);
    Paragraph btw = new Paragraph(this.Getspringmessage("taxamount") + ": " + " "
            + String.format("%.2f", (this.totaalprijs / 100) * 19), subFont);
    btw.setAlignment(Element.ALIGN_RIGHT);
    preface.add(btw);
    //Overzicht Totaalbedrag
    Paragraph Totaalbedrag = new Paragraph(
            this.Getspringmessage("totalamount") + ": " + " " + String.format("%.2f", this.totaalprijs),
            subtitel);
    Totaalbedrag.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Totaalbedrag);
    addEmptyLine(preface, 1);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("invoicend"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);
    document.add(preface);
    Mailgenerator mail = new Mailgenerator();
    mail.Sendmail("willem1995@hotmail.com", order, env, filename);
}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    document.newPage();/*from   ww  w  .  ja  v a2 s  .  c om*/
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(Getspringmessage("Date") + " " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + " " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ": ", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam(),
            subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            this.Getspringmessage("allordersby") + " " + order.getInvoiceaddress().getKlantnaam(), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("thanksforordering"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);

    document.add(preface);

}