Example usage for com.itextpdf.text.pdf PdfPCell addElement

List of usage examples for com.itextpdf.text.pdf PdfPCell addElement

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell addElement.

Prototype

public void addElement(Element element) 

Source Link

Document

Adds an iText element to the cell.

Usage

From source file:pipe.PdfMaker.java

private Element ninethElement(String kaufpreis, String gekauft_bei, String datum) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);//from   w  ww. jav a 2s . co  m
    PdfPCell cell;
    //Hier die Header zuerst
    cell = new PdfPCell(new Paragraph("Einstandspreis", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Gekauft bei / von", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Kaufdatum", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    //Ab hier die Werte
    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph herkunftInfo = new Paragraph(kaufpreis, courier);
    herkunftInfo.setLeading(leading);
    cell.addElement(herkunftInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph editionInfo = new Paragraph(gekauft_bei, courier);
    editionInfo.setLeading(leading);
    cell.addElement(editionInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph yearInfo = new Paragraph(datum, courier);
    yearInfo.setLeading(leading);
    cell.addElement(yearInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element tenthElement(String verkaufspreis, String verkauft_an, String datum) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);//w  w w. j a v a 2  s . c o  m
    PdfPCell cell;
    //Hier die Header zuerst
    cell = new PdfPCell(new Paragraph("Verkaufspreis", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Verkauft an", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Verkaufsdatum", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    //Ab hier die Werte
    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph herkunftInfo = new Paragraph(verkaufspreis, courier);
    herkunftInfo.setLeading(leading);
    cell.addElement(herkunftInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph editionInfo = new Paragraph(verkauft_an, courier);
    editionInfo.setLeading(leading);
    cell.addElement(editionInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph yearInfo = new Paragraph(datum, courier);
    yearInfo.setLeading(leading);
    cell.addElement(yearInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element eleventhElement(String oberflaeche, String bohrung, String filter) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);//from w  w w. j  a  va2  s  .co m
    PdfPCell cell;
    //Hier die Header zuerst
    cell = new PdfPCell(new Paragraph("Oberflche", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Bohrung", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Filter", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    //Ab hier die Werte
    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph herkunftInfo = new Paragraph(oberflaeche, courier);
    herkunftInfo.setLeading(leading);
    cell.addElement(herkunftInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph editionInfo = new Paragraph(bohrung, courier);
    editionInfo.setLeading(leading);
    cell.addElement(editionInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(18f);
    Paragraph yearInfo = new Paragraph(filter, courier);
    yearInfo.setLeading(leading);
    cell.addElement(yearInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element twelvethElement(String laenge, String kopfhoehe, String kopfdurchmesser) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);//  www  . j ava2s.  c o  m
    PdfPCell cell;
    //Hier die Header zuerst
    cell = new PdfPCell(new Paragraph("Lnge", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Kopfhhe", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Kopfdurchmesser", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    //Ab hier die Werte
    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph herkunftInfo = new Paragraph(laenge, courier);
    herkunftInfo.setLeading(leading);
    cell.addElement(herkunftInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    Paragraph editionInfo = new Paragraph(kopfhoehe, courier);
    editionInfo.setLeading(leading);
    cell.addElement(editionInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(18f);
    Paragraph yearInfo = new Paragraph(kopfdurchmesser, courier);
    yearInfo.setLeading(leading);
    cell.addElement(yearInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element thirteenthElement(String gewicht, String farbe) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);//from   w w  w.  j  a v  a 2s .c o  m
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Gewicht", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Farbe", arialSmall));
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setGrayFill(0.85f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(18f);
    Paragraph mundMatInfo = new Paragraph(gewicht, courier);
    mundMatInfo.setLeading(leading);
    cell.addElement(mundMatInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(18f);
    Paragraph modellInfo = new Paragraph(farbe, courier);
    modellInfo.setLeading(leading);
    cell.addElement(modellInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element fourteenthElement(String zustand, String lagerort) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);//  w  w w.j  a  va2 s  .  c o  m
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Zustand", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Lagerort", arialSmall));
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setGrayFill(0.85f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(18f);
    Paragraph mundMatInfo = new Paragraph(zustand, courier);
    mundMatInfo.setLeading(leading);
    cell.addElement(mundMatInfo);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(18f);
    Paragraph modellInfo = new Paragraph(lagerort, courier);
    modellInfo.setLeading(leading);
    cell.addElement(modellInfo);
    table.addCell(cell);

    return table;
}

From source file:pipe.PdfMaker.java

private Element fifteenthElement(String besonderes) {
    float leading = 9f;
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);//from w  w w .j av a 2s . co m
    PdfPCell cell;

    cell = new PdfPCell(new Paragraph("Besonderes", arialSmall));
    cell.setPadding(2);
    cell.setGrayFill(0.85f);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(2);
    cell.setBorderWidth(0.3f);
    cell.setFixedHeight(30f);
    Paragraph herstellerInfo = new Paragraph(besonderes, courier);
    herstellerInfo.setLeading(leading);
    cell.addElement(herstellerInfo);
    table.addCell(cell);

    return table;
}

From source file:Print.Print.java

public void printIndex(ArrayList<String> imagesPath, String customer) {
    try {/*from w  w w  .j  a  v  a 2s .c o  m*/
        //ArrayList<Image> images = new ArrayList<Image>();
        Map<Image, String> dict = new HashMap<Image, String>();
        for (String path : imagesPath) {
            try {
                System.out.println("path = /home/student" + path);
                int index = path.lastIndexOf("/");
                String photoId = path.substring(index + 1, path.length());
                Image newImage = Image.getInstance("/home/student" + path);
                //images.add(newImage);
                dict.put(newImage, photoId);
            } catch (BadElementException ex) {
                Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        System.out.println("Total images = " + dict.size());
        Document index = new Document(PageSize.A4.rotate());
        FileOutputStream fos = new FileOutputStream("/home/student/Pictures/index.pdf");
        PdfWriter writer = PdfWriter.getInstance(index, fos);
        writer.open();
        index.open();

        PdfPTable adresTable = new PdfPTable(3);
        PdfPCell adresCell = new PdfPCell(new Paragraph(customer));
        adresCell.setColspan(3);
        adresTable.addCell(adresCell);
        adresTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        adresTable.setWidthPercentage(100);
        index.add(adresTable);
        PdfPTable table = new PdfPTable(imagesPath.size());

        for (Map.Entry<Image, String> image : dict.entrySet()) {
            PdfPCell cell = new PdfPCell();
            table.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.setWidthPercentage(10);
            table.addCell(image.getValue());
            cell.addElement(image.getKey());
            table.addCell(cell);

        }
        index.add(table);
        //index.add(adresTable);
        index.close();
        writer.close();
        System.out.println("Index printed");

        //        // define pdfprinter and within try clause create
        //        PdfWriter writer = null;
        //        FileOutputStream fos = null;
        //        Document index = new Document(PageSize.A4.rotate());
        //        File file;
        //        try {
        //            file = new File("/home/student/Pictures/index.pdf");
        //            if(!file.exists()){
        //                file.createNewFile();
        //                
        //            }
        //            String test = "test data";
        //            fos = new FileOutputStream(file);
        //            fos.write(test.getBytes());
        //            fos.flush();
        //        } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
        //        } catch (IOException ex) {
        //            Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
        //        }
        //
        //        for (BufferedImage image : bufferedImages) {            
        //                try {
        //                    writer = PdfWriter.getInstance(index, fos);
        //                } catch (DocumentException ex) {
        //                    System.out.println(ex.getMessage());
        //                }
        //                writer.open();
        //                index.open();
        //                try {
        //                    PdfContentByte pdfCB = new PdfContentByte(writer);
        //                    Image newImage = Image.getInstance(pdfCB, image, 1);
        //                    index.add(Image.getInstance(newImage));
        //                } catch (DocumentException ex) {
        //                    System.out.println(ex.getMessage());
        //                } catch (IOException ex) {
        //                Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
        //            }
        //        }
        //        index.close();
        //        writer.close();
        //        System.out.println("Index done.");
    } catch (DocumentException ex) {
        Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:py.com.palermo.imprimeetiquetas.web.ProductoController.java

public String createPdf() throws IOException, DocumentException {

    if (hayParaImprimir()) {

        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                .getExternalContext().getResponse();
        response.setContentType("application/x-pdf");
        response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\"");

        // step 1
        Document document = new Document(new Rectangle(86, 35));
        // step 2

        document.setMargins(0f, 0f, 0f, 0f);

        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
        // step 3
        document.open();//w  w w. ja  v  a 2s .com

        // step 4
        PdfContentByte cb = writer.getDirectContent();

        for (ProductoCantidad p : productos) {
            if (p.getCantidad() > 0) {

                BarcodeEAN codeEAN = new BarcodeEAN();
                codeEAN.setCode(p.getCodigo());
                codeEAN.setCodeType(Barcode.EAN13);
                codeEAN.setBarHeight(10f);
                codeEAN.setX(0.7f);
                codeEAN.setSize(4f);

                NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("es", "py"));
                Font fontbold = FontFactory.getFont("Times-Roman", 5, Font.NORMAL);
                Chunk productTitle = new Chunk(p.getNombre() + "," + " " + nf.format(p.getPrecio()), fontbold);

                // EAN 13
                Paragraph pTitile = new Paragraph(productTitle);
                pTitile.setAlignment(Element.ALIGN_CENTER);
                pTitile.setLeading(0, 1);

                PdfPTable table = new PdfPTable(1);
                table.setPaddingTop(0f);

                table.setWidthPercentage(96);
                PdfPCell cell = new PdfPCell();
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setBorder(Rectangle.NO_BORDER);
                cell.addElement(codeEAN.createImageWithBarcode(cb, null, BaseColor.BLACK));

                table.addCell(cell);

                PdfPCell cell2 = new PdfPCell();
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setBorder(Rectangle.NO_BORDER);
                cell2.addElement(pTitile);

                table.addCell(cell2);

                for (int i = 0; i < p.getCantidad(); i++) {
                    document.add(table);
                    document.newPage();
                }
            }
        }

        // step 5
        document.close();

        response.getOutputStream().flush();
        response.getOutputStream().close();
        FacesContext.getCurrentInstance().responseComplete();
    } else {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", ""));
    }
    return null;
}

From source file:ReportGeneration.GenerateReport.java

public void print() {

    FileOutputStream fileOut = null;
    try {//from   w w w .j  a  v  a  2  s.  co  m
        Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50);
        //Document document = new Document(); //Create PDF cocument
        fileOut = new FileOutputStream(new File("report.pdf"));
        PdfWriter writer = PdfWriter.getInstance(document, fileOut);
        document.open(); //Open the document for writting
        PdfPTable table = new PdfPTable(5); //Create a table with 7 columns. 6 the first column
        //is for labeling the day, and the rest are for displaying actual time table entries.
        document.add(new Paragraph("  RFID ATTENDANCE SYSTEM  "));
        table.setWidthPercentage(100);
        PdfPCell cell;
        cell = new PdfPCell();
        cell.setColspan(1);
        cell.addElement(new Phrase("S/N"));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(new Phrase("Name"));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(new Phrase("Matricule Number"));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(new Phrase("Date"));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(new Phrase("Time"));
        table.addCell(cell);
        int i = 0;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

        String date2 = df.format(jXDatePicker2.getDate()).toString();
        String date3 = df.format(jXDatePicker3.getDate()).toString();

        genReport = DataBase.getInstance();
        genReport.connect();
        String query = "select `registered personel`.Name, `registered personel`.Matricule_Number, `Attendance Record`.Date, `Attendance Record`.Time from `Registered Personel` join `Attendance Record` on `registered personel`.Tag_ID =`Attendance Record`.`Registered Personel_Tag_ID`  where Date>='"
                + date2 + "' AND Date<='" + date3 + "'";

        genReport.query(query);

        records = genReport.getResultSet();
        while (records.next()) {
            studName = records.getString(1);
            cell = new PdfPCell();
            cell.addElement(new Phrase("" + i));
            table.addCell(cell);
            cell = new PdfPCell();
            cell.addElement(new Phrase(records.getString(1)));
            table.addCell(cell);
            cell = new PdfPCell();
            cell.addElement(new Phrase(records.getString(2)));
            table.addCell(cell);
            cell = new PdfPCell();
            cell.addElement(new Phrase(records.getString(3)));
            table.addCell(cell);
            cell = new PdfPCell();
            cell.addElement(new Phrase(records.getString(4)));
            table.addCell(cell);
            i++;
        }
        document.add(table);
        document.close();
    } catch (Exception ex) {
        Logger.getLogger(GenerateReport.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            fileOut.close();
        } catch (IOException ex) {
            Logger.getLogger(GenerateReport.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}