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:it.vige.magazzino.pdf.Format1DocumentReceipt.java

License:Apache License

@Model
public void build(Receipt receipt) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("messages");

    Document document = new Document();
    ByteArrayOutputStream bytesOS = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, bytesOS);
    document.open();/*w w  w .j  a va 2s.  c  o  m*/

    Font normalFont = new Font();
    Font headerFont = FontFactory.getFont(FontFactory.TIMES, 9);

    PdfContentByte canvas = writer.getDirectContentUnder();
    List<Data> imagesJar = receipt.getJar().getFiles();

    if (imagesJar != null && imagesJar.size() > 0) {
        Image image1 = Image.getInstance(imagesJar.get(0).getData());
        image1.setAbsolutePosition(166, 738);
        image1.scalePercent(60);
        document.add(image1);
        if (imagesJar.size() > 1) {
            Image image2 = Image.getInstance(imagesJar.get(1).getData());
            image2.setAbsolutePosition(326, 748);
            image2.scalePercent(40);
            document.add(image2);
        }
    }

    Phrase phrase1 = new Phrase(receipt.getJar().getRagSoc1(), normalFont);
    Phrase phrase2 = new Phrase(
            receipt.getJar().getAddress().getAddress() + " " + receipt.getJar().getAddress().getCivicNumber(),
            normalFont);
    Phrase phrase3 = new Phrase("Loc. " + receipt.getJar().getAddress().getTown() + " - "
            + receipt.getJar().getAddress().getCap() + " " + receipt.getJar().getAddress().getCity() + " ("
            + receipt.getJar().getAddress().getProvince() + ")", normalFont);
    Phrase phrase4 = new Phrase("Tel. " + receipt.getJar().getAddress().getPhone() + " r.a.Fax "
            + receipt.getJar().getAddress().getFax(), normalFont);
    Phrase phrase5 = new Phrase(
            receipt.getJar().getAddress().getSite() + " E-mail: " + receipt.getJar().getAddress().getEmail(),
            normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 36, 784, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 36, 774, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 36, 764, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 36, 754, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 36, 744, 0);

    Phrase phrase6 = new Phrase(bundle.getString("magazzino_iva") + " " + receipt.getJar().getIva(),
            normalFont);
    Phrase phrase7 = new Phrase(bundle.getString("magazzino_capsoc") + " " + receipt.getJar().getCapSoc()
            + " - " + bundle.getString("magazzino_reapi") + " n. " + receipt.getJar().getReaPI(), normalFont);
    Phrase phrase8 = new Phrase("Reg. Impr. PI n. " + receipt.getJar().getIva(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 36, 724, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 36, 714, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 36, 704, 0);

    Phrase phrase9 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase10 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase11 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase12 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase13 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase14 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase15 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 664, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 36, 654, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 644, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 36, 634, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 624, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 36, 614, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 604, 0);

    List<Data> imagesCustomer = receipt.getCustomer().getFiles();

    if (imagesCustomer != null && imagesCustomer.size() > 0) {
        Image image3 = Image.getInstance(imagesCustomer.get(0).getData());
        image3.setAbsolutePosition(212, 664);
        image3.scalePercent(40);
        document.add(image3);
    }

    Phrase phrase16 = new Phrase(receipt.getCustomer().getName(), normalFont);
    Phrase phrase17 = new Phrase(receipt.getCustomer().getAddress().getAddress() + ", "
            + receipt.getCustomer().getAddress().getCivicNumber(), normalFont);
    Phrase phrase18 = new Phrase(
            receipt.getCustomer().getAddress().getCap() + " " + receipt.getCustomer().getAddress().getCity()
                    + " " + receipt.getCustomer().getAddress().getProvince(),
            normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 206, 644, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 206, 624, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 206, 604, 0);

    Phrase phrase19 = new Phrase("prova", normalFont);
    Phrase phrase20 = new Phrase("prova", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 316, 694, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 356, 694, 0);

    Phrase phrase21 = new Phrase(
            bundle.getString("customer_code").toUpperCase() + " " + bundle.getString("customer").toUpperCase(),
            headerFont);
    Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva").toUpperCase(), headerFont);
    Phrase phrase23 = new Phrase(bundle.getString("pdf_agent").toUpperCase(), headerFont);
    Phrase phrase24 = new Phrase(bundle.getString("pdf_number_receipt").toUpperCase(), headerFont);
    Phrase phrase25 = new Phrase(
            bundle.getString("receipt_date").toUpperCase() + " " + bundle.getString("receipt").toUpperCase(),
            headerFont);
    Phrase phrase26 = new Phrase(bundle.getString("pdf_number_page").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 24, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 100, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 176, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 390, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 466, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase26, 542, 540, 0);

    Phrase phrase27 = new Phrase("aaqaqaq", normalFont);
    Phrase phrase28 = new Phrase("cddcddcd", normalFont);
    Phrase phrase29 = new Phrase("cnjcndkd", normalFont);
    Phrase phrase30 = new Phrase(receipt.getCodeReceipt() + "", normalFont);
    Phrase phrase31 = new Phrase(receipt.getDate(), normalFont);
    Phrase phrase32 = new Phrase("tgsb", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase27, 36, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase28, 106, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase29, 176, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase30, 396, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase31, 470, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase32, 546, 530, 0);

    Phrase phrase33 = new Phrase("aaqaqaq", headerFont);
    Phrase phrase34 = new Phrase("cddcddcd", headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 24, 513, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 264, 513, 0);

    Phrase phrase35 = new Phrase("cnjcndkd", normalFont);
    Phrase phrase36 = new Phrase("dddedreqq", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 36, 503, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 276, 503, 0);

    Phrase phrase37 = new Phrase(bundle.getString("article_code").toUpperCase(), headerFont);
    Phrase phrase38 = new Phrase(bundle.getString("article_description").toUpperCase(), headerFont);
    Phrase phrase39 = new Phrase(bundle.getString("article_um").toUpperCase(), headerFont);
    Phrase phrase40 = new Phrase(bundle.getString("pdf_number_articles").toUpperCase(), headerFont);
    Phrase phrase41 = new Phrase(bundle.getString("article_prize").toUpperCase(), headerFont);
    Phrase phrase42 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont);
    Phrase phrase43 = new Phrase(bundle.getString("pdf_amount").toUpperCase(), headerFont);
    Phrase phrase44 = new Phrase(bundle.getString("pdf_iva").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase37, 47, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase38, 126, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase39, 286, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase40, 324, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase41, 373, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase42, 440, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 488, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 552, 480, 0);

    Phrase phrase45 = null;
    Phrase phrase46 = null;
    Phrase phrase47 = null;
    Phrase phrase48 = null;
    Phrase phrase49 = null;
    Phrase phrase50 = null;
    Phrase phrase51 = null;
    Phrase phrase52 = null;

    int i = 0;
    for (i = 0; i < 70; i = i + 15) {
        phrase45 = new Phrase("dgbsbb", normalFont);
        phrase46 = new Phrase("323232", normalFont);
        phrase47 = new Phrase("bbg", normalFont);
        phrase48 = new Phrase("wefwe", normalFont);
        phrase49 = new Phrase("ewrew", normalFont);
        phrase50 = new Phrase("ewr5", normalFont);
        phrase51 = new Phrase("dsadasd", normalFont);
        phrase52 = new Phrase("ds", normalFont);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase45, 59, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase46, 126, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase47, 280, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 306, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase49, 368, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 436, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase51, 480, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 556, 460 - i, 0);
    }

    int j = 298;
    if (i - 298 < 0)
        i = 298;
    else {
        j = i;
        i = 460 - i;
    }

    Phrase phrase81 = new Phrase(receipt.getCause(), normalFont);
    Phrase phrase82 = new Phrase(receipt.getDescription(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase81, 59, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase82, 326, i, 0);

    Phrase phrase53 = new Phrase(bundle.getString("pdf_total_goods").toUpperCase(), headerFont);
    Phrase phrase54 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont);
    Phrase phrase55 = new Phrase(bundle.getString("pdf_total_net").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase53, 26, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase54, 104, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase55, 182, i - 30, 0);

    Phrase phrase56 = new Phrase("opoppp", normalFont);
    Phrase phrase57 = new Phrase("2ws", normalFont);
    Phrase phrase58 = new Phrase("78900", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase56, 96, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase57, 176, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase58, 252, i - 50, 0);

    Phrase phrase59 = new Phrase(bundle.getString("pdf_expiries").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase59, 36, i - 70, 0);

    Phrase phrase60 = new Phrase("78900", normalFont);
    Phrase phrase61 = new Phrase("opoppp", normalFont);
    Phrase phrase62 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase60, 166, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase61, 166, i - 110, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase62, 166, i - 130, 0);

    Phrase phrase63 = new Phrase("78900", normalFont);
    Phrase phrase64 = new Phrase("opoppp", normalFont);
    Phrase phrase65 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase63, 256, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase64, 256, i - 110, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase65, 256, i - 130, 0);

    Phrase phrase66 = new Phrase(bundle.getString("pdf_transport").toUpperCase(), headerFont);
    Phrase phrase67 = new Phrase(bundle.getString("pdf_caching").toUpperCase(), headerFont);
    Phrase phrase68 = new Phrase(bundle.getString("pdf_various_costs").toUpperCase(), headerFont);
    Phrase phrase69 = new Phrase(bundle.getString("pdf_stamps").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase66, 260, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase67, 340, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase68, 418, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase69, 496, i - 30, 0);

    Phrase phrase70 = new Phrase("2ws", normalFont);
    Phrase phrase71 = new Phrase("78900", normalFont);
    Phrase phrase72 = new Phrase("opoppp", normalFont);
    Phrase phrase73 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase70, 300, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase71, 390, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase72, 468, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase73, 546, i - 50, 0);

    Phrase phrase74 = new Phrase(bundle.getString("article_imponible").toUpperCase(), headerFont);
    Phrase phrase75 = new Phrase(bundle.getString("pdf_tax").toUpperCase(), headerFont);
    Phrase phrase76 = new Phrase(bundle.getString("pdf_total_receipt").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase74, 260, i - 70, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase75, 352, i - 70, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase76, 484, i - 70, 0);

    Phrase phrase77 = new Phrase("2ws", normalFont);
    Phrase phrase78 = new Phrase("78900", normalFont);
    Phrase phrase79 = new Phrase("opoppp", normalFont);
    Phrase phrase80 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase77, 310, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase78, 352, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase79, 450, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase80, 536, i - 110, 0);

    PdfPTable table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    PdfPCell cell = new PdfPCell();
    cell.setPadding(127);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(6);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 7, 7, 20, 7, 7, 3 });
    cell = new PdfPCell();
    cell.setPadding(14);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(2);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 15.5f, 20 });
    cell = new PdfPCell();
    cell.setPadding(14);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(100);
    table.setWidths(new float[] { 23.5f, 2, 5, 6, 4, 7, 3 });
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(j * 8 - 2279);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(17);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(5);
    table.setWidths(new float[] { 10.5f, 4, 6, 4 });
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(48);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    document.close();

    HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
    response.setContentType("application/pdf");
    response.addHeader("Content-disposition",
            "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\"");

    ServletOutputStream os = response.getOutputStream();
    os.write(bytesOS.toByteArray());
    os.flush();
    os.close();

    facesContext.responseComplete();
}

