Example usage for com.itextpdf.text FontFactory getFont

List of usage examples for com.itextpdf.text FontFactory getFont

Introduction

In this page you can find the example usage for com.itextpdf.text FontFactory getFont.

Prototype


public static Font getFont(final String fontname, final float size, final int style, final BaseColor color) 

Source Link

Document

Constructs a Font-object.

Usage

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 {//from   w ww.  j a  v  a2  s . c  o 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;//  www.j  av a2  s. c om
    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;//  ww w.  ja va  2s  .c o  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;/*from w w  w  .  j  a  va  2s. com*/
    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:Measurment_Result_Record.MeasurmentSetup.java

private void jMenuItem_exportpdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_exportpdfActionPerformed
    // TODO add your handling code here:
    // TODO add your handling code here:
    try {/*from  ww  w.j  a  va  2s  .c o m*/
        // TODO add your handling code here:
        JFileChooser fchooser = new JFileChooser();
        int status = fchooser.showSaveDialog(null);
        if (status != JFileChooser.APPROVE_OPTION)
            return;
        fchooser.setDialogTitle("Save the Measurment result to pdf.");
        File selectedF = fchooser.getSelectedFile();
        String filename = selectedF.getAbsolutePath();
        //get the file path to save the pdf
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));
        document.open();
        //add the IPELS logo and title
        int size = 30;
        com.itextpdf.text.Font titleFont;
        titleFont = FontFactory.getFont(FontFactory.TIMES_BOLD, size, com.itextpdf.text.Font.BOLD,
                BaseColor.BLUE);
        Paragraph ipels = new Paragraph("IPELS", titleFont);
        ipels.setAlignment(Element.ALIGN_CENTER);

        document.add(ipels);
        titleFont.setSize(25);
        Paragraph para = new Paragraph("Measurment result \n ", titleFont);
        para.setAlignment(Element.ALIGN_CENTER);
        document.add(para);

        //loop through all the measurmentsetups tables and add each of them to the document
        for (MeasurmentSetup mesSetup : this.presenter.allMeasurmentSetups) {
            addResultTablesTotheDocument(document, mesSetup.recordTablePreview, mesSetup.getMeasurmentTitle());
        }

        //close the document
        document.close();
        //preview the document
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filename + ".pdf");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE);
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "opening pdf", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:model.PDFModel.java

License:Open Source License

public PdfPTable createTablePDFTable(int counter, String raportDate) {

    JTable resultTable = query.getProductsInTablePDFTable(raportDate, counter);

    PdfPTable[] tableTable = new PdfPTable[11];
    PdfPCell cell, productNameCell, paymentCell, countCell, priceCell;

    tableTable[counter] = new PdfPTable(4);
    tableTable[counter].setSpacingBefore(5f);
    tableTable[counter].setSpacingAfter(5f);

    totalTablePayment[counter] = 0.00;/*from  w w  w .  j a  v a2s  .c o m*/
    if (resultTable != null) {
        DefaultTableModel resultTableModel = (DefaultTableModel) resultTable.getModel();
        if (resultTableModel.getRowCount() > 0) {
            cell = new PdfPCell(new Phrase("Stolik " + (counter)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 255, 50));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            tableTable[counter].addCell(cell);
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            tableTable[counter].addCell(cell);
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            tableTable[counter].addCell(cell);

            cell = new PdfPCell(new Phrase("Produkt"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell(new Phrase("Ilosc"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell(new Phrase("Cena jednostkowa"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell(new Phrase("Zaplata"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);

            for (int i = 0; i < resultTableModel.getRowCount(); i++) {
                productNameCell = new PdfPCell(new Phrase(resultTableModel.getValueAt(i, 0).toString(),
                        FontFactory.getFont(FontFactory.defaultEncoding, 10, Font.NORMAL, BaseColor.BLACK)));
                productNameCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                productNameCell.setBackgroundColor(new BaseColor(80, 135, 8));
                tableTable[counter].addCell(productNameCell);
                countCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 2))));
                countCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                tableTable[counter].addCell(countCell);
                double payment = Double.parseDouble(resultTableModel.getValueAt(i, 1).toString())
                        * Double.parseDouble(resultTableModel.getValueAt(i, 2).toString());
                totalTablePayment[counter] += payment;
                paymentCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 1))));
                paymentCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                tableTable[counter].addCell(paymentCell);
                priceCell = new PdfPCell(new Phrase(String.valueOf(payment)));
                priceCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                priceCell.setBackgroundColor(new BaseColor(255, 160, 160));
                tableTable[counter].addCell(priceCell);
            }
        }
    }
    if (totalTablePayment[counter] > 0.00) {
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        tableTable[counter].addCell(cell);
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        tableTable[counter].addCell(cell);
        cell = new PdfPCell(new Phrase("SUMA:",
                FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.NORMAL, BaseColor.BLACK)));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableTable[counter].addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(totalTablePayment[counter]),
                FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.BOLD, BaseColor.BLACK)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(new BaseColor(255, 50, 50));
        tableTable[counter].addCell(cell);
    }

    return tableTable[counter];
}

