Example usage for com.itextpdf.text Anchor Anchor

List of usage examples for com.itextpdf.text Anchor Anchor

Introduction

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

Prototype

public Anchor(final float leading, final String string) 

Source Link

Document

Constructs an Anchor with a certain leading and a certain String.

Usage

From source file:Controller.CrearPDF.java

/**
 * We create a PDF document with iText using different elements to learn 
 * to use this library.//from  w  w  w  .  j av a 2s  .com
 * Creamos un documento PDF con iText usando diferentes elementos para aprender 
 * a usar esta librera.
 * @param pdfNewFile  <code>String</code> 
 *      pdf File we are going to write. 
 *      Fichero pdf en el que vamos a escribir. 
 */
//    public void createPDF(File pdfNewFile, ReparacionEntity reparacion) throws Exception {
public void createPDF(File pdfNewFile) throws Exception {
    // We create the document and set the file name.        
    // Creamos el documento e indicamos el nombre del fichero.
    try {
        //            ClienteController cc = new ClienteController();
        //            Cliente cliente = cc.buscarPorId(reparacion.getCliente());
        Document document = new Document();
        try {

            PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile));

        } catch (FileNotFoundException fileNotFoundException) {
            System.out.println("No such file was found to generate the PDF "
                    + "(No se encontr el fichero para generar el pdf)" + fileNotFoundException);
        }
        document.open();
        // We add metadata to PDF
        // Aadimos los metadatos del PDF
        document.addTitle("Table export to PDF (Exportamos la tabla a PDF)");
        document.addSubject("Using iText (usando iText)");
        document.addKeywords("Java, PDF, iText");
        document.addAuthor("Cdigo Xules");
        document.addCreator("Cdigo Xules");

        // First page
        // Primera pgina 
        Chunk chunk = new Chunk("RDEN DE TRABAJO", categoryFont);
        Chunk c2 = new Chunk("\n\n\nCentro de Formacin SATCAR6\n" + "Calle Artes Grficas n1 Nave 12 A\n"
                + "Pinto (28320), Madrid", smallFont);

        Chunk c3 = new Chunk("Datos del Cliente", smallBold);
        //            Chunk c4 = new Chunk("Nombre: "+cliente.getRazonSocial(),smallBold);
        //            Chunk c5 = new Chunk("Poblacin: "+cliente.getPoblacion(),smallBold);
        //            Chunk c6 = new Chunk("Provincia: "+cliente.getProvincia(),smallBold);
        //            Chunk c7 = new Chunk("Cdigo Postal: "+cliente.getCp(),smallBold);
        //            Chunk c8 = new Chunk("Num Telfono: Pepito"+cliente.getTlf1(),smallBold);
        Chunk c4 = new Chunk("Nombre: Jesus Eduardo Garcia Toril", smallBold);
        Chunk c5 = new Chunk("Poblacin: Pinto", smallBold);
        Chunk c6 = new Chunk("Provincia: Madrid", smallBold);
        Chunk c7 = new Chunk("Cdigo Postal: 28320", smallBold);
        Chunk c8 = new Chunk("Num Telfono: 659408182", smallBold);

        Paragraph parrafo = new Paragraph(chunk);
        Paragraph p2 = new Paragraph(c2);
        Paragraph p3 = new Paragraph(c3);
        Phrase ph1 = new Phrase(c4);
        Phrase ph2 = new Phrase(c5);
        Phrase ph3 = new Phrase(c6);
        Phrase ph4 = new Phrase(c7);
        Phrase ph5 = new Phrase(c8);

        // Let's create de first Chapter (Creemos el primer captulo)

        // We add an image (Aadimos una imagen)
        Image image;
        try {
            parrafo.setAlignment(Element.ALIGN_CENTER);
            image = Image.getInstance(iTextExampleImage);
            image.setAbsolutePosition(0, 750);
            p2.setAlignment(Element.ALIGN_LEFT);
            document.add(parrafo);
            document.add(image);
            document.add(p2);
            document.add(p3);
            document.add(ph1);
            document.add(ph2);
            document.add(ph3);
            document.add(ph4);
            document.add(ph5);

        } catch (BadElementException ex) {
            System.out.println("Image BadElementException" + ex);
        }

        // Second page - some elements
        // Segunda pgina - Algunos elementos

        // List by iText (listas por iText)
        String text = "test 1 2 3 ";
        for (int i = 0; i < 5; i++) {
            text = text + text;
        }
        List list = new List(List.UNORDERED);
        ListItem item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);
        text = "a b c align ";
        for (int i = 0; i < 5; i++) {
            text = text + text;
        }
        item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);
        text = "supercalifragilisticexpialidocious ";
        for (int i = 0; i < 3; i++) {
            text = text + text;
        }
        item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);

        // How to use PdfPTable
        // Utilizacin de PdfPTable

        // We use various elements to add title and subtitle
        // Usamos varios elementos para aadir ttulo y subttulo
        Anchor anchor = new Anchor("Table export to PDF (Exportamos la tabla a PDF)", categoryFont);
        anchor.setName("Table export to PDF (Exportamos la tabla a PDF)");
        Chapter chapTitle = new Chapter(new Paragraph(anchor), 1);
        Paragraph paragraph = new Paragraph("Do it by Xules (Realizado por Xules)", subcategoryFont);
        Section paragraphMore = chapTitle.addSection(paragraph);
        paragraphMore.add(new Paragraph("This is a simple example (Este es un ejemplo sencillo)"));
        Integer numColumns = 6;
        Integer numRows = 120;
        // We create the table (Creamos la tabla).
        PdfPTable table = new PdfPTable(numColumns);
        // Now we fill the PDF table 
        // Ahora llenamos la tabla del PDF
        PdfPCell columnHeader;
        // Fill table rows (rellenamos las filas de la tabla).                
        for (int column = 0; column < numColumns; column++) {
            columnHeader = new PdfPCell(new Phrase("COL " + column));
            columnHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(columnHeader);
        }
        table.setHeaderRows(1);
        // Fill table rows (rellenamos las filas de la tabla).                
        for (int row = 0; row < numRows; row++) {
            for (int column = 0; column < numColumns; column++) {
                table.addCell("Row " + row + " - Col" + column);
            }
        }
        // We add the table (Aadimos la tabla)
        paragraphMore.add(table);
        // We add the paragraph with the table (Aadimos el elemento con la tabla).
        document.add(chapTitle);
        document.close();
        System.out.println("Your PDF file has been generated!(Se ha generado tu hoja PDF!");
    } catch (DocumentException documentException) {
        System.out.println(
                "The file not exists (Se ha producido un error al generar un documento): " + documentException);
    }
}

