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:Tables.Printer.java

public void footer(Document doc) throws DocumentException {
    Paragraph paragraph = new Paragraph("Njieforbi Bakery,   Cameroon Buea");
    doc.add(paragraph);/*  ww w .  j av a  2s. c om*/
    dNow = new Date();

    String prodDate = "Created on the " + datOnly.format(dNow) + " at " + timOnly.format(dNow);

    //////////////////

    PdfPTable timeOfProduction = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(prodDate.trim(), smallFooter));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setColspan(3);
    cell.setBorder(0);
    if (prodDate.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    timeOfProduction.addCell(cell);
    doc.add(timeOfProduction);

    Dialogs.create().title("Printing Complete").masthead("Printing process complete.")
            .message("Patient while the file open to see your printout.").showInformation();

}

From source file:Tables.PrinterClass.java

public void footer(Document doc) throws DocumentException {
    Paragraph paragraph = new Paragraph("@" + this.companyName);
    doc.add(paragraph);//from   www .ja  v a  2  s.  co m
    dNow = new Date();

    String prodDate;
    prodDate = "Created on the " + dateOnly.format(dNow) + " at " + timeOnly.format(dNow);

    //////////////////

    PdfPTable timeOfProduction = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(prodDate.trim(), smallFooter));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setColspan(3);
    cell.setBorder(0);
    if (prodDate.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    timeOfProduction.addCell(cell);
    doc.add(timeOfProduction);

    try {
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(20f, 20f);

        img.setAbsolutePosition((PageSize.A4.getWidth() - img.getScaledWidth()),
                (PageSize.A4.getHeight() - img.getScaledHeight())); //place the image at the bottom right position

        img.setAlt("Unity Systems");
    } catch (Exception ex) {

    }

}

From source file:util.ImageExample.java

public ImageExample(Calendar date, int settings, ArrayList<String> courses, String time, String eventAddress,
        int totalPrice, String comments, boolean kunde) throws Exception {
    this.date = date;
    this.settings = settings;
    this.courses = courses;
    this.time = time;
    this.eventAddress = eventAddress;
    this.totalPrice = totalPrice;
    this.comments = comments;
    this.fileName = "";
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();//  w ww. j a  va  2  s . c om
    FontFactory.register("C:/Windows/Fonts/ARLRDBD.TTF", "Arial Rounded");
    Font font = FontFactory.getFont("Arial Rounded", 22, Font.NORMAL, new BaseColor(51, 102, 102));
    Document document = new Document();

    System.out.println("Pdf creation startet");
    try {
        if (kunde) {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + ".pdf";
        } else {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime())
                    + "Prisliste.pdf";
        }

        FileOutputStream file = new FileOutputStream(new File("C:/Users/Mark/Desktop", fileName));
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();

        Image img = Image.getInstance("src/pictures/cirkles.png");
        img.scaleToFit(277, 277);
        img.setAbsolutePosition(40, PageSize.A4.getHeight() - img.getHeight());
        document.add(img);
        Chunk chunk = new Chunk("Grillmester 'Frankie'", font);
        chunk.setCharacterSpacing(3);
        Paragraph header = new Paragraph(chunk);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setSpacingBefore(15);
        document.add(header);
        Paragraph title = new Paragraph(
                "Tilbud angende d. " + new SimpleDateFormat("dd. MMMMM yyyy").format(date.getTime()) + ".",
                new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD));
        title.setAlignment(Element.ALIGN_LEFT);
        title.setIndentationLeft(235);
        title.setSpacingBefore(100);
        title.setLeading(17);
        document.add(title);
        Paragraph subtitle = new Paragraph("(Arrangement til " + settings + " personer).",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.ITALIC));
        subtitle.setAlignment(Element.ALIGN_LEFT);
        subtitle.setIndentationLeft(235);
        subtitle.setLeading(17);
        document.add(subtitle);
        Paragraph body = new Paragraph("\n\nDer er aftalt:\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 18));
        body.setAlignment(Element.ALIGN_LEFT);
        body.setIndentationLeft(235);
        body.setLeading(17);
        for (String course : courses) {
            body.add(course + "\n\n");
        }
        body.add("\nServeres klokken " + time + " i " + eventAddress + ".");
        document.add(body);
        Paragraph ending = new Paragraph("\n\n\nPris: " + totalPrice + ",-kr.",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        ending.setAlignment(Element.ALIGN_LEFT);
        ending.setIndentationLeft(235);
        ending.setLeading(17);
        document.add(ending);
        if (!comments.equals("null")) {
            if (!comments.equals("")) {
                Paragraph comment = new Paragraph("\n\nKommentarer\n" + comments,
                        new Font(Font.FontFamily.TIMES_ROMAN, 18));
                comment.setAlignment(Element.ALIGN_LEFT);
                comment.setIndentationLeft(235);
                comment.setLeading(17);
                document.add(comment);
            }
        }

        Image footerImg = Image.getInstance("src/pictures/grillmester.png");
        footerImg.scaleToFit(210, 210);
        footerImg.setAbsolutePosition(40, 40);
        document.add(footerImg);

        Image img2 = Image.getInstance("src/pictures/Contact.png");
        img2.scaleToFit(250, 250);
        img2.setAbsolutePosition(20, PageSize.A4.getHeight() - img.getHeight() - 250);
        document.add(img2);

        document.close();

        System.out.println("Pdf finish");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getLocalizedMessage());
    }
}

