Example usage for com.itextpdf.text.pdf PdfPTable writeSelectedRows

List of usage examples for com.itextpdf.text.pdf PdfPTable writeSelectedRows

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable writeSelectedRows.

Prototype

public float writeSelectedRows(final int rowStart, final int rowEnd, final float xPos, final float yPos,
        final PdfContentByte canvas) 

Source Link

Document

Writes the selected rows to the document.

Usage

From source file:Almacen.Responsiva.java

private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed
    // TODO add your handling code here:
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from  w  w w.  j  av  a 2 s  . c o m*/
        String empleado = "";
        String puesto = "";
        if (t_datos.getRowCount() > 0) {
            //consulta
            Query q = session.createSQLQuery(
                    "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado="
                            + t_id_empleado.getText() + ";");
            q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
            List lista = q.list();

            for (int i = 0; i < lista.size(); i++) {
                java.util.HashMap map = (java.util.HashMap) lista.get(i);
                empleado = (String) map.get("empleado");
                puesto = (String) map.get("puesto");
            }

            Date fecha = new Date();
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
            String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto",
                    "Septiembre", "Octubre", "Noviembre", "Diciembre" };
            Calendar fecha1 = new GregorianCalendar();
            int anio = fecha1.get(Calendar.YEAR);
            int mes = fecha1.get(Calendar.MONTH);
            int dia = fecha1.get(Calendar.DAY_OF_MONTH);
            //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
            String valor = dateFormat.format(fecha);
            File folder = new File("reportes/Responsivas");
            folder.mkdirs();
            PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf");
            PdfStamper stamp = new PdfStamper(reader,
                    new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"));
            PdfContentByte cb = stamp.getUnderContent(1);
            PdfContentByte cb2 = stamp.getUnderContent(2);
            AcroFields fdfDoc = stamp.getAcroFields();
            // Creo una fuente
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

            cb.beginText();
            //dia
            try {
                if (dia < 9)
                    fdfDoc.setField("Dia", "0" + String.valueOf(dia));
                else
                    fdfDoc.setField("Dia", String.valueOf(dia));
            } catch (Exception e) {
                fdfDoc.setField("Dia", "error");
            }
            //mes
            try {
                fdfDoc.setField("Mes", Mes[mes]);
            } catch (Exception e) {
                fdfDoc.setField("Mes", "");
            }
            //ao
            try {
                fdfDoc.setField("Anio", String.valueOf(anio));
            } catch (Exception e) {
                fdfDoc.setField("Anio", "");
            }
            //nombre
            try {
                fdfDoc.setField("Nombre", empleado);
            } catch (Exception e) {
                fdfDoc.setField("Nombre", "");
            }
            //puesto
            try {
                fdfDoc.setField("Puesto", puesto);
            } catch (Exception e) {
                fdfDoc.setField("Puesto", "");
            }

            //tabla de herramientas
            float tam[] = new float[] { 250, 50, 180 };
            Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
            PDF reporte = new PDF();
            PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT);
            tabla.setTotalWidth(tam);
            BaseColor cabecera = BaseColor.GRAY;
            BaseColor contenido = BaseColor.WHITE;
            int centro = Element.ALIGN_CENTER;
            int izquierda = Element.ALIGN_LEFT;
            int derecha = Element.ALIGN_RIGHT;

            tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

            for (int i = 0; i < t_datos.getRowCount(); i++) {
                tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0,
                        1, Rectangle.RECTANGLE));

                tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido,
                        centro, 0, 1, Rectangle.RECTANGLE));
                if (t_datos.getValueAt(i, 3) != null)
                    tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda,
                            0, 1, Rectangle.RECTANGLE));
                else
                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
            }

            tabla.completeRow();
            tabla.writeSelectedRows(0, -1, 70, 720, cb2);
            cb.endText();
            stamp.close();
            reporte.cerrar();
            reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf");
        } else {
            JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva");
        }
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null) {
        if (session.isOpen()) {
            session.close();
        }
    }
}

From source file:cl.preguntame.clases.Cabecera.java

