Example usage for com.lowagie.text.pdf PdfPCell setVerticalAlignment

List of usage examples for com.lowagie.text.pdf PdfPCell setVerticalAlignment

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setVerticalAlignment.

Prototype

public void setVerticalAlignment(int verticalAlignment) 

Source Link

Document

Sets the vertical alignment for the cell.

Usage

From source file:storemanagment.Printing.java

public PdfPCell createTextCell(String text) {

    PdfPCell cell = new PdfPCell();
    Paragraph p = new Paragraph();
    p.setFont(FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, java.awt.Font.BOLD));
    //  p.setFont(Font.BOLD);
    p.setAlignment(Element.ALIGN_CENTER);
    p.add(text);//from w w  w  .  java  2  s  . c  o m
    cell.addElement(p);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setVerticalAlignment(Rectangle.NO_BORDER);

    return cell;

}

From source file:storemanagment.Printing.java

public PdfPCell createTextCellNormal(String text) {

    PdfPCell cell = new PdfPCell();
    Paragraph p = new Paragraph();
    // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,java.awt.Font.BOLD));
    //  p.setFont(Font.BOLD);
    p.setAlignment(Element.ALIGN_CENTER);
    p.add(text);/*from   ww w  .  ja v  a  2s. c  o m*/
    cell.addElement(p);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setVerticalAlignment(Rectangle.NO_BORDER);

    return cell;

}

From source file:storemanagment.Printing.java

public PdfPCell createTextCellNormalUnderlined(String text) {

    PdfPCell cell = new PdfPCell();
    Paragraph p = new Paragraph();
    // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,java.awt.Font.BOLD));
    //  p.setFont(Font.BOLD);
    p.setAlignment(Element.ALIGN_CENTER);

    p.add(text);/*from   w  w w.  j a v  a 2  s  . com*/

    cell.addElement(p);

    cell.setBorder(Rectangle.NO_BORDER);
    cell.setVerticalAlignment(Rectangle.NO_BORDER);

    return cell;

}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addTitle(Document doc, String text)
        throws IOException, BadElementException, DocumentException {
    float[] widths = { 62f, 164f, 62f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);/*from  w  w  w  .  j  a  v  a2s  .  co m*/
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setSpacingAfter(10);

    Image image = Image.getInstance("app_title.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD));
    cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    image = Image.getInstance("title_shot.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    doc.add(table);

    table = new PdfPTable(1);
    table.setWidthPercentage(100);
    cell = new PdfPCell();
    cell.setBackgroundColor(Color.BLACK);
    cell.setFixedHeight(1);
    table.addCell(cell);

    doc.add(table);
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addScreenShorts(Document doc, String text)
        throws BadElementException, IOException, DocumentException {

    Paragraph heading = new Paragraph("Screenshots",
            FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC));
    heading.setSpacingAfter(12f);//from   www .  j av  a 2  s  . co m
    doc.add(heading);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(80);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    Image image = Image.getInstance("screen_shoot1.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot2.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot3.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot4.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot5.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot6.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    //      doc.add(new Paragraph("\n"));
    doc.add(table);
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createNodeNotes4PerPage(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612//from   w w w .  j av  a2  s .co  m
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object

    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        PdfPTable table;
        PdfPCell cell;
        int entryCount = 0;
        int entryOnPage = 0;

        Iterator i = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator();
        while (i.hasNext()) {
            LWComponent component = (LWComponent) i.next();
            if (component instanceof LWNode) {
                final LWNode node = (LWNode) component;

                final String notes = node.getNotes();

                entryCount++;

                table = new PdfPTable(new float[] { 1, 1 });
                table.getDefaultCell().setBorder(0);

                table.setSpacingAfter(20.0f);
                Paragraph p = new Paragraph();

                p.setAlignment(Element.ALIGN_CENTER);

                Phrase phrase = new Phrase(notes);

                Font f = phrase.getFont();
                f.setSize(8.0f);
                p.setFont(f);
                cell = new PdfPCell(phrase);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cell.setBorder(0);

                PdfPCell i2 = new PdfPCell();
                i2.setFixedHeight(172);
                i2.setBorder(0);

                //Render the table then throw the images on
                PdfContentByte cb = writer.getDirectContent();
                PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY);

                Point2D.Float offset = new Point2D.Float();
                //center vertically only if landscape mode
                //if (format.getOrientation() == PageFormat.LANDSCAPE)
                //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)

                Rectangle2D bounds = null;

                bounds = node.getBounds();

                Dimension page = null;

                page = new Dimension(SlideSizeX, 172);

                //   PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80);
                double scale = ZoomTool.computeZoomFit(page, 15, bounds, offset, true);
                PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(),
                        false, 60.0f);
                DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle
                        node, false); // todo: absolute links shouldn't be spec'd here

                dc.setClipOptimized(false);
                dc.setPrintQuality();
                node.drawFit(dc, 15);

                g2d.dispose();

                Image img = Image.getInstance(tp);
                table.addCell(img);
                table.addCell(cell);
                p.add(table);
                document.add(p);
            }
        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();

}

From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java

License:Educational Community License

private PdfPCell headCell(String name, Font font) {

    PdfPCell pdfCell = new PdfPCell(new Phrase(name, font));
    pdfCell.setMinimumHeight(font.getSize() * 2f);
    pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    pdfCell.setVerticalAlignment(Element.ALIGN_CENTER);
    pdfCell.setPaddingBottom(font.getSize() * 0.5f);
    pdfCell.setPaddingTop(font.getSize() * 0.5f);
    pdfCell.setPaddingLeft(font.getSize());
    pdfCell.setPaddingRight(font.getSize());
    return pdfCell;
}

From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java

License:Educational Community License

private PdfPCell nameCell(String name, String webauthId, String department) {

    Phrase phrase = new Phrase();
    phrase.add(new Chunk(name, tableNameFont));
    phrase.add(Chunk.NEWLINE);//from w  w w.  j a  v a 2 s.  c o  m
    StringBuilder otherDetails = new StringBuilder();
    if (webauthId != null && webauthId.trim().length() > 0) {
        otherDetails.append(webauthId);
    }
    if (department != null && department.trim().length() > 0) {
        if (otherDetails.length() > 0) {
            otherDetails.append(" ");
        }
        otherDetails.append(department);
    }
    phrase.add(new Chunk(otherDetails.toString(), tableOtherFont));

    PdfPCell pdfCell = new PdfPCell(phrase);
    pdfCell.setMinimumHeight(tableNameFont.getSize() * 2f);
    pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    pdfCell.setVerticalAlignment(Element.ALIGN_CENTER);
    pdfCell.setPaddingBottom(tableNameFont.getSize() * 0.5f);
    pdfCell.setPaddingTop(tableNameFont.getSize() * 0.5f);
    pdfCell.setPaddingLeft(tableNameFont.getSize());
    pdfCell.setPaddingRight(tableNameFont.getSize());
    return pdfCell;
}