From source file:it.vige.magazzino.pdf.Format2DocumentReceipt.java

License:Apache License

@Model
public void build(Receipt receipt) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("messages");

    Document document = new Document();
    ByteArrayOutputStream bytesOS = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, bytesOS);

    document.open();// ww w  .  j a  v a  2 s. c  o  m

    Font normalFont = new Font();

    PdfContentByte canvas = writer.getDirectContentUnder();
    List<Data> imagesJar = receipt.getJar().getFiles();

    if (imagesJar != null && imagesJar.size() > 0) {
        Image image1 = Image.getInstance(imagesJar.get(0).getData());
        image1.setAbsolutePosition(36, 742);
        image1.scalePercent(60);
        document.add(image1);
    }

    Phrase phrase1 = new Phrase(bundle.getString("pdf_number_receipt"), normalFont);
    Phrase phrase2 = new Phrase(receipt.getCodeReceipt() + "", normalFont);
    Phrase phrase3 = new Phrase(bundle.getString("receipt_date"), normalFont);
    Phrase phrase4 = new Phrase(receipt.getDate(), normalFont);
    Phrase phrase5 = new Phrase(receipt.getCause(), normalFont);
    Phrase phrase6 = new Phrase(receipt.getDescription(), normalFont);
    Phrase phrase7 = new Phrase(bundle.getString("customer_code") + " " + bundle.getString("customer"),
            normalFont);
    Phrase phrase8 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 286, 797, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 386, 797, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 286, 777, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 386, 777, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 286, 757, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 386, 757, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 286, 737, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 386, 737, 0);

    Phrase phrase9 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase10 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase11 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase12 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase13 = new Phrase(bundle.getString("pdf_tel"), normalFont);
    Phrase phrase14 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase15 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont);
    Phrase phrase16 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 718, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 136, 718, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 698, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 136, 698, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 678, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 136, 678, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 658, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 136, 658, 0);

    Phrase phrase17 = new Phrase("Ditta", normalFont);
    Phrase phrase18 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase19 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase20 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase21 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont);
    Phrase phrase23 = new Phrase("prova 2: ", normalFont);
    Phrase phrase24 = new Phrase(bundle.getString("pdf_cod_fisc"), normalFont);
    Phrase phrase25 = new Phrase("prova 2: ", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 236, 736, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 236, 708, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 236, 688, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 236, 668, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 386, 668, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 236, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 286, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 356, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 416, 648, 0);

    Phrase phrase26 = new Phrase(bundle.getString("article_code"), normalFont);
    Phrase phrase27 = new Phrase(bundle.getString("article_description"), normalFont);
    Phrase phrase28 = new Phrase(bundle.getString("pdf_number_articles"), normalFont);
    Phrase phrase29 = new Phrase(bundle.getString("article_prize"), normalFont);
    Phrase phrase30 = new Phrase(bundle.getString("pdf_reduction"), normalFont);
    Phrase phrase31 = new Phrase(bundle.getString("pdf_amount"), normalFont);
    Phrase phrase32 = new Phrase(bundle.getString("pdf_iva"), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase26, 59, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase27, 146, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase28, 208, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase29, 280, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase30, 353, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase31, 422, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase32, 498, 618, 0);

    Phrase phrase33 = null;
    Phrase phrase34 = null;
    Phrase phrase35 = null;
    Phrase phrase36 = null;
    Phrase phrase37 = null;
    Phrase phrase38 = null;
    Phrase phrase39 = null;

    int i = 0;
    for (i = 0; i < 70; i = i + 15) {
        phrase33 = new Phrase("dsadasd", normalFont);
        phrase34 = new Phrase("dgbsbb", normalFont);
        phrase35 = new Phrase("323232", normalFont);
        phrase36 = new Phrase("bbgdbdfbdb", normalFont);
        phrase37 = new Phrase("wefwew", normalFont);
        phrase38 = new Phrase("ewrew", normalFont);
        phrase39 = new Phrase("ewr5", normalFont);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 59, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 136, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 196, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 266, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase37, 351, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase38, 416, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase39, 496, 598 - i, 0);
    }
    int j = 298;
    if (i - 298 < 0)
        i = 298;
    else {
        j = i;
        i = 588 - i;
    }
    Phrase phrase40 = new Phrase(bundle.getString("pdf_references").toUpperCase(), normalFont);
    Phrase phrase41 = new Phrase(bundle.getString("pdf_delivery").toUpperCase(), normalFont);
    Phrase phrase42 = new Phrase(bundle.getString("pdf_payments").toUpperCase(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase40, 105, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase41, 206, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase42, 316, i, 0);

    Phrase phrase43 = new Phrase("opoppp", normalFont);
    Phrase phrase44 = new Phrase("2ws", normalFont);
    Phrase phrase45 = new Phrase("78900", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 59, i - 20, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 186, i - 20, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase45, 276, i - 20, 0);

    Phrase phrase46 = new Phrase(bundle.getString("pdf_sign_producer").toUpperCase(), normalFont);
    Phrase phrase47 = new Phrase(bundle.getString("pdf_sign_receiver").toUpperCase(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase46, 154, i - 40, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase47, 321, i - 40, 0);

    Phrase phrase48 = new Phrase(bundle.getString("article_imponible"), normalFont);
    Phrase phrase49 = new Phrase("opoppp", normalFont);
    Phrase phrase50 = new Phrase(bundle.getString("pdf_tax"), normalFont);
    Phrase phrase51 = new Phrase("78900", normalFont);
    Phrase phrase52 = new Phrase(bundle.getString("pdf_total_receipt"), normalFont);
    Phrase phrase53 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 356, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase49, 566, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 356, i - 25, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase51, 566, i - 25, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 356, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase53, 566, i - 50, 0);

    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    PdfPCell cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(3);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 38, 48, 14 });
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(40);
    table.addCell(cell);
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(j * 8 - 2234);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(5);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 20, 20, 20, 20, 20 });
    cell = new PdfPCell();
    cell.setPadding(20);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 30, 30, 20, 20 });
    cell = new PdfPCell();
    cell.setPadding(20);
    table.addCell(cell);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    document.close();

    HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
    response.setContentType("application/pdf");
    response.addHeader("Content-disposition",
            "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\"");

    ServletOutputStream os = response.getOutputStream();
    os.write(bytesOS.toByteArray());
    os.flush();
    os.close();

    facesContext.responseComplete();
}

