Example usage for com.itextpdf.text Document close

List of usage examples for com.itextpdf.text Document close

Introduction

In this page you can find the example usage for com.itextpdf.text Document close.

Prototype

boolean close

To view the source code for com.itextpdf.text Document close.

Click Source Link

Document

Has the document already been closed?

Usage

From source file:containers.Receipt.java

public void printReceiptTogether() {
    try {/*from   w  w w .  java  2s.  com*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\receiptTogether.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        p.add(header);
        p.add(new Date().toString());
        footerTogether();
        p.add(body);
        p.add(footer);
        document.add(p);

        document.close();
        file.close();

        header = "";
        body = "";
        footer = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Receipt.java

public void printReceiptSeparate() {
    try {/*w  w  w .  ja  v a2  s.c om*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\receipt" + orderNumber + ".pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        p.add(header);
        p.add(new Date().toString());
        footerSeparate();
        p.add(body);
        p.add(footer);
        document.add(p);

        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Receipt.java

public void printSentOrder(Order order) {
    ArrayList<Item> items = order.getItems();
    orderNumber = Integer.toString(order.getOrderNo());

    drink = "Bar Order\n";
    drink += "\nOrder #: " + orderNumber + "\n";
    drink += "Server : " + empName + "\n\n";
    drink += String.format("%-15s\n", "Item");
    drink += String.format("%-15s\n", "----");

    food = "Kitchen Order\n";
    food += "\nOrder #: " + orderNumber + "\n";
    food += "Server : " + empName + "\n\n";
    food += String.format("%-15s\n", "Item");
    food += String.format("%-15s\n", "----");

    for (Item item : items) {
        if (item.getItemType().equalsIgnoreCase("drink")) {
            drink += String.format("%-15s", item.getItemName());
            drink += "\n";
            drinkCount++;// ww  w .ja va  2s  .  c o  m
        } else {
            food += String.format("%-15s", item.getItemName());
            food += "\n";
            foodCount++;
        }
    }

    if (drinkCount > 0) {
        try {
            String path = System.getProperty("user.home") + File.separator + "Documents";
            OutputStream file = new FileOutputStream(new File(path + "\\barOrder" + orderNumber + ".pdf"));
            Document document = new Document();
            PdfWriter.getInstance(document, file);
            document.open();
            Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

            p.add(new Date().toString() + "\n");
            p.add(drink);
            document.add(p);

            document.close();
            file.close();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    if (foodCount > 0) {
        try {
            String path = System.getProperty("user.home") + File.separator + "Documents";
            OutputStream file = new FileOutputStream(new File(path + "\\kitchenOrder" + orderNumber + ".pdf"));
            Document document = new Document();
            PdfWriter.getInstance(document, file);
            document.open();
            Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

            p.add(new Date().toString() + "\n");
            p.add(food);
            document.add(p);

            document.close();
            file.close();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    drink = "";
    food = "";
}

From source file:containers.Report.java

public void generateHours(String hours, String from, String to) {
    try {//from ww w.jav a2 s .co m
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\EmployeeReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        ehours = hours;

        body = String.format("%-15s - %2s\n", "Employee Number", empno);
        body += String.format("%-15s - %5s\n", "First Name", fname);
        body += String.format("%-15s - %1s\n", "Last Name", lname);
        body += String.format("%-15s - %9s\n", "Address", address);
        body += String.format("%-15s - %9s\n", "Phone Number", phone);
        body += String.format("%-15s - %3s\n", "Position", position);
        body += String.format("%-15s - %8s\n", "Total Hours", ehours);
        body += "\n";

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nEmployee Report\n\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body);
        document.add(p);

        document.close();
        file.close();

        body = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderByDate(ArrayList<String> entry, String from, String to) {
    try {/*from ww  w  . j  a  v  a 2  s.  c  o  m*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\DateOrderReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body2 = String.format("%5s - %5s - %5s - %5s\n", "Order No.", "Order Total", "Payment Type",
                "Order Date");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 4) {
            body2 += String.format("%-10s %8s %15s %24s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2),
                    entry.get(i + 3).substring(0, 19));
            counter += Double.parseDouble(entry.get(i + 1));
        }

        body2 += "\n\nTotal for all orders: $" + counter;

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nOrder by Date Report\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body2);
        document.add(p);

        document.close();
        file.close();

        body2 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderByPayment(String type, ArrayList<String> entry, String from, String to) {
    try {/*from  www .j a  v  a2 s .c om*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\PayTypeReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body3 = String.format("%5s - %5s - %5s\n", "Order No.", "Order Total", "Order Date");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 3) {
            body3 += String.format("%-10s %8s %25s\n", entry.get(i), entry.get(i + 1),
                    entry.get(i + 2).substring(0, 19));
            counter += Double.parseDouble(entry.get(i + 1));
        }

        body3 += "\n\nTotal for all orders: $" + counter;

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nOrder by Payment Report\n");
        p.add("Payment Type: " + type + "\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body3);
        document.add(p);

        document.close();
        file.close();

        body3 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderItem(String ordernum, ArrayList<String> entry) {
    try {/*from  w w w . j  a  va 2 s  . c  om*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\OrderReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body4 = String.format("%5s  %27s  %10s\n", "Item Name", "Base Price", "Log Total");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 3) {
            body4 += String.format("%-10s %15s %12s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2));
            counter += Double.parseDouble(entry.get(i + 2));
        }

        body4 += "\n\nTotal for all orders: $" + counter;

        p.add(new Date().toString());
        p.add("\n\nItems on Order Report\n");
        p.add("Order Number: " + ordernum + "\n\n");

        p.add(body4);
        document.add(p);

        document.close();
        file.close();

        body4 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:control.AdminPDF.java

public static void generarInforme(ArrayList<Tarea> tareas, String usuario) {

    try {/*from www  .  j av  a 2 s  . co m*/
        //Creamos la carpeta donde se almacenaran las facturas
        // Si quieres que las facturas se guarden en una carpeta del computador, 
        // aca colocas la ruta donde quieres que se guarden en lugar de src/facturas, 
        // tanto al crear carpeta y laFactura (de tipo File) y al crear archivo (de tipo FileOutputStream)
        //Ejemplo:  File carpeta = new File("D:\\facturas"); 
        //          FileOutputStream archivo = new FileOutputStream("D:\\facturas" + consecutivo + ".pdf");
        //          File laFactura = new File("src/facturas" + consecutivo + ".pdf");

        File carpeta = new File("web/pdfs");
        System.out.println(carpeta.exists());
        if (!carpeta.exists()) {
            carpeta.mkdirs();
        }
        String[] list = carpeta.list();
        consecutivo = list.length;
        System.out.println("Consecutivo es: " + consecutivo);
        int total = 0;
        FileOutputStream archivo = new FileOutputStream("web/pdfs/" + consecutivo + ".pdf");
        Document documento = new Document();
        PdfWriter.getInstance(documento, archivo);
        documento.open();
        Paragraph titulo = new Paragraph("Resumen de Actividades");
        titulo.setAlignment(Element.ALIGN_CENTER);
        documento.add(titulo);

        documento.add(new Paragraph(
                "------------------------------------------------------------------------------------------------------------------------------"));
        documento.add(new Paragraph("Usuario: " + usuario));
        documento.add(new Paragraph(" "));
        //         documento.add(new Paragraph("------------------------------------------------------------------------------------------------------------------------------"));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        //         documento.add(new Paragraph(" "));
        //         documento.add(new Paragraph(" "));
        documento.add(new Paragraph("  "));
        PdfPTable tabla = new PdfPTable(7);
        Image image = Image.getInstance("../EasyTasks/web/images/logo.png");

        //         tabla.addCell(image);
        Paragraph nombreBase = new Paragraph("Nombre ");
        Paragraph descripcionBase = new Paragraph("Descripcion     ");
        Paragraph fechaBase = new Paragraph("Fecha ");
        Paragraph prioridadBase = new Paragraph("Prioridad  ");
        Paragraph tagsBase = new Paragraph("Tags");
        Paragraph categoriaBase = new Paragraph("Categoria  ");
        Paragraph ubicacionBase = new Paragraph("Ubicacion    ");

        //         tabla.addCell(image);
        tabla.addCell(nombreBase);
        tabla.addCell(descripcionBase);
        tabla.addCell(fechaBase);
        tabla.addCell(prioridadBase);
        tabla.addCell(tagsBase);
        tabla.addCell(categoriaBase);
        tabla.addCell(ubicacionBase);
        for (int i = 0; i < tareas.size(); i++) {

            Tarea tareaNueva = tareas.get(i);
            Paragraph nombre = new Paragraph(tareaNueva.getNombre());
            Paragraph descripcion = new Paragraph(tareaNueva.getDescripcion());
            Paragraph fecha = new Paragraph(tareaNueva.getFechaLimite() + "");
            Paragraph prioridad = new Paragraph(tareaNueva.getPrioridad());
            Paragraph tags = null;
            for (int k = 0; k < tareaNueva.getTags().size(); k++) {
                tags = new Paragraph(tareaNueva.getTags().get(k));
            }
            Paragraph categoria = new Paragraph(tareaNueva.getCategoria());
            Paragraph ubicacion = new Paragraph(
                    tareaNueva.getUbiLatitud() + ", " + tareaNueva.getUbiLongitud());
            //            Paragraph tost = new Paragraph(tareaNueva.toStringSimple());

            tabla.addCell(nombre);
            tabla.addCell(descripcion);
            tabla.addCell(fecha);
            tabla.addCell(prioridad);
            tabla.addCell(tags);
            tabla.addCell(categoria);
            tabla.addCell(ubicacion);
            //            tabla.addCell(tost);

        }

        //         FileReader fr = new FileReader("src/archivos/pedidos.txt");
        //         BufferedReader bwa = new BufferedReader(fr);
        //         String elProducto = bwa.readLine();
        //         while (elProducto != null) {
        //            if (!elProducto.equalsIgnoreCase("")) {
        //               System.out.println("El producto: " + elProducto);
        //               String[] elProductoConPrecio = elProducto.split("-");
        //               Paragraph producto = new Paragraph(elProductoConPrecio[0]);
        //               Paragraph precio = new Paragraph(elProductoConPrecio[1]);
        //               total += Integer.parseInt(elProductoConPrecio[1]);
        //               precio.setAlignment(Element.ALIGN_RIGHT);
        //               tabla.addCell(producto);
        //               tabla.addCell(precio);
        //               elProducto = bwa.readLine();
        //            }
        //         }
        //         if (!darIva().equals("") && !darIva().equals("0")) {
        //            tabla.addCell("Subtotal");
        //            Paragraph elSubTotal = new Paragraph("" + total);
        //            elSubTotal.setAlignment(Element.ALIGN_RIGHT);
        //            tabla.addCell(elSubTotal);
        //            tabla.addCell("Iva (" + darIva() + ")");
        //            int iva = total * Integer.parseInt(darIva()) / 100;
        //            tabla.addCell("" + iva);
        //            int precioConIva = total + iva;
        //            tabla.addCell("Total");
        //            Paragraph elTotal = new Paragraph("" + precioConIva);
        //            elTotal.setAlignment(Element.ALIGN_RIGHT);
        //            tabla.addCell(elTotal);
        //         } else {
        //            tabla.addCell("Total");
        //            Paragraph elTotal = new Paragraph("" + total);
        //            elTotal.setAlignment(Element.ALIGN_RIGHT);
        //            tabla.addCell(elTotal);
        //         }
        documento.add(tabla);
        documento.add(new Paragraph(
                "----------------------------------------------------------------------------------------------"));
        documento.add(new Paragraph("Muchas gracias por utilizar nuestro servicio,"));
        documento.add(new Paragraph(""));
        //         Image image = Image.getInstance("logo.png");
        documento.addCreator("EasyTask Team");
        documento.add(image);
        documento.addCreationDate();
        //         PdfPCell cell2 = new PdfPCell(image, true);

        //         tabla.addCell(cell2);
        documento.add(new Paragraph(""));
        documento.add(new Paragraph("         EasyTask Team"));
        documento.close();
        File elInforme = new File("../EasyTasks/web/pdfs/" + usuario + ".pdf");
        Desktop.getDesktop().open(elInforme);
        //         BufferedWriter br = new BufferedWriter(new FileWriter("src//pedidos.txt"));
        //         br.write("");
        //         br.close();
        //         fr.close();
        //         bwa.close();
        archivo.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(AdminPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(AdminPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(AdminPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
    }

}

From source file:control.listaEquipos.java

private boolean generapdf(String path) throws DocumentException, FileNotFoundException {
    boolean estado = false;
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();//from  w ww .  j  av  a2  s. c  o m
    Paragraph paragraph1 = new Paragraph("Equipos");
    document.add(paragraph1);
    Paragraph paragraph2 = new Paragraph("");
    paragraph2.setSpacingBefore(38f);
    document.add(paragraph2);
    PdfPTable table = new PdfPTable(7);
    table.addCell("Id ");
    table.addCell("Nombre");
    table.addCell("categoria");
    table.addCell("Accesorios");
    table.addCell("Descripcion");
    table.addCell("Marca");
    table.addCell("Estado");
    Object[][] tabla = this.getTableData(tabEquipo);
    for (Object[] o : tabla) {
        int i = 0;
        for (Object e : o) {
            if (i <= 6) {
                if (e != null)
                    table.addCell(((String) e.toString()));
                else
                    table.addCell("");
            }
            i++;
        }
    }
    document.add(table);
    document.close();
    return true;
}