From source file:utilities.itext.Turnover.java

private static Paragraph createTablesWithoutDetails(HashMap<String, BigDecimal> expenseData)
        throws DocumentException {
    Paragraph paragraph = new Paragraph();

    PdfPTable expense = new PdfPTable(2);
    float[] colWidths = { 1f, 3f };
    expense.setWidths(colWidths);//ww w  .ja va 2s  .  c o m

    for (String cat : expenseData.keySet()) {
        Paragraph contentCell1 = new Paragraph(cat);
        PdfPCell cell1 = new PdfPCell(contentCell1);

        Paragraph contentCell2 = new Paragraph(formatter.format(expenseData.get(cat)));
        PdfPCell cell2 = new PdfPCell(contentCell2);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell1.setPaddingBottom(4f);
        cell2.setPaddingBottom(4f);

        expense.addCell(cell1);
        expense.addCell(cell2);
    }

    paragraph.add(expense);
    return paragraph;
}

From source file:Utility.PDFDemo.java

public PdfPTable reports() {
    //specify column widths
    float[] columnWidths = { .2f, .2f, .2f, .2f, .2f, .2f };

    //create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    //PdfPTable table = new PdfPTable(10);

    // set table width a percentage of the page width
    table.setWidthPercentage(100f);/*  ww  w . j av a2s.  c  om*/

    try {

        /*
                
         IT REPORT GENERATION BLOCK
                
         */
        //insert column headings
        insertCell(table, "Farmer Name", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Replante Date", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Treated farms", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "District", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Number of Trees Cut", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Farmer Number ", Element.ALIGN_CENTER, 1, bfBold8);
        //insertCell(table, "Farm size Replanted", Element.ALIGN_CENTER, 1, bfBold8);

        table.setHeaderRows(1);

        ResultSet rs = manager.PDFdemos();
        int Tresscut = 0;
        float allFarmSize = 0;

        //Populating Feilds            
        while (rs.next()) {

            insertCell(table, rs.getString(3), Element.ALIGN_RIGHT, 1, bf8);
            insertCell(table, rs.getString(4), Element.ALIGN_LEFT, 1, bf8);
            insertCell(table, rs.getFloat(2) + "", Element.ALIGN_RIGHT, 1, bf8);
            insertCell(table, rs.getString(6), Element.ALIGN_LEFT, 1, bf8);
            insertCell(table, rs.getInt(5) + "", Element.ALIGN_RIGHT, 1, bf8);
            insertCell(table, rs.getString(1), Element.ALIGN_LEFT, 1, bf8);
            //insertCell(table, rs.getString(7) + "", Element.ALIGN_RIGHT, 1, bf8);

            allFarmSize += rs.getFloat(2);
            Tresscut += rs.getInt(5);
        }

        insertCell(table, "TOTAL FARMS TREATED:         " + manager.totalReports(), Element.ALIGN_CENTER, 2,
                bfBold12);
        insertCell(table, "Total Treated Farm Size:       " + String.format("%.2f", allFarmSize),
                Element.ALIGN_CENTER, 2, bfBold8);
        insertCell(table, "Total Treescut:    " + Tresscut + "", Element.ALIGN_CENTER, 2, bfBold8);
        //insertCell(table, "        ", Element.ALIGN_CENTER, 3, bfBold8);
        //insertCell(table, "         ", Element.ALIGN_CENTER, 1, bfBold8);
        //insertCell(table, "          ", Element.ALIGN_CENTER, 1, bfBold8);
        //insertCell(table,  "Total Treated Farm Size:       "+String.format("%.2f", allFarmSize), Element.ALIGN_CENTER, 1, bfBold8);

    } //Try ends here
    catch (SQLException ex) {
        Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
    }

    return table;
}