From source file:jdbreport.model.io.pdf.itext5.ITextWriter.java

License:Apache License

protected int toPdfHAlignment(int horizontalAlignment) {
    switch (horizontalAlignment) {
    case CellStyle.LEFT:
        return Element.ALIGN_LEFT;
    case CellStyle.RIGHT:
        return Element.ALIGN_RIGHT;
    case CellStyle.CENTER:
        return Element.ALIGN_CENTER;
    case CellStyle.JUSTIFY:
        return Element.ALIGN_JUSTIFIED;
    }// w w  w.  ja va  2  s .c  o m
    return Element.ALIGN_LEFT;
}

From source file:ke.co.tawi.babblesms.server.utils.export.PdfUtil.java

License:Open Source License

/**
 * Adds the header and the footer./*from   w  w  w  .j a  v  a  2s. com*/
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");
    switch (writer.getPageNumber() % 1) {

    case 0:
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, header[0], rect.getRight(),
                rect.getTop(), 0);
        break;
    case 1:
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, header[1], rect.getLeft(),
                rect.getTop(), 0);
        break;
    }
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase(String.format("page %d", pagenumber)), (rect.getLeft() + rect.getRight()) / 2,
            rect.getBottom() - 18, 0);
}

From source file:Logic.DocsCreation.java