From source file:drugsupplychain.neu.css.gui.common.distributor.GenerateBillPDF.java

/**
 * add content to the page//from  w  ww  . j  av a 2 s.  c  o  m
 * @param document
 * @throws DocumentException 
 */
private static void addContent(Document document, Order order, Distributor distributor, Address billingAddress)
        throws DocumentException {
    Paragraph paragraph = new Paragraph();
    Anchor anchor = new Anchor("DISTRIBUTOR INVOICE", catFont);
    anchor.setName("DISTRIBUTOR INVOICE");
    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);
    Paragraph subPara = new Paragraph("CUSTOMER DETAILS", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("ID: " + distributor.getOrganizationID()));
    subCatPart.add(new Paragraph("NAME: " + distributor.getName()));
    subCatPart.add(new Paragraph("LOCATION: " + distributor.getLocation()));
    subCatPart.add(new Paragraph("LICENSE NUMBER: " + distributor.getLincense().getLicenseNumber()));
    //add empty lines
    addEmptyLine(paragraph, 1);
    subCatPart.add(paragraph);
    subPara = new Paragraph("BILLING ADDRESS DETAILS", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("ADDRESS LINE 1: " + billingAddress.getAddressLine1()));
    subCatPart.add(new Paragraph("ADDRESS LINE 2: " + billingAddress.getAddressLine2()));
    subCatPart.add(new Paragraph("CITY: " + billingAddress.getCity()));
    subCatPart.add(new Paragraph("STATE: " + billingAddress.getState()));
    subCatPart.add(new Paragraph("COUNTRY: " + billingAddress.getCountry()));
    subCatPart.add(new Paragraph("ZIP CODE: " + billingAddress.getZipcode()));
    //add empty lines
    addEmptyLine(paragraph, 1);
    subCatPart.add(paragraph);
    subPara = new Paragraph("ORDER SUMMARY TABLE", subFont);
    subCatPart = catPart.addSection(subPara);
    //add empty lines
    addEmptyLine(paragraph, 1);
    subCatPart.add(paragraph);
    // add a table
    int totalPrice = createTable(subCatPart, order);
    subCatPart.add(new Paragraph("Total Price: " + totalPrice));
    subCatPart.add(new Paragraph(
            "ORDER DATE(MM/DD/YYYY): " + ImplCommonUtil.getFormattedDate(order.getCreationDate())));
    subCatPart.add(new Paragraph("BILL GENERATED BY: " + System.getProperty("user.name")));
    // now add all this to the document
    document.add(catPart);
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Factuur12", catFont);
    anchor.setName("Factuur");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    // add a list
    //createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, (int) 1);
    catPart.add(paragraph);/*w w  w . j  av  a  2 s  .  c o  m*/

    // add a table
    createTable(catPart);

    createTable2(catPart);

    createTable3(catPart);

    createTable4(catPart);

    createTable5(catPart);

    // now add all this to the document
    document.add(catPart);

}