From source file:Utility.PDFDemo.java

public void cretePDF(String name, String rpor) throws FileNotFoundException {

    try {//from  w w  w . j  av  a2  s  .c  om

        //Create document for pdf
        Document doc = new Document();

        //PDF writer to write into document
        PdfWriter docwriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {
            // //file path
            //String path = "docs/" + name;
            docwriter = PdfWriter.getInstance(doc, new FileOutputStream(rpor + ".pdf"));
        } catch (DocumentException ex) {
            Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
        }

        //document header attributes
        doc.addAuthor("CHED CU");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Grant Monitor");
        doc.addTitle(rpor);
        doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
        //doc.setPageSize(PageSize.A4);
        doc.setMargins(30f, 30f, 20f, 20f);

        //open document
        doc.open();

        //Creating a paragraphs and chunks
        Paragraph pp = new Paragraph("Cocoa Health And Extension", forTitle);
        pp.setAlignment(Element.ALIGN_CENTER);

        Paragraph palaglapgh = new Paragraph("(Cocobod)", bfBold12);
        palaglapgh.setAlignment(Element.ALIGN_CENTER);

        Chunk chk = new Chunk("From GIS Office, Accra", bfBold12);
        chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
        Paragraph underText = new Paragraph(chk);
        underText.setAlignment(Element.ALIGN_CENTER);

        Chunk chuk1 = new Chunk("Lot No:", bfBold12);
        chuk1.setUnderline(.1f, -2f);
        Chunk chuk2 = new Chunk(name, bfBold12);

        Paragraph regionText = new Paragraph(rpor, bfBold12);
        regionText.setAlignment(Element.ALIGN_CENTER);
        String rporx = "";
        //            ResultSet dir = manager.PDFdemos(name);
        //            try {
        //                if (dir.next()) {
        //                    rporx = dir.getString(12);
        //
        //                }
        //            } catch (SQLException ex) {
        //                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
        //            }

        Paragraph regionTexts = new Paragraph(rporx, bfBold12);
        regionText.setAlignment(Element.ALIGN_CENTER);
        //add the PDF table to the paragraph
        //palaglapgh.add(table);
        //Table Generation block
        regionText.add(reports());

        //SECTION TO ADD ELEMENTS TO PDF
        // add the paragraph to the document
        doc.add(pp);
        //doc.add(Chunk.NEWLINE);       //Adds a new blank line
        doc.add(palaglapgh);
        doc.add(underText);

        doc.add(chuk1);
        doc.add(chuk2);

        //Current Date and time insertion
        Paragraph newDate = new Paragraph(new Date().toString(), bf12);
        newDate.setAlignment(Element.ALIGN_RIGHT);
        doc.add(newDate);
        doc.add(regionTexts);
        doc.add(regionText);

        //close the document
        doc.close();

        //close the writer
        docwriter.close();

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

}

From source file:utils.PrintInvoice.java

public void getDocument() {
    try {/*ww  w  .  j  a v a2s  .c om*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("SaleBill#" + salebill.getId() + ".pdf"));

        document.open();
        ////////////////////////////////////////////////////////////////////////////////////
        ///////////////////Start Document Here/////////////////////////////////
        PdfContentByte directContent = writer.getDirectContent();
        Paragraph p1 = new Paragraph("SALE BILL");
        p1.setFont(FONT[4]);
        p1.setAlignment(Element.ALIGN_CENTER);

        document.add(p1);
        //show the company details here.
        Phrase company = new Phrase(new Chunk("BIO PHARMA\nAKOT 444101(M.S)", FONT[3]));
        document.add(company);
        document.add(new Phrase(
                "\nLicense No : 20B : AK-88888\n                     21B : AK-88889\n       Mobile : "
                        + SessionClass.getInstance().getMobileNumber(),
                FONT[2]));

        //            Phrase mobNum  = new Phrase("    Mobile : "+SessionClass.getInstance().getMobileNumber() );
        //            mobNum.setFont(FONT[2]);
        //            ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, mobNum, 35, 710, 0);

        System.out.println(dateFormatter.format(salebill.getBillDate()));
        //show the invoice details
        //  String txt = "Bill No. : " + salebill.getId()+"\nBill Date : " + dateFormatter.format(salebill.getBillDate()) +;
        Phrase invoiceDetails = new Phrase("Bill No. : " + salebill.getId());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 693, 0);
        invoiceDetails = new Phrase("Bill Date : " + dateFormatter2.format(salebill.getBillDate()));
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 681, 0);
        invoiceDetails = new Phrase("Mode of Payment : " + salebill.getMode());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 668, 0);

        //show the customer details
        Customer c = salebill.getCustomerId();
        Phrase custDetails = new Phrase("SOLD TO", FONT[3]);
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 693, 0);
        custDetails = new Phrase(c.getCompanyName());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 681, 0);
        custDetails = new Phrase(c.getSiteAddress());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 668, 0);
        custDetails = new Phrase("Licence : " + c.getLicenceNo());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 655, 0);

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        //Item Particulars are shown here
        PdfPTable table = new PdfPTable(7);
        table.setTotalWidth(new float[] { 175, 80, 80, 50, 50, 50, 75 });
        table.setHeaderRows(1);

        //headers
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell("Particulars");
        table.addCell("Batch");
        table.addCell("Expiry");
        table.addCell("MRP");
        table.addCell("Rate");
        table.addCell("Qnty");
        table.addCell("SubTotal");
        table.getDefaultCell().setBackgroundColor(null);
        table.setSpacingAfter(5.0f);

        List<SaleBillPharmaItem> items = salebill.getSaleBillPharmaItemList();
        for (int i = 0; i < items.size(); i++) {
            PdfPCell desc = new PdfPCell(new Phrase(items.get(i).getItemName()));

            table.addCell(desc);

            PdfPCell batch = new PdfPCell(new Phrase(items.get(i).getBatch()));

            table.addCell(batch);

            PdfPCell expiry = null;
            Date tDate = null;
            try {
                tDate = dateFormatter2.parse(items.get(i).getExpDate());
            } catch (ParseException ex) {
                Logger.getLogger(PrintInvoice.class.getName()).log(Level.SEVERE, null, ex);
            }

            expiry = new PdfPCell(new Phrase(dateFormatter.format(tDate)));

            table.addCell(expiry);

            PdfPCell mrp = new PdfPCell(new Phrase(items.get(i).getMrp() + ""));
            //                 //mrp.setBorderColor(BaseColor.WHITE);
            //                 mrp.setBorderColorLeft(BaseColor.BLACK);
            //                 mrp.setBorderColorRight(BaseColor.WHITE);
            table.addCell(mrp);
            PdfPCell rate = new PdfPCell(new Phrase(items.get(i).getItemRate() + ""));
            //                 //rate.setBorderColor(BaseColor.WHITE);
            //                 rate.setBorderColorLeft(BaseColor.BLACK);
            //                 rate.setBorderColorRight(BaseColor.WHITE);
            table.addCell(rate);
            PdfPCell quantity = new PdfPCell(new Phrase(items.get(i).getQnty() + ""));
            //                 //quantity.setBorderColor(BaseColor.WHITE);
            //                 quantity.setBorderColorLeft(BaseColor.BLACK);
            //                 quantity.setBorderColorRight(BaseColor.WHITE);
            table.addCell(quantity);
            PdfPCell subtotal = new PdfPCell(new Phrase(items.get(i).getAmt() + ""));
            //                 //subtotal.setBorderColor(BaseColor.WHITE);
            //                 subtotal.setBorderColorLeft(BaseColor.BLACK);
            //                 subtotal.setBorderColorRight(BaseColor.WHITE);
            table.addCell(subtotal);

        }

        //now show the sub details
        //PdfPCell finalCell = new PdfPCell(new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + "                     Total Amount : Rs "));
        //Todo change code here to show vat amount when there is vat number
        PdfPCell finalCell = new PdfPCell(
                new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + "           Total Amount : Rs "));
        finalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        finalCell.setColspan(6);
        table.addCell(finalCell);
        table.addCell("" + salebill.getTotalAmt());

        PdfPCell cdCell = new PdfPCell(new Phrase("Cash Discount (2 %) : (-) Rs"));
        cdCell.setColspan(6);
        cdCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cdCell);
        table.addCell("" + salebill.getDiscount());

        PdfPCell finalAmtCell = new PdfPCell(new Phrase("Final Amount : Rs"));
        finalAmtCell.setColspan(6);
        finalAmtCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(finalAmtCell);
        table.addCell("" + salebill.getFinalAmt());

        document.add(table);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        Paragraph sign = new Paragraph(new Chunk("Authorized signatory\n(BIO PHARMA)"));
        sign.setAlignment(Element.ALIGN_RIGHT);
        document.add(sign);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        document.add(Chunk.NEWLINE);

        Paragraph p = new Paragraph("THANK YOU FOR YOUR BUSINESS");
        p.setFont(FONT[4]);
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);

        ///////////////////End Documnet here//////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////
        document.close(); // no need to close PDFwriter?

    } catch (DocumentException | FileNotFoundException e) {
        //LOGGER
        e.printStackTrace();
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Printing Error");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.setScene(new Scene(VBoxBuilder.create()
                .children(new Text(
                        "The file to be printed is already open \n. Please close the file and Print Again"))
                .alignment(Pos.CENTER).padding(new Insets(50)).build()));
        dialogStage.show();
    }

}

From source file:validator.Invoice.java

public static boolean printInvoice(HttpServletResponse response)
        throws DocumentException, FileNotFoundException {
    Document document = new Document();
    java.net.URL path = LogData.class.getResource("/");
    String destinationDir;/*from ww w .j a  va2  s  . c om*/
    destinationDir = path.toString();
    destinationDir = destinationDir.substring(destinationDir.lastIndexOf(":") + 1,
            destinationDir.indexOf("WEB-INF"));
    String filePath = destinationDir + "invoice" + "/";
    ;
    File fileName = new File(filePath);
    if (!fileName.exists()) {
        fileName.mkdir();
    }

    filePath = filePath + "invoice" + ".pdf";
    PdfWriter.getInstance(document, new FileOutputStream(filePath));
    document.open();
    Paragraph paragraph1 = new Paragraph("Invoice");
    paragraph1.setAlignment(Element.ALIGN_CENTER);

    paragraph1.setFont(FontFactory.getFont(FontFactory.COURIER, 18, Font.BOLD, new CMYKColor(0, 255, 0, 0)));
    Paragraph datePara = new Paragraph("Date :" + new Date());
    datePara.setAlignment(Element.ALIGN_RIGHT);

    File file = new File(filePath);
    PdfPTable table = new PdfPTable(2);
    table.setSpacingBefore(25);
    table.setWidthPercentage(100);
    table.setSpacingAfter(25);

    PdfPCell c1 = new PdfPCell(new Phrase("Description"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(" Amount "));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);
    table.addCell("         " + "   ");
    table.addCell("         " + "  ");
    table.addCell("          Total Balance amount :");
    table.addCell("         " + "   ");
    Paragraph amountPara = new Paragraph("\nPaid Amount:  ");
    Paragraph forCom = new Paragraph("\n For Company: ");
    document.open();
    document.add(paragraph1);
    document.add(datePara);
    document.add(table);
    document.add(amountPara);
    document.add(forCom);
    document.close();
    streamImageFile(file, response);

    return true;
}

From source file:Valuacion.Autorizacion.java

private void b_pdfhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pdfhActionPerformed
     // TODO add your handling code here:
     h = new Herramientas(user, 0);
     h.session(sessionPrograma);//from   w w  w  . j  a  va 2s.  c  o  m
     Session session = HibernateUtil.getSessionFactory().openSession();
     try {
         session.beginTransaction().begin();
         BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
         //Orden ord=buscaApertura();
         PDF reporte = new PDF();
         Date fecha = new Date();
         DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
         String valor = dateFormat.format(fecha);
         File folder = new File("reportes/" + ord.getIdOrden());
         folder.mkdirs();
         reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin",
                 "reportes/" + ord.getIdOrden() + "/" + valor + "-autorizacion.pdf");
         Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
         BaseColor contenido = BaseColor.WHITE;
         int centro = Element.ALIGN_CENTER;
         int izquierda = Element.ALIGN_LEFT;
         int derecha = Element.ALIGN_RIGHT;
         float tam[] = new float[] { 15, 15, 50, 150, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 100 };
         PdfPTable tabla = reporte.crearTabla(15, tam, 100, Element.ALIGN_LEFT);

         cabecera(reporte, bf, tabla);

         session.beginTransaction().begin();
         Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
         //Partida resp=(Partida[]) session.createCriteria(Partida.class).add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden))).addOrder(Order.desc("idEvaluacion")).addOrder(Order.desc("subPartida"));
         //Partida[] cuentas = (Partida[]) ord.getPartidas().toArray(new Partida[0]);
         List cuentas = null;
         switch (c_filtro.getSelectedItem().toString()) {
         case "Todos":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .addOrder(Order.asc("idEvaluacion")).addOrder(Order.asc("subPartida")).list();
             break;

         case "Hojalateria":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espHoj", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Mecanica":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espMec", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Suspension":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espSus", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Electricidad":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espEle", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;
         }

         int ren = 0;
         if (cuentas.size() > 0) {
             DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
             formatoPorcentaje.setMinimumFractionDigits(2);
             for (int i = 0; i < cuentas.size(); i++) {
                 Partida Part = (Partida) cuentas.get(i);
                 tabla.addCell(reporte.celda("" + Part.getIdEvaluacion(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 tabla.addCell(reporte.celda("" + Part.getSubPartida(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));

                 if (Part.isEspEle() == true)
                     tabla.addCell(reporte.celda("Electricidad", font, contenido, izquierda, 0, 0,
                             Rectangle.RECTANGLE));
                 else {
                     if (Part.isEspMec() == true)
                         tabla.addCell(reporte.celda("Mecanica", font, contenido, izquierda, 0, 0,
                                 Rectangle.RECTANGLE));
                     else {
                         if (Part.isEspSus() == true)
                             tabla.addCell(reporte.celda("Suspension", font, contenido, izquierda, 0, 0,
                                     Rectangle.RECTANGLE));
                         else {
                             if (Part.isEspHoj() == true)
                                 tabla.addCell(reporte.celda("Hojalateria", font, contenido, izquierda, 0, 0,
                                         Rectangle.RECTANGLE));
                             else {
                                 tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 0,
                                         Rectangle.RECTANGLE));
                             }
                         }
                     }
                 }

                 tabla.addCell(reporte.celda(Part.getCatalogo().getNombre(), font, contenido, izquierda, 0, 0,
                         Rectangle.RECTANGLE));

                 tabla.addCell(reporte.celda("" + Part.getCant(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 tabla.addCell(
                         reporte.celda(Part.getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntDesm() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntDesm()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntCamb() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntCamb()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMin() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntRepMin()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMed() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntRepMed()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMax() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntRepMax()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMin() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntPinMin()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMed() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntPinMed()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMax() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntPinMax()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getInstruccion() != null)
                     tabla.addCell(reporte.celda(Part.getInstruccion(), font, contenido, izquierda, 0, 1,
                             Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 /*if(ren==38)
                 {
                     reporte.agregaObjeto(tabla);
                     reporte.writer.newPage();
                     tabla=reporte.crearTabla(17, tam, 100, Element.ALIGN_LEFT);
                     cabecera(reporte, bf, tabla);
                     ren=-1;
                 }*/
                 ren++;
             }

         }
         session.beginTransaction().rollback();
         tabla.setHeaderRows(3);
         reporte.agregaObjeto(tabla);
         reporte.cerrar();
         reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-autorizacion.pdf");

     } catch (Exception e) {
         System.out.println(e);
         e.printStackTrace();
         JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte");
     }
     if (session != null)
         if (session.isOpen())
             session.close();
 }

From source file:Valuacion.Autorizacion.java

private void b_pdfxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pdfxActionPerformed
     // TODO add your handling code here:
     h = new Herramientas(user, 0);
     h.session(sessionPrograma);//from w  ww  .  j a  v a  2  s .  co m
     Session session = HibernateUtil.getSessionFactory().openSession();
     try {
         session.beginTransaction().begin();
         BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
         //Orden ord=buscaApertura();
         PDF reporte = new PDF();
         Date fecha = new Date();
         DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
         String valor = dateFormat.format(fecha);
         File folder = new File("reportes/" + ord.getIdOrden());
         folder.mkdirs();
         reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin",
                 "reportes/" + ord.getIdOrden() + "/" + valor + "-autorizacion.pdf");
         Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
         BaseColor contenido = BaseColor.WHITE;
         int centro = Element.ALIGN_CENTER;
         int izquierda = Element.ALIGN_LEFT;
         int derecha = Element.ALIGN_RIGHT;
         float tam[] = new float[] { 15, 15, 50, 150, 15, 15, 12, 12, 12, 12, 12, 12, 12, 12, 100 };
         PdfPTable tabla = reporte.crearTabla(15, tam, 100, Element.ALIGN_LEFT);

         cabecera(reporte, bf, tabla);

         session.beginTransaction().begin();
         Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
         //Partida resp=(Partida[]) session.createCriteria(Partida.class).add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden))).addOrder(Order.desc("idEvaluacion")).addOrder(Order.desc("subPartida"));
         //Partida[] cuentas = (Partida[]) ord.getPartidas().toArray(new Partida[0]);
         List cuentas = null;
         switch (c_filtro.getSelectedItem().toString()) {
         case "Todos":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .addOrder(Order.asc("idEvaluacion")).addOrder(Order.asc("subPartida")).list();
             break;

         case "Hojalateria":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espHoj", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Mecanica":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espMec", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Suspension":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espSus", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Electricidad":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espEle", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;
         }

         int ren = 0;
         if (cuentas.size() > 0) {
             for (int i = 0; i < cuentas.size(); i++) {
                 Partida Part = (Partida) cuentas.get(i);
                 /*if(Part.isRefCoti())
                 {*/
                 tabla.addCell(reporte.celda("" + Part.getIdEvaluacion(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 tabla.addCell(reporte.celda("" + Part.getSubPartida(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 if (Part.isEspEle() == true)
                     tabla.addCell(reporte.celda("Electricidad", font, contenido, izquierda, 0, 0,
                             Rectangle.RECTANGLE));
                 else {
                     if (Part.isEspMec() == true)
                         tabla.addCell(reporte.celda("Mecanica", font, contenido, izquierda, 0, 0,
                                 Rectangle.RECTANGLE));
                     else {
                         if (Part.isEspSus() == true)
                             tabla.addCell(reporte.celda("Suspension", font, contenido, izquierda, 0, 0,
                                     Rectangle.RECTANGLE));
                         else {
                             if (Part.isEspHoj() == true)
                                 tabla.addCell(reporte.celda("Hojalateria", font, contenido, izquierda, 0, 0,
                                         Rectangle.RECTANGLE));
                             else {
                                 tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 0,
                                         Rectangle.RECTANGLE));
                             }
                         }
                     }
                 }
                 tabla.addCell(reporte.celda(Part.getCatalogo().getNombre(), font, contenido, izquierda, 0, 0,
                         Rectangle.RECTANGLE));

                 tabla.addCell(reporte.celda("" + Part.getCant(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 tabla.addCell(
                         reporte.celda(Part.getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntDesm() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntCamb() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMin() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMed() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMax() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMin() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMed() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMax() > -1)
                     tabla.addCell(reporte.celda("X", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getInstruccion() != null)
                     tabla.addCell(reporte.celda(Part.getInstruccion(), font, contenido, izquierda, 0, 1,
                             Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 /*if(ren==38)
                 {
                     reporte.agregaObjeto(tabla);
                     reporte.writer.newPage();
                     tabla=reporte.crearTabla(17, tam, 100, Element.ALIGN_LEFT);
                     cabecera(reporte, bf, tabla);
                     ren=-1;
                 }*/
                 ren++;
                 //}
             }

         }
         session.beginTransaction().rollback();
         tabla.setHeaderRows(3);
         reporte.agregaObjeto(tabla);
         reporte.cerrar();
         reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-autorizacion.pdf");

     } catch (Exception e) {
         System.out.println(e);
         e.printStackTrace();
         JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte");
     }
     if (session != null)
         if (session.isOpen())
             session.close();
 }