From source file:modelo.crearPdf.java

public String pdf(int tiquet, int idOrden, String codOrden) {
    try {//  ww w.j a v  a  2s  .  co  m

        String sql = "Select * from tiquet where idorden = '" + idOrden + "' and tiquet='" + tiquet + "'";
        rs = Consultar(sql);
        int id = 0;
        int numTiquet = 0;
        String ob = "";
        tiquet verTiquet = new tiquet();
        colores verColor = new colores();
        String colorUno = "";
        String colorDos = "";
        System.out.print("id de la orden en el tiquet:" + idOrden);
        ArrayList<String> lista = new ArrayList<String>();
        int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0,
                c13 = 0, c14 = 0, c15 = 0;
        int c16 = 0, c17 = 0, c18 = 0, c19 = 0, c20 = 0, c21 = 0, c22 = 0, c23 = 0, c24 = 0, c25 = 0, c26 = 0,
                c27 = 0, c28 = 0, c29 = 0;
        int c30 = 0, c31 = 0, c32 = 0, c33 = 0;
        String observacion = "";
        String verificacion = "";
        //rs.last();
        int cuantos = rs.getRow();
        //System.out.print("puestos:" + cuantos+ "orden: " + codOrden + "tiquet: " + tiquet);
        //Creamos el CHUNK definiendo su tipo de letra, tamao
        Chunk direccion = new Chunk("Calle 12 # 6-68 Nia Ceci",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Tiq = new Chunk("Tiquet #",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValTiq = new Chunk("" + tiquet,
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Tel = new Chunk("Tel: 5783364",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Ref = new Chunk("Ref",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValRef = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Correo = new Chunk("calzadoseiya@gmail.com",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk Par = new Chunk("Pares",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValPar = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk FechaTiq = new Chunk("Fecha",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk FechaTiq2 = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Orden = new Chunk("Orden",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValOrd = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Cor = new Chunk("CORTADA",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Guar = new Chunk("GUARNICION",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Mon = new Chunk("MONTADA",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Emp = new Chunk("EMPLANTILLADA",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk OBSER = new Chunk("OBSERVACION",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Col1 = new Chunk("Color 1",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk Col2 = new Chunk("Color 2",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk Encabezado = new Chunk("SEIYA",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11, Font.NORMAL, BaseColor.BLACK));
        Chunk num21 = new Chunk("21",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num22 = new Chunk("22",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num23 = new Chunk("23",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num24 = new Chunk("24",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num25 = new Chunk("25",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num26 = new Chunk("26",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num27 = new Chunk("27",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num28 = new Chunk("28",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num29 = new Chunk("29",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num30 = new Chunk("30",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num31 = new Chunk("31",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num32 = new Chunk("32",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num33 = new Chunk("33",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num34 = new Chunk("34",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num35 = new Chunk("35",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num36 = new Chunk("36",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num37 = new Chunk("37",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num38 = new Chunk("38",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num39 = new Chunk("39",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num40 = new Chunk("40",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num41 = new Chunk("41",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num42 = new Chunk("42",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num43 = new Chunk("43",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num44 = new Chunk("44",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));

        //Fecha actual en formato completo:
        //Tue Sep 23 01:18:48 CEST 2014
        Date fechaActual = new Date();

        //Formateando la fecha:
        DateFormat formatoHora = new SimpleDateFormat("HH-mm-ss");
        DateFormat formatoFecha = new SimpleDateFormat("yyyy-MM-dd");
        DateFormat Fecha = new SimpleDateFormat("dd/MM/yyyy");
        //  System.out.println("Fecha: "+formatoFecha.format(fechaActual)+" Son las: "+formatoHora.format(fechaActual));
        String fe = Fecha.format(fechaActual);
        //Directorio destino para las descargas
        File folder = new File("c:\\seiya\\tiquets");

        //Crea el directorio de destino en caso de que no exista
        folder.mkdirs();

        int numeroAleatorio = (int) (Math.random() * 2500 + 1);
        //Nombre del fichero <strong>PDF</strong> Resultante de la ejecucion
        String dir = "C:\\seiya\\tiquets\\Tiquet_" + tiquet + ".pdf";
        // El archivo pdf que vamos a generar
        FileOutputStream fileOutputStream = new FileOutputStream(dir);
        Rectangle pageSize = new Rectangle(300f, 792f); //ancho y alto
        //Creacion del documento con un tamao y unos margenes predeterminados

        Document document = new Document(pageSize, 1, 1, 1, 1);
        // Obtener la instancia del PdfWriter
        PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);

        //Opens the document.
        //You have to open the document before you can begin to add content to the body of the document.
        document.open();
        //**************************************************************

        //Ejemplos de TABLE
        titulo = new Chunk("", FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK));
        document.add(titulo);
        //Aadir tabla 5 columnas
        PdfPTable table = new PdfPTable(15);
        //Aadir CABECERA

        PdfPCell cell = new PdfPCell();
        cell.setColspan(15);
        table.addCell(cell);

        Image image = Image.getInstance("logo.png");
        //    String col = "jhon";
        cell = new PdfPCell(image);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(4);
        cell.setRowspan(7);
        table.addCell(cell);
        /*
        cell = new PdfPCell(new Phrase("imagen:"));
        cell.setColspan(4);
        cell.setRowspan(7);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        //cell.setBackgroundColor(BaseColor.GRAY);
        table.addCell(cell);
                
        /*table.addCell(createImageCell(IMG1));*/
        cell = new PdfPCell(new Phrase(direccion));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(6);
        cell.setRowspan(2);

        table.addCell(cell);

        while (rs.next()) {

            c1 = rs.getInt(1);
            c2 = rs.getInt(2);
            c3 = rs.getInt(3);
            c4 = rs.getInt(4);
            c5 = rs.getInt(5);
            observacion = rs.getString(6);
            verificacion = rs.getString(7);
            c8 = rs.getInt(8);
            c9 = rs.getInt(9);
            c10 = rs.getInt(10);
            c11 = rs.getInt(11);
            c12 = rs.getInt(12);
            c13 = rs.getInt(13);
            c14 = rs.getInt(14);
            c15 = rs.getInt(15);
            c16 = rs.getInt(16);
            c17 = rs.getInt(17);
            c18 = rs.getInt(18);
            c19 = rs.getInt(19);
            c20 = rs.getInt(20);
            c21 = rs.getInt(21);
            c22 = rs.getInt(22);
            c23 = rs.getInt(23);
            c24 = rs.getInt(24);
            c25 = rs.getInt(25);
            c26 = rs.getInt(26);
            c27 = rs.getInt(27);
            c28 = rs.getInt(28);
            c29 = rs.getInt(29);
            c30 = rs.getInt(30);
            c31 = rs.getInt(31);
            c32 = rs.getInt(32);
            c33 = rs.getInt(33);

            String c01 = " ", c02 = " ", c03 = " ", c04 = " ", c05 = " ", c06 = " ", c07 = " ", c08 = " ",
                    c09 = " ", c010 = " ", c011 = " ", c012 = " ";
            String c013 = " ", c014 = " ", c015 = " ", c016 = " ", c017 = " ", c018 = " ", c019 = " ",
                    c020 = " ", c021 = " ", c022 = " ", c023 = " ", c024 = " ";
            String c025 = " ", c026 = " ", c027 = " ", c028 = " ", c029 = " ", c030 = " ", c031 = " ",
                    c032 = " ", c033 = " ", c034 = " ";
            if (c1 != 0)
                c01 = String.valueOf(c1);
            if (c2 != 0)
                c02 = String.valueOf(c2);
            if (c3 != 0)
                c03 = String.valueOf(c3);
            if (c4 != 0)
                c04 = String.valueOf(c4);
            if (c5 != 0)
                c05 = String.valueOf(c5);
            if (c8 != 0)
                c08 = String.valueOf(c8);
            if (c9 != 0)
                c09 = String.valueOf(c9);
            if (c10 != 0)
                c010 = String.valueOf(c10);
            if (c11 != 0)
                c011 = String.valueOf(c11);
            if (c12 != 0)
                c012 = String.valueOf(c12);
            if (c13 != 0)
                c013 = String.valueOf(c13);
            if (c14 != 0)
                c014 = String.valueOf(c14);
            if (c15 != 0)
                c015 = String.valueOf(c15);
            if (c16 != 0)
                c016 = String.valueOf(c16);
            if (c17 != 0)
                c017 = String.valueOf(c17);
            if (c18 != 0)
                c018 = String.valueOf(c18);
            if (c19 != 0)
                c019 = String.valueOf(c19);
            if (c20 != 0)
                c020 = String.valueOf(c20);
            if (c21 != 0)
                c021 = String.valueOf(c21);
            if (c22 != 0)
                c022 = String.valueOf(c22);
            if (c23 != 0)
                c023 = String.valueOf(c23);
            if (c24 != 0)
                c024 = String.valueOf(c24);
            if (c25 != 0)
                c025 = String.valueOf(c25);
            if (c26 != 0)
                c026 = String.valueOf(c26);
            if (c27 != 0)
                c027 = String.valueOf(c27);
            if (c28 != 0)
                c028 = String.valueOf(c28);
            if (c29 != 0)
                c029 = String.valueOf(c29);
            if (c30 != 0)
                c030 = String.valueOf(c30);
            if (c31 != 0)
                c031 = String.valueOf(c31);
            if (c32 != 0)
                c032 = String.valueOf(c32);
            if (c33 != 0)
                c033 = String.valueOf(c33);

            colorUno = verColor.consultarNombreColorUno(c4);
            colorDos = verColor.consultarNombreColorDos(c5);
            ob = verTiquet.ConsultaObservacion(tiquet);
            Chunk ValCol1 = new Chunk(colorUno,
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
            Chunk ValCol2 = new Chunk(colorDos,
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
            Chunk ValObserv = new Chunk(ob,
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));

            System.out.print("Color Uno: " + colorUno);

            cell = new PdfPCell(new Phrase(Tiq));
            cell.setColspan(3);
            cell.setRowspan(2);
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("" + tiquet));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Tel));
            cell.setColspan(6);
            cell.setRowspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.CYAN);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(Ref));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("" + c8));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Correo));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(6);
            cell.setRowspan(2);//para eliminar espacio cabecera reemplazo el 2 por 3
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(Par));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("" + c9));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(FechaTiq));//espacio intermedio cabecera
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(fe));//espacio intermedio cabecera
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Orden));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(1);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("" + codOrden));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(1);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Cor));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            cell.setRowspan(1);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Guar));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Mon));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Emp));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(OBSER));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            cell.setRowspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(ValObserv));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            cell.setRowspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Col1));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(3);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(ValCol1));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Col2));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(3);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(ValCol2));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(5);
            table.addCell(cell);

            table.addCell(new Phrase(num21));
            table.addCell(new Phrase(num22));
            table.addCell(new Phrase(num23));
            table.addCell(new Phrase(num24));
            table.addCell(new Phrase(num25));
            table.addCell(new Phrase(num26));
            table.addCell(new Phrase(num27));
            table.addCell(new Phrase(num28));
            table.addCell(new Phrase(num29));
            table.addCell(new Phrase(num30));
            table.addCell(new Phrase(num31));
            table.addCell(new Phrase(num32));
            table.addCell(new Phrase(num33));
            table.addCell(new Phrase(num34));
            table.addCell(new Phrase(num35));

            table.addCell("" + c010);
            table.addCell("" + c011);
            table.addCell("" + c012);
            table.addCell("" + c013);
            table.addCell("" + c014);
            table.addCell("" + c015);
            table.addCell("" + c016);
            table.addCell("" + c017);
            table.addCell("" + c018);
            table.addCell("" + c019);
            table.addCell("" + c020);
            table.addCell("" + c021);
            table.addCell("" + c022);
            table.addCell("" + c023);
            table.addCell("" + c024);

            table.addCell(new Phrase(num36));
            table.addCell(new Phrase(num37));
            table.addCell(new Phrase(num38));
            table.addCell(new Phrase(num39));
            table.addCell(new Phrase(num40));
            table.addCell(new Phrase(num41));
            table.addCell(new Phrase(num42));
            table.addCell(new Phrase(num43));
            table.addCell(new Phrase(num44));
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");

            table.addCell("" + c025);
            table.addCell("" + c026);
            table.addCell("" + c027);
            table.addCell("" + c028);
            table.addCell("" + c029);
            table.addCell("" + c030);
            table.addCell("" + c031);
            table.addCell("" + c032);
            table.addCell("" + c033);
            table.addCell("");
            table.addCell("");
            table.addCell("");
            table.addCell("");
            table.addCell("");
            table.addCell("");

            table.setWidthPercentage(100f);
            table.setHorizontalAlignment(Element.ALIGN_RIGHT);

            document.add(table);

            // String cadena="";
            Chunk cadena = null;
            for (int i = 1; i <= 4; i++) {
                //Chunk chunkSeparador =  new Chunk(SEPARADOR);
                // document.add(chunkSeparador);
                // document.add(Chunk.NEWLINE);

                PdfPTable tabla = new PdfPTable(15);
                if (i == 1)
                    cadena = Emp;
                if (i == 2)
                    cadena = Mon;

                if (i == 3) {
                    cadena = Guar;

                }
                if (i == 4)
                    cadena = Cor;

                cell = new PdfPCell(
                        new Phrase("-----------------------------------------------------------------"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(15);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase(Encabezado));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(5);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(cadena));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(4);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(Tiq));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("" + tiquet));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase(Par));
                cell.setHorizontalAlignment(Font.BOLD);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(2);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("" + c9));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(4);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(Ref));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("" + c8));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase(Col1));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(ValCol1));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(4);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase(Col2));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(ValCol2));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(5);
                tabla.addCell(cell);

                tabla.addCell(new Phrase(num21));
                tabla.addCell(new Phrase(num22));
                tabla.addCell(new Phrase(num23));
                tabla.addCell(new Phrase(num24));
                tabla.addCell(new Phrase(num25));
                tabla.addCell(new Phrase(num26));
                tabla.addCell(new Phrase(num27));
                tabla.addCell(new Phrase(num28));
                tabla.addCell(new Phrase(num29));
                tabla.addCell(new Phrase(num30));
                tabla.addCell(new Phrase(num31));
                tabla.addCell(new Phrase(num32));
                tabla.addCell(new Phrase(num33));
                tabla.addCell(new Phrase(num34));
                tabla.addCell(new Phrase(num35));

                tabla.addCell("" + c010);
                tabla.addCell("" + c011);
                tabla.addCell("" + c012);
                tabla.addCell("" + c013);
                tabla.addCell("" + c014);
                tabla.addCell("" + c015);
                tabla.addCell("" + c016);
                tabla.addCell("" + c017);
                tabla.addCell("" + c018);
                tabla.addCell("" + c019);
                tabla.addCell("" + c020);
                tabla.addCell("" + c021);
                tabla.addCell("" + c022);
                tabla.addCell("" + c023);
                tabla.addCell("" + c024);

                tabla.addCell(new Phrase(num36));
                tabla.addCell(new Phrase(num37));
                tabla.addCell(new Phrase(num38));
                tabla.addCell(new Phrase(num39));
                tabla.addCell(new Phrase(num40));
                tabla.addCell(new Phrase(num41));
                tabla.addCell(new Phrase(num42));
                tabla.addCell(new Phrase(num43));
                tabla.addCell(new Phrase(num44));
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");

                tabla.addCell("" + c025);
                tabla.addCell("" + c026);
                tabla.addCell("" + c027);
                tabla.addCell("" + c028);
                tabla.addCell("" + c029);
                tabla.addCell("" + c030);
                tabla.addCell("" + c031);
                tabla.addCell("" + c032);
                tabla.addCell("" + c033);
                tabla.addCell("");
                tabla.addCell("");
                tabla.addCell("");
                tabla.addCell("");
                tabla.addCell("");
                tabla.addCell("");

                tabla.setWidthPercentage(100f);
                tabla.setHorizontalAlignment(Element.ALIGN_RIGHT);

                document.add(tabla);

            }
            //FIN Ejemplos de TABLE

        }

        document.close();

        return "exito";

    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        return "Error al Generar el PDF";
    }

}