From source file:edu.esprit.pi.gui.internalframes.PDFwithItextInternalFrame.java

public void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor(titreChapitre1jTextField.getText(), catFont);
    //anchor.setName("First Chapter");

    // le socond paramtre est le numro du chapitre.
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph(titreParagraphe1TextField.getText(), subFont);
    Section subCatPart = catPart.addSection(subPara);

    subCatPart.add(new Paragraph(descriptionjTextArea.getText()));

    // Nouvelle //w  w  w  .j av a2 s. c  o m
    Paragraph subPara2 = new Paragraph(description3jTextArea.getText(), subFont);
    Section subCatPart2 = catPart.addSection(subPara2);
    subCatPart2.add(new Paragraph(description4jTextArea.getText()));
    // Ajouter une liste de sections
    createList(subCatPart2);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 3);
    subCatPart2.add(paragraph);

    // Ajouter un tableau
    createTable(subCatPart2);

    // Ajouter tout cela au document.
    document.add(catPart);

    // Nouvelle Section    
    anchor = new Anchor(titreChapitre2jTextField.getText(), catFont);
    //anchor.setName("Second Chapter");

    // Le socond paramtre est le numro du chapitre
    catPart = new Chapter(new Paragraph(anchor), 1);
    subPara = new Paragraph(titreParagraphe2jTextField.getText(), subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph(description2jTextArea.getText()));
    // ajouter au document
    document.add(catPart);

}

From source file:Ekon.zamestnanecToPDF.java

/**
 * pridani titulku//www.ja  v a 2  s .  co  m
 *
 * @param dokument
 * @throws DocumentException
 */
private static void addTitlePage(Document document, Zamestnanec zam) throws DocumentException {
    if (zam == null) {
        System.out.println("chyba");
        return;
    }
    String jmeno = zam.getJmeno();
    String prijmeni = zam.getPrijmeni();
    String datumNarozeni = zam.getDatumNarozeni();
    String mesto = zam.getMesto();
    String ulice = zam.getUlice();
    String kraj = zam.getKraj();
    String pozice = zam.getPozice();
    Anchor anchor = new Anchor("Vypis zamestnance", catFont);
    anchor.setName("Vypis zamestnance");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Zamestnanec", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Jmeno : " + jmeno));
    subCatPart.add(new Paragraph("Prijmeni : " + prijmeni));
    subCatPart.add(new Paragraph("Datum narozeni : " + datumNarozeni));
    subCatPart.add(new Paragraph("Mesto : " + mesto));
    subCatPart.add(new Paragraph("Ulice: " + ulice));
    subCatPart.add(new Paragraph("Kraj : " + kraj));
    subCatPart.add(new Paragraph("Pozice : " + pozice));

    subPara = new Paragraph("Vypis hodin", subFont);
    subCatPart = catPart.addSection(subPara);

    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 3);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

    // now add all this to the document
    document.add(catPart);
}