public void createPdfDoc(JTable Table, GetPatientData data, StartDB con, boolean flag,
        ArrayList<String> arrPatient, String crb) {
    try {//  www . j  a  v  a  2 s  .co  m
        norm.getNorm(con.getConnection());
        int b = arrPatient.size();
        if (b == -1) {
            return;
        }
        String path = System.getProperty("user.home");
        path = path + "//Desktop//";
        File theDir = new File(path, "???");
        // if the directory does not exist, create it
        if (!theDir.exists()) {

            boolean result = false;

            try {
                theDir.mkdir();
                result = true;
            } catch (SecurityException se) {
                //handle it
            }
            if (result) {
                System.out.println("DIR created");
            }
        }
        for (int k = 0; k < b; k++) {
            String id = arrPatient.get(k);//Table.getModel().getValueAt(k, 0).toString(); 
            data = new GetPatientData();
            data.getMainData(con.getConnection(), id, crb);
            data.getPatientDocs(con.getConnection(), id);
            String[] arr = null;
            String fname = data.getName().replaceAll(" ", "") + data.getBirth();

            Document doc = new Document();
            String fileName = path + "\\???\\" + fname + ".pdf";
            String pdfName = "";
            FileOutputStream fos = new FileOutputStream(fileName);
            PdfWriter.getInstance(doc, fos);
            doc.open();

            BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\ARIAL.TTF", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            BaseFont bfn = BaseFont.createFont("C:\\Windows\\Fonts\\ARIALI.TTF", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            // 
            Paragraph title = new Paragraph(data.getCrbName() + "\n", new Font(bf, 16, Font.BOLD));
            title.setAlignment(Element.ALIGN_CENTER);
            doc.add(title);
            // ? 
            Paragraph lpu = new Paragraph("?   " + data.getLpu(), new Font(bf, 12));
            lpu.setAlignment(Element.ALIGN_RIGHT);
            doc.add(lpu);
            doc.add(new Phrase(
                    "____________________________________________________________________________________\n",
                    new Font(bf, 11, Font.BOLD)));

            doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getName() + " (" + data.getSex() + ")\n", new Font(bf, 13)));
            doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getBirth() + "\n", new Font(bf, 13)));
            doc.add(new Phrase(" ? ??: ",
                    new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getDate() + "\n", new Font(bf, 13)));

            if (data.getSnils() != null) {
                doc.add(new Phrase("? : ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getSnils() + "\n", new Font(bf, 13)));
            }
            if (data.getDocs() != null) {
                doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getDocs() + " ", new Font(bf, 13)));
                ;
            }
            if (data.getPolicy() != null) {
                doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getPolicy() + "; ", new Font(bf, 13)));
            }

            if (data.getPhone() != null) {
                doc.add(new Phrase("?  ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getPhone() + "; ", new Font(bf, 13)));
            }
            //  ?

            data.getDoneServiceCount(con.getConnection(), id);
            data.getDoneServiceData(con.getConnection(), id);
            // data.getDoneServiceProp(con.getConnection(), id,data.getService_code().get(k));
            //  ?
            doc.add(new Paragraph("\n ?: \n", new Font(bf, 16, Font.BOLD)));

            for (int i = 0; i < data.getCount(); i++) {
                data.getDoneServiceProp(con.getConnection(), id, data.getService_code().get(i));
                doc.add(new Phrase(data.getService_name().get(i) + " : \n", new Font(bf, 12, Font.BOLD)));
                if (data.getService_result().get(i) != null) {
                    arr = data.getService_result().get(i).split(";");

                    for (int l = 0; l < norm.getCode().size(); l++) {
                        if (data.getService_code().get(i).equals(norm.getCode().get(l))) {
                            flagExistNorm = true;
                            if ("".equals(data.getSex()))
                                arrNorm = norm.getNormsWoman().get(l).split(";");
                            else if ("".equals(data.getSex())) {
                                arrNorm = norm.getNormsMan().get(l).split(";");
                            }

                            break;
                        } else
                            flagExistNorm = false;
                    }

                    //<editor-fold defaultstate="collapsed" desc="?? ?? ">
                    //                switch(data.getService_name().get(i)){            
                    //                    
                    //                    case "01.?()":
                    //                    doc.add(new Phrase("  ? - " +arr[0]+ " ;\n " ,new Font(bf, 12)));
                    //                    break;
                    //                    
                    //                    case "02.??":                 
                    //                        doc.add(new Phrase("? - " + arr[0] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[2] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("?  - " + arr[1] +" ;\n ",new Font(bf, 12)));               
                    //                        break; 
                    //
                    //                    case "03.  ?":                 
                    //                        doc.add(new Phrase("   - " + arr[0] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("?   - " + arr[1] +" ;",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[2] +" ;\n ",new Font(bf, 12)));
                    //                        break; 
                    //
                    //                     case "06.?  " :                 
                    //                            
                    //                     {   
                    //                            doc.add(new Phrase("  " +";\n ",new Font(bf, 12)));
                    //                            pdfName = "C:\\MDKTemp\\"+fname+"ECG.pdf";
                    //                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                    //                            targetFile.write(data.getPDFData(con.getConnection(), id));
                    //                            targetFile.close();
                    //                            log.info("pdf  ? "+id+ "?");
                    //                            } catch (Exception ex) {
                    //                                    log.error(ex, ex);                            
                    //                            }
                    //                        }
                    //                     break;         
                    //
                    //                     case "08.? ":                 
                    //                        doc.add(new Phrase(" ?? - " + arr[0] +" ;\n",new Font(bf, 12)));               
                    //                        break; 
                    //
                    //                     case "13.  ":                 
                    //                        doc.add(new Phrase("\n (), / - " + arr[0] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", /- " + arr[1] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", / - " + arr[2] +" - \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (),-/ - " + arr[3] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (), -/ - " + arr[4] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? ? - " + arr[5] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("pH - " + arr[6] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", / - " + arr[7] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("??? ?, / - " + arr[8] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[9] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (), / - " + arr[10] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" - " + arr[11] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[12] +" ;\n",new Font(bf, 12)));
                    //                        break; 
                    //
                    //                        case "16.  ?":                 
                    //                        doc.add(new Phrase(" - " + arr[0] +" ;",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" - " + arr[1] +" ;",new Font(bf, 12)));                
                    //                        break;
                    //                    } 
                    //</editor-fold>    
                    //            
                    int arrSize = arr.length;
                    for (int j = 0; (j < arrSize); j++) {

                        if (data.getService_name().get(i).contains("?")
                                || data.getService_name().get(i).contains("")) {
                            doc.add(new Phrase("  " + ";\n ", new Font(bf, 12)));
                            pdfName = "C:\\MDKTemp\\" + fname + "ECG.pdf";
                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                                targetFile.write(data.getPDFData(con.getConnection(), id));
                                targetFile.close();
                                log.info("pdf  ? " + id + "?");

                                break;
                            } catch (Exception ex) {
                                log.error(ex, ex);
                            }
                        }
                        if (flagExistNorm) {
                            String[] border;
                            border = new String[2];

                            border = arrNorm[j].split(" - ");
                            if (Float.parseFloat(arr[j]) >= Float.parseFloat(border[0])) {
                                if (Float.parseFloat(arr[j]) <= Float.parseFloat(border[1])) {
                                    //   ?

                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                            new Font(bf, 12)));
                                } else {
                                    //    
                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                            new Font(bf, 12, Font.UNDERLINE)));
                                    if (border[0].equals(border[1])) {
                                        doc.add(new Phrase("! (? " + border[0] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                    } else
                                        doc.add(new Phrase(
                                                "! (? " + border[0] + " - " + border[1] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                }
                            } else {
                                //    
                                doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                        new Font(bf, 12, Font.UNDERLINE)));
                                if (border[0].equals(border[1])) {
                                    doc.add(new Phrase("! (? " + border[0] + ");\n",
                                            new Font(bfn, 12, Font.UNDERLINE)));
                                } else
                                    doc.add(new Phrase(
                                            "! (? " + border[0] + " - " + border[1] + ");\n",
                                            new Font(bfn, 12, Font.UNDERLINE)));
                            }
                        } else
                            doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                    new Font(bf, 12)));

                    }

                }
            }
            //  ?
            data.getAppoitedServiceCount(con.getConnection(), id);
            data.getAppServiceData(con.getConnection(), id);
            doc.add(new Phrase("? ? :\n", new Font(bf, 16, Font.BOLD)));
            for (int j = 0; j < data.getCount(); j++) {
                if (data.getService_result().get(j) != null) {
                    doc.add(new Phrase(data.getService_name().get(j) + " - ", new Font(bf, 12, Font.BOLD)));
                    doc.add(new Phrase(data.getService_result().get(j) + " ; ", new Font(bf, 12)));
                }
                if (data.getService_result().get(j) == null) {
                    doc.add(new Phrase(data.getService_name().get(j) + " ; ", new Font(bf, 12, Font.BOLD)));
                }
            }
            // 
            data.getRenServiceCount(con.getConnection(), id);
            data.getRenServiceData(con.getConnection(), id);
            doc.add(new Phrase("\n : ", new Font(bf, 16, Font.BOLD)));
            for (int i = 0; i < data.getCount(); i++) {
                if (data.getService_name().get(i) == null) {
                    doc.add(new Phrase("? ", new Font(bf, 12)));
                }
                doc.add(new Phrase(data.getService_name().get(i) + " ; ", new Font(bf, 12, Font.BOLD)));
            }
            // 
            data.getEarlierServiceCount(con.getConnection(), id);
            data.getEarServiceData(con.getConnection(), id);
            doc.add(new Phrase("\n  : ", new Font(bf, 16, Font.BOLD)));
            for (int i = 0; i < data.getCount(); i++) {
                if (data.getService_result().get(i) != null) {
                    doc.add(new Phrase(data.getService_name().get(i) + " - ", new Font(bf, 12, Font.BOLD)));
                    doc.add(new Phrase(data.getService_date().get(i) + " ; ", new Font(bf, 12)));
                }
                if (data.getService_result().get(i) == null) {
                    doc.add(new Phrase(data.getService_name().get(i) + " ;", new Font(bf, 12)));
                }

            }
            doc.close();
            if (!flag) {
                if (!pdfName.equals("")) {
                    AddCover1 cov = new AddCover1();
                    String tempFile = fileName;
                    String ECGFile = pdfName;
                    String res = path + "//???//" + fname + "ECG.pdf";
                    File file = new File(res);
                    file.getParentFile().mkdirs();
                    cov.manipulatePdf(ECGFile, res, tempFile);
                    File dfile = new File(fileName);
                    if (dfile.delete()) {
                        System.out.println(dfile.getName() + " is deleted!");
                    } else {
                        System.out.println("Delete operation is failed.");
                    }

                }
            }

            if (flag) {
                if (!pdfName.equals("")) {
                    AddCover1 cov = new AddCover1();
                    String tempFile = fileName;
                    String ECGFile = pdfName;
                    String res = "C:\\" + fname + "ECG.pdf";
                    File file = new File(res);
                    file.getParentFile().mkdirs();
                    cov.manipulatePdf(ECGFile, res, tempFile);
                    File dfile = new File(fileName);
                    if (dfile.delete()) {
                        System.out.println(dfile.getName() + " is deleted!");
                    } else {
                        System.out.println("Delete operation is failed.");
                    }

                    File pfile = new File(res);
                    try {
                        Desktop.getDesktop().print(pfile);
                        Thread.sleep(2000);
                    } catch (IOException ex) {
                        log.error(ex, ex);
                    }
                } else {
                    File pfile = new File(fileName);
                    try {
                        Desktop.getDesktop().print(pfile);
                        Thread.sleep(2000);
                    } catch (IOException ex) {
                        log.error(ex, ex);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e, e);
    }

}