From source file:modelo.GenerarPDF.java

public void nuevoReporteClientes(ArrayList<Cliente> Datos) throws IOException {
    // Se crea el documento Document documento = new Document();
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;/*w  w w. j  a  v a  2  s.  c o m*/
    try {
        FileOutputStream ficheroPdf = new FileOutputStream("C:\\Users\\panle\\Documents\\ReporteClientes.pdf");
        documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento.
        documento.open();
        documento.add(new Paragraph("REPORTE CLIENTES", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(9);
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("algo", font));
        documento.add(new Paragraph("\n"));

        Image img = Image.getInstance("C:\\Users\\panle\\Documents\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));
        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("NOMBRE COMLETO");
        tabla.addCell("USUARIO");
        tabla.addCell("NIT");
        tabla.addCell("NO DOCUMENTO");
        tabla.addCell("PROFESION");
        tabla.addCell("TELFONO CELULAR");
        tabla.addCell("TELFONO RESIDENCIA");
        tabla.addCell("DIRECCIN");
        tabla.addCell("CIUDAD");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getNOMBRE() + " " + Datos.get(conta).getAPELLIDO());
            tabla.addCell(Datos.get(conta).getUSUARIO());
            tabla.addCell(Datos.get(conta).getNIT());
            tabla.addCell(Datos.get(conta).getNUMERO_DOC());
            tabla.addCell(Datos.get(conta).getPROFESION());
            tabla.addCell(Datos.get(conta).getTEL_CEL());
            tabla.addCell(Datos.get(conta).getTEL_RESIDENCIA());
            tabla.addCell(Datos.get(conta).getDIRECCION());
            tabla.addCell(Datos.get(conta).getCIUDAD());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Clientes, por:");
        e.printStackTrace();
    }
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteProductos(ArrayList<Producto> Datos) throws IOException {
    // Se crea el documento Document
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;//from w  w  w .  ja  va 2 s . co m
    try {
        //Direccion root
        FileOutputStream ficheroPdf = new FileOutputStream("C:\\Users\\panle\\Documents\\ReporteProductos.pdf");
        //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf");
        //File tempfile = new File("user.dir/tmp", "tempfile.txt");    
        documento = new Document();
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento
        documento.open();
        documento.add(new Paragraph("REPORTE PRODUCTOS", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("Celdas", font));

        documento.add(new Paragraph("\n"));

        Image img = Image.getInstance("C:\\Users\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));

        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("DESCRIPCION");
        tabla.addCell("REFERENCIA");
        tabla.addCell("TIPO");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getDESCRIPCION());
            tabla.addCell(Datos.get(conta).getREFERENCIA());
            tabla.addCell(Datos.get(conta).getTIPO());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Productos, por:");
        e.printStackTrace();
    }
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteVentasFecha(ArrayList<Producto> Datos) throws IOException {
    // Se crea el documento Document
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;/* www  .  j  ava  2  s .  c  om*/
    try {
        //Direccion root
        FileOutputStream ficheroPdf = new FileOutputStream(
                "C:\\Users\\panle\\Documents\\ReporteVentasFecha.pdf");
        //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf");
        //File tempfile = new File("user.dir/tmp", "tempfile.txt");    
        documento = new Document();
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento
        documento.open();
        documento.add(new Paragraph("REPORTE VENTAS POR FECHA", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("Celdas", font));

        documento.add(new Paragraph("\n"));

        Image img = Image.getInstance("C:\\Users\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));

        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("DESCRIPCION");
        tabla.addCell("REFERENCIA");
        tabla.addCell("TIPO");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getDESCRIPCION());
            tabla.addCell(Datos.get(conta).getREFERENCIA());
            tabla.addCell(Datos.get(conta).getTIPO());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Productos, por:");
        e.printStackTrace();
    }
}