From source file:eu.trentorise.smartcampus.citizenportal.service.PdfCreator.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("COMUNITA' DELLA VALLAGARINA", catFont);
    anchor.setName("COMUNITA' DELLA VALLAGARINA");
    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);
    catPart.setNumberDepth(0);//from  w  w w  . j a  v  a 2s.  c om
    Paragraph subPara = new Paragraph("Graduatoria Generale", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.setNumberDepth(0);
    Anchor phaseClass = new Anchor("Fase: " + phase, smallBold);
    Anchor state = new Anchor("Stato: Confermata", smallBold);
    Anchor edFinPer = new Anchor("Edizione: " + edFin.getPeriod(), smallBold);
    Anchor edFinCat = new Anchor("Categoria: " + edFin.getCategory(), smallBold);
    Anchor edFinTool = new Anchor("Strumento: " + edFin.getTool(), smallBold);
    // subCatPart.add(new Paragraph("Graduatoria: Generale"));
    subCatPart.add(new Paragraph(phaseClass));
    subCatPart.add(new Paragraph(state));
    subCatPart.add(new Paragraph(edFinPer));
    subCatPart.add(new Paragraph(edFinCat));
    subCatPart.add(new Paragraph(edFinTool));
    // add a list
    // createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 1);
    subCatPart.add(paragraph);
    // add a table
    createTable(subCatPart);
    // now add all this to the document
    document.add(catPart);
    // Next section
    // anchor = new Anchor("Second Chapter", catFont);
    // anchor.setName("Second Chapter");
    // Second parameter is the number of the chapter
    // catPart = new Chapter(new Paragraph(anchor), 1);
    // subPara = new Paragraph("Subcategory", subFont);
    // subCatPart = catPart.addSection(subPara);
    // subCatPart.add(new Paragraph("This is a very important message"));
    // now add all this to the document
    // document.add(catPart);
}

From source file:generadorPDF.generarPDF.java

private static void addContent(Document document, Socio sociox, Resolucion res) throws DocumentException {
       Anchor anchor = new Anchor("First Chapter", catFont);
       anchor.setName("First Chapter");

       // Second parameter is the number of the chapter
       Chapter catPart = new Chapter(new Paragraph(anchor), 1);

       Paragraph subPara = new Paragraph("Subcategory 1", subFont);
       Section subCatPart = catPart.addSection(subPara);
       subCatPart.add(new Paragraph("Hello"));
       subCatPart.add(new Paragraph(sociox.getApellido() + sociox.getNombre() + sociox.getLegajo_socio()));

       subPara = new Paragraph("Subcategory 2", subFont);
       subCatPart = catPart.addSection(subPara);
       subCatPart.add(new Paragraph("Paragraph 1"));
       subCatPart.add(new Paragraph("Paragraph 2"));
       subCatPart.add(new Paragraph("Paragraph 3"));

       // add a list
       createList(subCatPart);/*from   ww w .  java 2  s . com*/
       Paragraph paragraph = new Paragraph();
       addEmptyLine(paragraph, 5);
       subCatPart.add(paragraph);

       // add a table
       createTable(subCatPart);

       // now add all this to the document
       //document.add(catPart);

       // Next section
       anchor = new Anchor("Second Chapter", catFont);
       anchor.setName("Second Chapter");

       // Second parameter is the number of the chapter
       catPart = new Chapter(new Paragraph(anchor), 1);

       subPara = new Paragraph("Subcategory", subFont);
       subCatPart = catPart.addSection(subPara);
       subCatPart.add(new Paragraph("This is a very important message"));

       // now add all this to the document
       //document.add(catPart);

   }

From source file:has.GenerateReceipt.java