/**
 * Esta es el metodo a llamar cuando ocurra el evento onEndPage, es en este
 * evento donde crearemos el encabeazado de la pagina con los elementos
 * indicados./*from w w w . j  a  v  a  2 s.  c o m*/
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        // Se determina el ancho y altura de la tabla 
        table.setWidths(new int[] { 24, 24, 2 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);

        // Borde de la celda
        table.getDefaultCell().setBorder(Rectangle.BOTTOM);

        table.addCell(encabezado);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        table.addCell(String.format("Pagina % 01d de ", writer.getPageNumber()));

        PdfPCell cell = new PdfPCell(Image.getInstance(total));

        cell.setBorder(Rectangle.BOTTOM);

        table.addCell(cell);
        // Esta linea escribe la tabla como encabezado
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java

License:Apache License

/**
 * header ? footer  /*from   w w w .  ja  v  a 2  s .  c  o m*/
 */
public void onEndPage(PdfWriter writer, Document document) {

    if (titleFlag)
        return;

    Font font = new Font(bfKorean, 9);
    PdfPTable hTable = new PdfPTable(1);
    PdfPTable ftable = new PdfPTable(3);
    try {

        hTable.setWidths(new int[] { 100 });
        hTable.setTotalWidth(500);
        hTable.setLockedWidth(true);
        hTable.getDefaultCell().setFixedHeight(15);
        hTable.getDefaultCell().setBorder(Rectangle.BOTTOM);
        hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font));
        hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent());

        ftable.setWidths(new int[] { 100, 100, 100 });
        ftable.setTotalWidth(500);
        ftable.setLockedWidth(true);
        ftable.getDefaultCell().setBorder(Rectangle.TOP);
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font));
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        if (pagingFlag)
            ftable.addCell(new Phrase(
                    MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())),
                    font));
        else
            ftable.addCell("");

        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font));
        ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent());
    } catch (Exception de) {
        throw new ExceptionConverter(de);
    }
}

From source file:com.automaster.autoview.server.servlet.TableHeader.java