From source file:ManagementPackage.ServiceEnd.java

private void txtDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoneActionPerformed
    // TODO add your handling code here:
    Document doc = new Document();
    try {//  www . j a  va 2s .  co m
        long time = new Date().getTime();
        TransNo = "" + time;
        PdfWriter.getInstance(doc, new FileOutputStream("Invoices\\Invoices" + time + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(4);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Invoice/Money Receipt\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell3 = new PdfPCell(new Paragraph("Transaction No: " + time, FontFactory.getFont(null, 10)));
        cell3.setColspan(2);
        cell3.setPaddingBottom(10);
        cell3.setPaddingTop(10);
        cell3.setBorder(2);
        cell3.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell3);

        PdfPCell cell4 = new PdfPCell(
                new Paragraph("Date: " + formatedDateTime, FontFactory.getFont(null, 10)));
        cell4.setColspan(3);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        //table.addCell("Sl No");
        table.addCell("Product Name");
        table.addCell("Rate");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String query = "select product_name, rate, qty, amount from temp_trans WHERE trans_by = '" + user + "'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                //String sl_no = rs.getString("sl_no");
                String product_name = rs.getString("product_name");
                String rate = rs.getString("rate");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");

                //table.addCell(sl_no);
                table.addCell(product_name);
                table.addCell(rate);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);
            }
            rs.close();
            pst.close();

        } catch (SQLException ex) {
            Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
        }

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph(txtTotal.getText()));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph(txtAdjust.getText()));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Billed By: " + user));
        celltxtTotalPaid.setColspan(2);
        //celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid0 = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid0.setColspan(1);
        celltxtTotalPaid0.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid0);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph(txtTotalPaid.getText()));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        savePermanently();
        clearTempTable();
        //JOptionPane.showMessageDialog(null, "Report Created!");

        // open PDF file
        File file = new File("Invoices\\Invoices" + time + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

    } catch (DocumentException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ManagementPackage.Setting.java

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    // TODO add your handling code here:
    totalAdjustment = 0;/*from   www. j  a va2s .com*/
    totalTotalPaid = 0;
    total = 0;

    Document doc = new Document();
    try {
        long time = new Date().getTime();
        PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Daily" + time + " " + formatedDate + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(5);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Daily Report\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime));
        cell4.setColspan(10);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        table.addCell("Transaction No");
        table.addCell("Billed By");
        table.addCell("Product Name");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String PrevTransNo = " ";
        String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date = '"
                + formatedDate + "'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                String NewTransNo = rs.getString("trans_no");
                String product_name = rs.getString("product_name");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");
                String trans_by = rs.getString("trans_by");

                total = total + Float.parseFloat(amount);

                if (PrevTransNo.equals(NewTransNo))
                    table.addCell(" ");
                else {
                    table.addCell(NewTransNo);
                    String query1 = "select adjustment, total_paid from paid_amount where trans_no = '"
                            + NewTransNo + "'";
                    pst1 = con1.prepareStatement(query1);
                    rs1 = pst1.executeQuery();
                    String adjustment = rs1.getString("adjustment");
                    String total_paid = rs1.getString("total_paid");

                    totalAdjustment = totalAdjustment + Float.parseFloat(adjustment);
                    totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid);

                    rs1.close();
                    pst1.close();
                }

                PrevTransNo = rs.getString("trans_no");
                table.addCell(trans_by);
                table.addCell(product_name);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);

            }
            rs.close();
            pst.close();

        } catch (SQLException ex) {
            Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
        }

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid.setColspan(3);
        celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        //JOptionPane.showMessageDialog(null, "Report Created!");
        // open PDF file
        File file = new File("Reports\\Daily" + time + " " + formatedDate + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

    } catch (DocumentException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ManagementPackage.Setting.java

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed

    // TODO add your handling code here:
    totalAdjustment = 0;/*from  w  w  w . j av  a2  s.co m*/
    totalTotalPaid = 0;
    total = 0;

    Document doc = new Document();
    try {
        long time = new Date().getTime();
        PdfWriter.getInstance(doc,
                new FileOutputStream("Reports\\Monthly" + time + " " + formatedDate + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(5);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Monthly Report\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime));
        cell4.setColspan(10);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        table.addCell("Transaction No");
        table.addCell("Billed By");
        table.addCell("Product Name");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String PrevTransNo = " ";
        String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%"
                + month + "%'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                String NewTransNo = rs.getString("trans_no");
                String product_name = rs.getString("product_name");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");
                String trans_by = rs.getString("trans_by");

                total = total + Float.parseFloat(amount);

                if (PrevTransNo.equals(NewTransNo))
                    table.addCell(" ");
                else {
                    table.addCell(NewTransNo);
                    String query1 = "select adjustment, total_paid from paid_amount where trans_no = '"
                            + NewTransNo + "'";
                    pst1 = con1.prepareStatement(query1);
                    rs1 = pst1.executeQuery();
                    String adjustment = rs1.getString("adjustment");
                    String total_paid = rs1.getString("total_paid");

                    totalAdjustment = totalAdjustment + Float.parseFloat(adjustment);
                    totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid);

                    rs1.close();
                    pst1.close();
                }

                PrevTransNo = rs.getString("trans_no");
                table.addCell(trans_by);
                table.addCell(product_name);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);

            }
            rs.close();
            pst.close();

        } catch (SQLException ex) {
            Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
        }

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid.setColspan(3);
        celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        //JOptionPane.showMessageDialog(null, "Report Created!");
        // open PDF file
        File file = new File("Reports\\Monthly" + time + " " + formatedDate + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

    } catch (DocumentException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ManagementPackage.Setting.java

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed

    // TODO add your handling code here:
    totalAdjustment = 0;/*w  ww . j  a va  2 s.co  m*/
    totalTotalPaid = 0;
    total = 0;

    Document doc = new Document();
    try {
        long time = new Date().getTime();
        PdfWriter.getInstance(doc,
                new FileOutputStream("Reports\\Yearly" + time + " " + formatedDate + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(5);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Yearly Report\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime));
        cell4.setColspan(10);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        table.addCell("Transaction No");
        table.addCell("Billed By");
        table.addCell("Product Name");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String PrevTransNo = " ";
        String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%"
                + year + "%'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                String NewTransNo = rs.getString("trans_no");
                String product_name = rs.getString("product_name");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");
                String trans_by = rs.getString("trans_by");

                total = total + Float.parseFloat(amount);

                if (PrevTransNo.equals(NewTransNo))
                    table.addCell(" ");
                else {
                    table.addCell(NewTransNo);
                    String query1 = "select adjustment, total_paid from paid_amount where trans_no = '"
                            + NewTransNo + "'";
                    pst1 = con1.prepareStatement(query1);
                    rs1 = pst1.executeQuery();
                    String adjustment = rs1.getString("adjustment");
                    String total_paid = rs1.getString("total_paid");

                    totalAdjustment = totalAdjustment + Float.parseFloat(adjustment);
                    totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid);

                    rs1.close();
                    pst1.close();
                }

                PrevTransNo = rs.getString("trans_no");
                table.addCell(trans_by);
                table.addCell(product_name);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);

            }
            rs.close();
            pst.close();

        } catch (SQLException ex) {
            Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
        }

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid.setColspan(3);
        celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        //JOptionPane.showMessageDialog(null, "Report Created!");
        // open PDF file
        File file = new File("Reports\\Yearly" + time + " " + formatedDate + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

    } catch (DocumentException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Model.GerarRelatorio.java

public void dateHeader() {
    Font fonte = new Font(FontFamily.TIMES_ROMAN, 10);
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm");
    toParagraphs(sdf.format(new Date(System.currentTimeMillis())), Element.ALIGN_RIGHT, fonte);
    toParagraphs("\n", Element.ALIGN_LEFT);
    fonte = new Font(FontFamily.TIMES_ROMAN, 15, Font.BOLD);
    toParagraphs("Santos Engenharia", Element.ALIGN_LEFT, fonte);
    toParagraphs("\n", Element.ALIGN_CENTER);
    fonte = new Font(FontFamily.TIMES_ROMAN, 15);
    toParagraphs(relatorio.getNmRelatorio(), Element.ALIGN_CENTER, fonte);
    toParagraphs("\n", Element.ALIGN_CENTER);
    sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
    toParagraphs("Data: " + (sdf.format(new Date(System.currentTimeMillis()))), Element.ALIGN_LEFT);

}