private static void addContent(Document document)
        throws DocumentException, IOException, SQLException, ClassNotFoundException {
    Anchor anchor = new Anchor("BILL DETAILS(Generated by HAS) on " + new Date(), catFont);
    // anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    addEmptyLine(preface, 2);/* ww  w . j av a2  s. c o m*/

    Statement stmt = null, stmt1 = null, stmt2 = null, stmt3 = null, stmt4 = null, stmt5 = null;
    Connection conn = null;
    String w = null;
    int found = 0;
    // System.out.println("At the start");
    try {
        conn = DriverManager.getConnection(url, user, password);
        stmt = conn.createStatement();
        stmt1 = conn.createStatement();
        stmt2 = conn.createStatement();
        stmt3 = conn.createStatement();
        stmt4 = conn.createStatement();
        stmt5 = conn.createStatement();
        // stmt1 = conn.createStatement();
    } catch (Exception rx) {
        System.out.println("in catch");
    }
    int present = 0;
    double minfre = 0;

    String sql2 = "SELECT id,Value FROM central";
    Vector tariff = null, discount = null, rates = null, totalbookings = null;
    ResultSet rsz = stmt.executeQuery(sql2);
    int iad;
    while (rsz.next()) {
        iad = rsz.getInt("id");

        if (iad == 9) {
            minfre = rsz.getDouble("Value");
        }
        if (iad == 10) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            tariff = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                tariff = (Vector) o.readObject();
            }
        }
        if (iad == 11) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            rates = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                rates = (Vector) o.readObject();
            }
        }

        if (iad == 12) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            totalbookings = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                totalbookings = (Vector) o.readObject();
            }
        }

        if (iad == 13) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            discount = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                discount = (Vector) o.readObject();
            }
        }

        if (iad == 14) {
            present = rsz.getInt("Value");
        }

    }

    String sql = "SELECT * FROM Customer ";
    ResultSet rs = null, rs1 = null;
    try {
        rs = stmt.executeQuery(sql);
    } catch (SQLException ex) {
        Logger.getLogger(CheckOut.class.getName()).log(Level.SEVERE, null, ex);
    }
    while (rs.next()) {
        int x = rs.getInt("ISAC");
        if (x == 2) {
            int y = rs.getInt("SCOD");
            if (present == y) {
                double Totalbill = 0, amount = 0;
                ObjectInputStream o = null;
                byte[] arr = rs.getBytes("Catering");
                Vector Catering = new Vector();
                if (arr != null) {
                    o = new ObjectInputStream(new ByteArrayInputStream(arr));
                    Catering = (Vector) o.readObject();
                }

                Paragraph subPara2 = new Paragraph(rs.getString("Name") + "  " + rs.getString("I"), subFont);
                Section subCatPart = catPart.addSection(subPara2);
                // Section subCatPart2 = catPart.addSection(subPara2);
                if (Catering.size() != 0) {

                    createTable(subCatPart, Catering);
                    System.out.println("Enterte in catering");
                    CateringObject obj = (CateringObject) Catering.elementAt(0);
                    Totalbill = obj.bill;
                    //    tb.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                    for (int f = 1; f < Catering.size(); f++) {
                        obj = (CateringObject) Catering.elementAt(f);
                        //    tb.addRow(new Object[]{new String(""),new String(""),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                        Totalbill = Totalbill + obj.bill;
                    }
                    String updatestr = "UPDATE customer SET Catering = ?  WHERE id = " + rs.getInt("id");
                    PreparedStatement p = conn.prepareStatement(updatestr);
                    p.setObject(1, null);
                    p.executeUpdate();
                }
                int ap1 = rs.getInt("SCOD") - rs.getInt("SCID") + 1;
                int ap = rs.getInt("History") + ap1;
                System.out.println("ap1=" + ap1);
                System.out.println("ap=" + ap);
                sql = "UPDATE customer SET history= " + ap + " WHERE id= " + rs.getInt("id");
                System.out.println(sql);
                stmt1.executeUpdate(sql);
                sql = "UPDATE customer SET ISAC= 0 WHERE id= " + rs.getInt("id");
                System.out.println(sql);
                stmt5.executeUpdate(sql);
                int to = 0;
                String room = rs.getString("Room");
                String roompart = room.substring(0, 2);
                double roomrent = 0, tariffa = 0, discounta = 0, advance = 0;
                advance = rs.getDouble("RTP");
                System.out.println(roompart);
                if (roompart.equalsIgnoreCase("SA")) {
                    amount = ap1 * (int) rates.elementAt(0);
                    roomrent = amount;
                    System.out.println("roomrent=" + roomrent);
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(0)) / 100;
                    amount = amount + tariffa;
                    to = (int) totalbookings.elementAt(0);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 0);
                }

                if (roompart.equalsIgnoreCase("SNA")) {
                    amount = ap1 * (int) rates.elementAt(1);
                    roomrent = amount;
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(1)) / 100;
                    amount = amount + (amount * (double) tariff.elementAt(1)) / 100;
                    to = (int) totalbookings.elementAt(1);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 1);
                }
                if (roompart.equalsIgnoreCase("DA")) {
                    amount = ap1 * (int) rates.elementAt(2);
                    roomrent = amount;
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(2)) / 100;
                    amount = amount + (amount * (double) tariff.elementAt(2)) / 100;
                    to = (int) totalbookings.elementAt(2);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 2);
                }
                if (roompart.equalsIgnoreCase("DNA")) {
                    amount = ap1 * (int) rates.elementAt(3);
                    roomrent = amount;
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(3)) / 100;
                    amount = amount + (amount * (double) tariff.elementAt(3)) / 100;
                    to = (int) totalbookings.elementAt(3);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 3);
                }
                String updatestr = "UPDATE central SET Value = ?  WHERE id =12 ";
                PreparedStatement p = conn.prepareStatement(updatestr);
                p.setObject(1, totalbookings);
                p.executeUpdate();
                int history = rs.getInt("history");
                double cusfre = history / present;
                double minfree = (double) discount.elementAt(0);
                double minbill = (double) discount.elementAt(1);
                double d1 = (double) discount.elementAt(2);
                double d2 = (double) discount.elementAt(3);
                double d3 = (double) discount.elementAt(4);
                double d4 = (double) discount.elementAt(5);

                if (cusfre < minfree && amount < minbill) {
                    discounta = (amount * d1) / 100;
                    amount = amount - discounta;
                }
                if (cusfre < minfree && amount > minbill) {
                    discounta = (amount * d2) / 100;
                    amount = amount - discounta;
                }
                if (cusfre > minfree && amount < minbill) {
                    discounta = (amount * d3) / 100;
                    amount = amount - discounta;
                }
                if (cusfre > minfree && amount > minbill) {
                    discounta = (amount * d4) / 100;
                    amount = amount - discounta;
                }
                amount = amount - advance;
                //  tb2.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new Double(Totalbill),new Double(advance),new Double(roomrent),new Double(tariffa),new Double(discounta),new Double(amount)});
            }
        }
        if (x == 1) {
            Vector advancev = null, ecid = null, ecod = null, advanceroom = null;
            ObjectInputStream o = null;
            byte[] arr = rs.getBytes("Advance");
            advancev = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                advancev = (Vector) o.readObject();
            }
            byte[] arr2 = rs.getBytes("Advance_room");
            advanceroom = new Vector();
            if (arr2 != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr2));
                advanceroom = (Vector) o.readObject();
            }
            byte[] arr3 = rs.getBytes("ECID");
            ecid = new Vector();
            if (arr3 != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr3));
                ecid = (Vector) o.readObject();
            }
            byte[] arr4 = rs.getBytes("ECOD");
            ecod = new Vector();
            if (arr4 != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr4));
                ecod = (Vector) o.readObject();
            }

            for (int l = 0; l < ecod.size(); l++) {
                long y = (long) ecod.elementAt(l);
                if (present == y) {
                    double Totalbill = 0, amount = 0;
                    //  ObjectInputStream o = null;
                    byte[] arr1 = rs.getBytes("Catering");
                    Vector Catering = new Vector();
                    if (arr1 != null) {
                        o = new ObjectInputStream(new ByteArrayInputStream(arr1));
                        Catering = (Vector) o.readObject();
                    }
                    Paragraph subPara2 = new Paragraph(rs.getString("Name") + "  " + rs.getString("I"),
                            subFont);
                    Section subCatPart = catPart.addSection(subPara2);
                    if (Catering.size() != 0) {
                        createTable(subCatPart, Catering);
                        CateringObject obj = (CateringObject) Catering.elementAt(0);
                        Totalbill = obj.bill;
                        //tb.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                        for (int f = 1; f < Catering.size(); f++) {
                            obj = (CateringObject) Catering.elementAt(f);
                            //  tb.addRow(new Object[]{new String(""),new String(""),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                            Totalbill = Totalbill + obj.bill;
                        }
                        String updatestr = "UPDATE customer SET Catering = ?  WHERE id = " + rs.getInt("id");
                        PreparedStatement p = conn.prepareStatement(updatestr);
                        p.setObject(1, null);
                        p.executeUpdate();
                    }

                    System.out.println("l == " + l);
                    System.out.println("size = " + ecod.size());
                    System.out.println(ecod);
                    System.out.println(ecid);
                    long ppp = (long) ecod.get(l);
                    long qqq = (long) ecid.get(l);
                    System.out.println("ecod = " + ppp);
                    System.out.println("ecid = " + qqq);
                    long ap1 = ppp - qqq + 1;
                    // sql="UPDATE customer SET ISAC=0 WHERE id= "+rs.getInt("id");
                    // stmt3.executeUpdate(sql);

                    int ap = rs.getInt("History") + (int) ap1;
                    sql = "UPDATE customer SET history=" + ap + " WHERE id= " + rs.getInt("id");
                    stmt4.executeUpdate(sql);

                    int to = 0;
                    String room = (String) advanceroom.elementAt(l);
                    String roompart = room.substring(0, 1);
                    double roomrent = 0, tariffa = 0, discounta = 0, advance = 0;
                    advance = Double.parseDouble((String) advancev.elementAt(l));
                    if (roompart.equalsIgnoreCase("SA")) {
                        amount = ap1 * (int) rates.elementAt(0);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(0)) / 100;
                        amount = amount + tariffa;
                        to = (int) totalbookings.elementAt(0);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 0);
                    }

                    if (roompart.equalsIgnoreCase("SNA"))
                        amount = (double) rates.elementAt(1);
                    {
                        amount = ap1 * (int) rates.elementAt(1);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(1)) / 100;
                        amount = amount + (amount * (double) tariff.elementAt(1)) / 100;
                        to = (int) totalbookings.elementAt(1);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 1);
                    }
                    if (roompart.equalsIgnoreCase("DA")) {
                        amount = ap1 * (int) rates.elementAt(2);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(2)) / 100;
                        amount = amount + (amount * (double) tariff.elementAt(2)) / 100;
                        to = (int) totalbookings.elementAt(2);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 2);
                    }
                    if (roompart.equalsIgnoreCase("DNA")) {
                        amount = ap1 * (int) rates.elementAt(3);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(3)) / 100;
                        amount = amount + (amount * (double) tariff.elementAt(3)) / 100;
                        to = (int) totalbookings.elementAt(3);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 3);
                    }
                    String updatestr = "UPDATE central SET Value = ?  WHERE id =12 ";
                    PreparedStatement p = conn.prepareStatement(updatestr);
                    p.setObject(1, totalbookings);
                    p.executeUpdate();
                    int history = rs.getInt("history");
                    double cusfre = history / present;
                    double minfree = (double) discount.elementAt(0);
                    double minbill = (double) discount.elementAt(1);
                    double d1 = (double) discount.elementAt(2);
                    double d2 = (double) discount.elementAt(3);
                    double d3 = (double) discount.elementAt(4);
                    double d4 = (double) discount.elementAt(5);

                    if (cusfre < minfree && amount < minbill) {
                        discounta = (amount * d1) / 100;
                        amount = amount - discounta;
                    }
                    if (cusfre < minfree && amount > minbill) {
                        discounta = (amount * d2) / 100;
                        amount = amount - discounta;
                    }
                    if (cusfre > minfree && amount < minbill) {
                        discounta = (amount * d3) / 100;
                        amount = amount - discounta;
                    }
                    if (cusfre > minfree && amount > minbill) {
                        discounta = (amount * d4) / 100;
                        amount = amount - discounta;
                    }
                    amount = amount - advance;
                    //   tb2.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new Double(Totalbill),new Double(advance),new Double(roomrent),new Double(tariffa),new Double(discounta),new Double(amount)});
                }
            }
        }
        // add a table
        //createTable(subCatPart);
    }
    Paragraph subPara2 = new Paragraph("Thanks for choosing us .. please visit again", subFont);
    Section subCatPart2 = catPart.addSection(subPara2);
    /* Anchor anchor2 = new Anchor("Thanks for choosing us .. please visit again", catFont);
     Chapter catPart2 = new Chapter(new Paragraph(anchor), 1);*/

    // now add all this to the document
    document.add(catPart);
    //document.add(catPart2);

}