/**
 * Adds a header to every page/*from w ww .j  a v a  2s.  c o m*/
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        table.setWidths(new int[] { 24, 24, 2 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);
        table.getDefaultCell().setBorder(Rectangle.BOTTOM);
        table.addCell(header);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(String.format("Pgina %d de", writer.getPageNumber()));
        PdfPCell cell = new PdfPCell(Image.getInstance(total));
        cell.setBorder(Rectangle.BOTTOM);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:com.example.admin.avoidq.billGenerated.java

private void generatePDF(final String personName) {
    new Thread(new Runnable() {
        public void run() {
            // a potentially  time consuming task

            //create a new document
            Document document = new Document();

            try {

                PdfWriter docWriter = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
                document.open();/*from   w w  w.  j av  a  2 s .c  o  m*/

                PdfContentByte cb = docWriter.getDirectContent();
                //initialize fonts for text printing
                initializeFonts();

                //the company logo is stored in the assets which is read only
                //get the logo and print on the document
                /*
                try {
                        
                bitmap11 = encodeAsBitmap(barcode_data, BarcodeFormat.CODE_128, 600, 300);
                iv.setImageBitmap(bitmap11);
                        
                } catch (WriterException e) {
                e.printStackTrace();
                }
                * */
                InputStream inputStream = getAssets().open("sale.png");

                Bitmap bmp = null;//BitmapFactory.decodeStream(inputStream);
                bmp = bitmap11;
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

                Image companyLogo = Image.getInstance(stream.toByteArray());
                companyLogo.setAbsolutePosition(25, 700);
                companyLogo.scalePercent(65);
                document.add(companyLogo);
                Calendar calendar = Calendar.getInstance();
                SimpleDateFormat df1 = new SimpleDateFormat("dd-MM-yyyy");
                String formattedDate = df1.format(calendar.getTime());

                //creating a sample invoice with some customer data
                createHeadings(cb, 400, 780, "Date :");
                createHeadings(cb, 430, 780, formattedDate);

                String fname = customer.getName();
                String lname = customer.getSurname();
                createHeadings(cb, 400, 765, "Customer :");
                createHeadings(cb, 445, 765, fname + " " + lname);

                String mob = customer.getMobile_no();
                createHeadings(cb, 400, 750, "Mobile No :");
                createHeadings(cb, 445, 750, mob);

                createHeadings(cb, 400, 735, "Shop :");
                createHeadings(cb, 430, 735, "Empress Mall");

                createHeadings(cb, 400, 720, "City :");
                createHeadings(cb, 430, 720, "Nagpur");
                // createHeadings(cb,400,720,"Country");

                //list all the products sold to the customer
                float[] columnWidths = { 1.5f, 3f, 2.5f, 2.5f, 2f, 2f };
                //create PDF table with the given widths
                PdfPTable table = new PdfPTable(columnWidths);
                // set table width a percentage of the page width
                table.setTotalWidth(500f);

                PdfPCell cell = new PdfPCell(new Phrase("S.NO"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Item Name"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Price"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Quantity"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Discount"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Amount"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                table.setHeaderRows(1);

                /*DecimalFormat df = new DecimalFormat("0.000");
                for(int i=0; i < 10; i++ ){
                    double price = Double.valueOf(df.format(Math.random() * 10));
                    double extPrice = price * (i+1) ;
                    table.addCell(String.valueOf(i+1));
                    table.addCell("ITEM" + String.valueOf(i+1));
                    table.addCell(String.valueOf(5*i));
                    table.addCell(String.valueOf(1));
                    table.addCell(String.valueOf(i)+ " %");
                    table.addCell(df.format(extPrice));
                }*/
                int sr = 0;
                DecimalFormat df = new DecimalFormat("0.0");
                double total_price = 0;
                //Log.i("c0","c0 = "+carts[0].getItemname()+" "+String.valueOf(carts[0].getPrice()));
                // Log.i("c1","c1 = "+carts[1].getItemname()+" "+String.valueOf(carts[1].getPrice()));
                for (Cart cd : carts) {
                    Log.i("cartscheck", "carts check = " + cd.getBarcode() + " " + cd.getItemname() + " "
                            + String.valueOf(cd.getPrice()));
                }
                for (Cart c : carts) {
                    double price = c.getPrice();
                    int quantity = c.getQuantity();
                    price = (price / quantity);
                    double discont = c.getDiscount();
                    sr++;
                    table.addCell(String.valueOf(sr));
                    table.addCell(c.getItemname());
                    table.addCell(df.format(price));
                    table.addCell(String.valueOf(quantity));
                    table.addCell(df.format(discont) + " %");

                    double total = (price * quantity);
                    total_price = total_price + total;
                    Log.i("total", "total in for loop = " + String.valueOf(total));
                    table.addCell(df.format(total));

                }
                float headerHeight = table.getHeaderHeight();
                Log.i("headerHeight", String.valueOf(headerHeight));
                //absolute location to print the PDF table from
                table.writeSelectedRows(0, -1, document.leftMargin(), 650, docWriter.getDirectContent());
                float total_height = table.getTotalHeight();
                Log.i("total_height", String.valueOf(total_height));
                createHeadings(cb, 420, 750f - 125f - total_height, "Total Price = ");
                createHeadings(cb, 475, 750f - 125f - total_height, String.valueOf(total_price));

                //print the signature image along with the persons name
                inputStream = getAssets().open("user.png");
                bmp = BitmapFactory.decodeStream(inputStream);
                stream = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
                Image signature = Image.getInstance(stream.toByteArray());
                signature.setAbsolutePosition(400f, 750f - 125f - total_height - 60f);
                signature.scalePercent(35f);
                document.add(signature);

                createHeadings(cb, 450, 750f - 125f - total_height - 80f, fname + " " + lname);

                document.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            //PDF file is now ready to be sent to the bluetooth printer using PrintShare
            Intent i = new Intent(Intent.ACTION_VIEW);
            //   i.setPackage("com.dynamixsoftware.printershare");
            i.setDataAndType(Uri.fromFile(pdfFile), "application/pdf");
            startActivity(i);

        }
    }).start();

}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public Boolean createFrontCoverPage(Document document, String coverTitle, Bitmap photo)
        throws DocumentException, MalformedURLException, IOException {
    if (photo != null) {
        int imageMaxWidth;
        int imageMaxHeight;
        int imagePosX;
        int imagePosY;
        if (photo.getWidth() < photo.getHeight()) {
            imageMaxWidth = 900;/*w  w  w .j  av a2  s.  c om*/
            imageMaxHeight = 1200;
            imagePosX = 198;
            imagePosY = 379;
        } else {
            imageMaxWidth = 1200;
            imageMaxHeight = 900;
            imagePosX = 162;
            imagePosY = 379;
        }
        OutputStream stream = new ByteArrayOutputStream();
        ImageUtilities.scaleCenterCrop(photo, imageMaxWidth, imageMaxHeight).compress(CompressFormat.JPEG, 50,
                stream);
        Image coverImage = Image.getInstance(stream.toByteArray());
        coverImage.setAbsolutePosition(0.0f, 0.0f);
        PdfTemplate t = this.writer.getDirectContent().createTemplate((float) imageMaxWidth,
                (float) imageMaxHeight);
        t.newPath();
        t.moveTo(0.0f, (float) imageMaxHeight);
        t.lineTo(0.0f, 71.0f);
        t.lineTo(17.0f, 71.0f);
        t.lineTo(17.0f, 0.0f);
        t.lineTo(72.0f, 71.0f);
        t.lineTo((float) imageMaxWidth, 71.0f);
        t.lineTo((float) imageMaxWidth, (float) imageMaxHeight);
        t.lineTo(0.0f, (float) imageMaxHeight);
        t.closePath();
        t.clip();
        t.newPath();
        t.addImage(coverImage);
        t.setColorStroke(new BaseColor(0, 0, 0));
        t.setLineWidth(BUBBLE_TEXT_INDENT_ALTERNATE);
        t.newPath();
        t.moveTo(0.0f, (float) imageMaxHeight);
        t.lineTo(0.0f, 71.0f);
        t.lineTo(17.0f, 71.0f);
        t.lineTo(17.0f, 0.0f);
        t.lineTo(72.0f, 71.0f);
        t.lineTo((float) imageMaxWidth, 71.0f);
        t.lineTo((float) imageMaxWidth, (float) imageMaxHeight);
        t.lineTo(0.0f, (float) imageMaxHeight);
        t.closePathStroke();
        Image clipped = Image.getInstance(t);
        clipped.scalePercent(24.0f);
        clipped.setAbsolutePosition((float) imagePosX, (float) imagePosY);
        clipped.setCompressionLevel(this.settings.compressionLevel);
        clipped.setAlignment(5);
        document.add(clipped);
    }
    if (coverTitle != null && coverTitle.length() > 0) {
        PdfContentByte canvas = this.writer.getDirectContent();
        Paragraph coverTitleEl = new Paragraph(coverTitle, this.serifFont24);
        coverTitleEl.setAlignment(1);
        PdfPTable table = new PdfPTable(1);
        table.setTotalWidth(311.0f);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.addElement(coverTitleEl);
        cell.setPadding(0.0f);
        cell.setIndent(0.0f);
        table.addCell(cell);
        table.completeRow();
        table.writeSelectedRows(0, -1, 147.0f, 390.0f, canvas);
    }
    return Boolean.valueOf(true);
}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public Boolean createBackCoverPage(Document document, String backCoverNote)
        throws DocumentException, MalformedURLException, IOException {
    document.newPage();/*from   w w  w  .j a v a 2  s . com*/
    Image backCoverImageFrame = Image
            .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/txtbook_backpage_300.png"));
    backCoverImageFrame.scalePercent(24.0f);
    backCoverImageFrame.setAbsolutePosition(87.0f, 78.0f);
    backCoverImageFrame.setCompressionLevel(this.settings.compressionLevel);
    document.add(backCoverImageFrame);
    PdfContentByte canvas = this.writer.getDirectContent();
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(215.0f);
    if (backCoverNote != null && backCoverNote.length() > 0) {
        Paragraph backCoverEl = new Paragraph(backCoverNote, this.serifFont14);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.addElement(backCoverEl);
        cell.setPadding(13.0f);
        cell.setIndent(0.0f);
        cell.setFixedHeight(310.0f);
        table.addCell(cell);
        table.completeRow();
    }
    Element backUrl = new Anchor("txt-book.com", this.sansFont11Gray);
    backUrl.setName("txt-book.com");
    backUrl.setReference("http://www.txt-book.com");
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(2);
    paragraph.add(backUrl);
    PdfPCell cell2 = new PdfPCell();
    cell2.setBorder(0);
    cell2.setHorizontalAlignment(2);
    cell2.addElement(paragraph);
    cell2.setPadding(0.0f);
    cell2.setPaddingTop(0.0f);
    cell2.setIndent(0.0f);
    table.addCell(cell2);
    table.completeRow();
    table.writeSelectedRows(0, -1, 306.0f, 400.0f, canvas);
    return Boolean.valueOf(true);
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * prints a footer table with a line at the top, a date and page numbering, second cell will be right aligned
 *
 * @see #PAGEFOOTERTABLEKEY/*from  w  ww  . j a  va 2s  .com*/
 * @see #PAGEFOOTERSTYLEKEY
 *
 * @param writer
 * @param document
 * @throws DocumentException
 * @throws VectorPrintException
 */
protected void renderFooter(PdfWriter writer, Document document)
        throws DocumentException, VectorPrintException, InstantiationException, IllegalAccessException {
    if (!debugHereAfter && !failuresHereAfter) {
        PdfPTable footerTable = elementProducer.createElement(null, PdfPTable.class,
                getStylers(PAGEFOOTERTABLEKEY));

        footerTable.addCell(createFooterCell(ValueHelper.createDate(new Date())));

        String pageText = writer.getPageNumber() + getSettings().getProperty(" of ", UPTO);

        PdfPCell c = createFooterCell(pageText);
        c.setHorizontalAlignment(Element.ALIGN_RIGHT);
        footerTable.addCell(c);

        footerTable.addCell(createFooterCell(new Chunk()));
        footerTable.writeSelectedRows(0, -1, document.getPageSize().getLeft() + document.leftMargin(),
                document.getPageSize().getBottom(document.bottomMargin()), writer.getDirectContentUnder());
        footerBottom = document.bottom() - footerTable.getTotalHeight();
    }
}

From source file:com.xumpy.itext.services.HeaderFooter.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable header = new PdfPTable(3);
    try {/* ww w .j a  va 2 s . c om*/
        header.setWidths(new int[] { 24, 24, 24 });
        header.setTotalWidth(527);
        header.setLockedWidth(true);
        header.getDefaultCell().setFixedHeight(20);
        header.getDefaultCell().setBorder(Rectangle.BOTTOM);
        for (PdfPCell cell : tableHeader) {
            cell.setBorder(Rectangle.NO_BORDER);
            header.addCell(cell);
        }
        header.writeSelectedRows(0, -1, 60, 803, writer.getDirectContent());
    } catch (DocumentException ex) {
        Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex);
    }

    PdfPTable footer = new PdfPTable(3);
    try {
        footer.setWidths(new int[] { 24, 24, 24 });
        footer.setTotalWidth(527);
        footer.setLockedWidth(true);
        footer.getDefaultCell().setFixedHeight(20);
        footer.getDefaultCell().setBorder(Rectangle.BOTTOM);
        for (PdfPCell cell : tableFooter) {
            cell.setBorder(Rectangle.NO_BORDER);
            footer.addCell(cell);
        }
        footer.writeSelectedRows(0, -1, 60, 200, writer.getDirectContent());
    } catch (DocumentException ex) {
        Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.aidger.utils.pdf.ActivityReportConverter.java

License:Open Source License

/**
 * Writes the logos and the address of the institute.
 *///  ww  w  . j  a v a2s  .  co m
private void writeLogo() {
    try {
        Font generatedByFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8);
        Image aidger = Image.getInstance(getClass().getResource("/de/aidger/res/pdf/AidgerLogo.png"));
        aidger.scaleAbsolute(80.0f, 20.0f);
        PdfPTable table = new PdfPTable(2);
        table.setTotalWidth(reader.getPageSize(1).getRight());
        PdfPCell cell = new PdfPCell(new Phrase(_("Generated by: "), generatedByFont));
        cell.setBorder(0);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
        cell = new PdfPCell(Image.getInstance(aidger));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(0);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 0, 25, contentByte);
    } catch (BadElementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}