From source file:klasy.PdfFiles.java

public static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // add a list
    createList(subCatPart);/*from  ww w .j av  a 2s.  c  o  m*/
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    //createTable(subCatPart);

    // now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    document.add(catPart);

}

From source file:negotiation.Contract.FormContractPdf.java

public static void addContents(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Contract", catFont);
    anchor.setName("Contract");

    Paragraph para = new Paragraph();
    para.add(new Paragraph("1. General", subFont));
    String para1 = ContractContents.addGeneral("userA", "ManagerD", "aws", "2014", "2015");
    para.add(para1);//  w  w w  .ja v  a  2  s . c om
    addEmptyLine(para, 1);

    para.add(new Paragraph("2. Scope & description of the service", subFont));
    String para2 = ContractContents.addDescription("aws-ec2", "www.aws.com", "computing service");
    para.add(para2);

    para.add(new Paragraph("3. Service hours & exceptions", subFont));
    String para3 = ContractContents.addTime("2014", "2015");
    para.add(para3);

    para.add(new Paragraph("4. Service components & dependencies", subFont));
    String para4 = ContractContents.addComponents("aws-ec2", "computing service");
    para.add(para4);

    para.add(new Paragraph("5. Support", subFont));
    String para5 = ContractContents.addSupport("University of Manchester", "Mon-Fri: 9:00am - 5:00pm");
    para.add(para5);

    para.add(new Paragraph("5.1 Incident handling", smallBold));
    String para6 = ContractContents.addHandling("Incident handling ...");
    para.add(para6);

    para.add(new Paragraph("5.2 Fulfillment of service requests", smallBold));
    String para7 = ContractContents.addFulfillment("Fulfillment ...");
    para.add(para7);

    para.add(new Paragraph("6. Service level targets", subFont));
    String para8 = AwsEc2ContractContents.addTargets();
    //String para8 = ContractContents.addTargets("Availability", "24 hours");
    para.add(para8);

    para.add(new Paragraph("7. Limitations & constaints", subFont));
    String para9 = AwsEc2ContractContents.addConstaints();
    //String para9 = ContractContents.addConstaints("Wordload limits...");
    para.add(para9);

    para.add(new Paragraph("8. Communication, reporting & escalation", subFont));
    para.add(new Paragraph("8.1 General communication", smallBold));
    String para10 = ContractContents.addContacts("123", "456", "789");
    para.add(para10);

    para.add(new Paragraph("8.2 Regular reporting", smallBold));
    String para11 = ContractContents.addReport("20150520", "regular check", "once a week",
            "University of Manchester.");
    para.add(para11);

    para.add(new Paragraph("8.3 SLA violations", smallBold));
    String para12 = AwsEc2ContractContents.addViolations();
    //String para12 = ContractContents.addViolations("Penalty required when performance cannot rearch agreed SLAs.");
    para.add(para12);

    para.add(new Paragraph("8.4 Escalation & complaints", smallBold));
    String para13 = ContractContents
            .addEscalation("Please contact University of Manchester via provided email.");
    para.add(para13);

    para.add(new Paragraph("9. Information security & data protection", subFont));
    String para14 = ContractContents
            .addProtection("All the data should be kept within University of Manchester network domain.");
    para.add(para14);

    para.add(new Paragraph("10. Additional responsibilities of the service provider", subFont));
    String para15 = ContractContents.addProviderResp("Provider should ...");
    para.add(para15);

    para.add(new Paragraph("11. Customer responsibilities", subFont));
    String para16 = ContractContents.addCustomerResp("Customer should ...");
    para.add(para16);

    para.add(new Paragraph("12. Review", subFont));
    String para17 = ContractContents.addReview("Review should be taken...");
    para.add(para17);

    para.add(new Paragraph("13. Glossary of terms", subFont));
    String para18 = AwsEc2ContractContents.addTerms();
    //String para18 = ContractContents.addTerms("aws-ec2", "computing services");
    para.add(para18);

    para.add(new Paragraph("14. Document control", subFont));
    String para19 = ContractContents.addControl(55555, "SLA on" + glo_service, "University of Manchester",
            "University of Manchester", "1.0", "2015", "2016", "No change so far");
    para.add(para19);

    document.add(para);
}