Example usage for com.itextpdf.text Element ALIGN_RIGHT

List of usage examples for com.itextpdf.text Element ALIGN_RIGHT

Introduction

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

Prototype

int ALIGN_RIGHT

To view the source code for com.itextpdf.text Element ALIGN_RIGHT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:org.totschnig.myexpenses.model.Account.java

License:Open Source License

private void addTransactionList(Document document, Cursor transactionCursor, PdfHelper helper,
        WhereFilter filter) throws DocumentException, IOException {
    String selection;/*from  w w w . j a  v a  2  s  .c om*/
    String[] selectionArgs;
    if (!filter.isEmpty()) {
        selection = filter.getSelectionForParts(DatabaseConstants.VIEW_EXTENDED);//GROUP query uses extended view
        selectionArgs = filter.getSelectionArgs(true);
    } else {
        selection = null;
        selectionArgs = null;
    }
    Builder builder = Transaction.CONTENT_URI.buildUpon();
    builder.appendPath(TransactionProvider.URI_SEGMENT_GROUPS).appendPath(grouping.name());
    if (getId() < 0) {
        builder.appendQueryParameter(KEY_CURRENCY, currency.getCurrencyCode());
    } else {
        builder.appendQueryParameter(KEY_ACCOUNTID, String.valueOf(getId()));
    }
    Cursor groupCursor = cr().query(builder.build(), null, selection, selectionArgs,
            KEY_YEAR + " ASC," + KEY_SECOND_GROUP + " ASC");

    MyApplication ctx = MyApplication.getInstance();

    int columnIndexGroupSumIncome = groupCursor.getColumnIndex(KEY_SUM_INCOME);
    int columnIndexGroupSumExpense = groupCursor.getColumnIndex(KEY_SUM_EXPENSES);
    int columnIndexGroupSumTransfer = groupCursor.getColumnIndex(KEY_SUM_TRANSFERS);
    int columIndexGroupSumInterim = groupCursor.getColumnIndex(KEY_INTERIM_BALANCE);
    int columnIndexRowId = transactionCursor.getColumnIndex(KEY_ROWID);
    int columnIndexYear = transactionCursor.getColumnIndex(KEY_YEAR);
    int columnIndexYearOfWeekStart = transactionCursor.getColumnIndex(KEY_YEAR_OF_WEEK_START);
    int columnIndexMonth = transactionCursor.getColumnIndex(KEY_MONTH);
    int columnIndexWeek = transactionCursor.getColumnIndex(KEY_WEEK);
    int columnIndexDay = transactionCursor.getColumnIndex(KEY_DAY);
    int columnIndexAmount = transactionCursor.getColumnIndex(KEY_AMOUNT);
    int columnIndexLabelSub = transactionCursor.getColumnIndex(KEY_LABEL_SUB);
    int columnIndexLabelMain = transactionCursor.getColumnIndex(KEY_LABEL_MAIN);
    int columnIndexComment = transactionCursor.getColumnIndex(KEY_COMMENT);
    int columnIndexReferenceNumber = transactionCursor.getColumnIndex(KEY_REFERENCE_NUMBER);
    int columnIndexPayee = transactionCursor.getColumnIndex(KEY_PAYEE_NAME);
    int columnIndexTransferPeer = transactionCursor.getColumnIndex(KEY_TRANSFER_PEER);
    int columnIndexDate = transactionCursor.getColumnIndex(KEY_DATE);
    DateFormat itemDateFormat;
    switch (grouping) {
    case DAY:
        itemDateFormat = android.text.format.DateFormat.getTimeFormat(ctx);
        break;
    case MONTH:
        itemDateFormat = new SimpleDateFormat("dd");
        break;
    case WEEK:
        itemDateFormat = new SimpleDateFormat("EEE");
        break;
    default:
        itemDateFormat = Utils.localizedYearlessDateFormat();
    }
    PdfPTable table = null;

    int prevHeaderId = 0, currentHeaderId;

    transactionCursor.moveToFirst();
    groupCursor.moveToFirst();

    while (transactionCursor.getPosition() < transactionCursor.getCount()) {
        int year = transactionCursor
                .getInt(grouping.equals(Grouping.WEEK) ? columnIndexYearOfWeekStart : columnIndexYear);
        int month = transactionCursor.getInt(columnIndexMonth);
        int week = transactionCursor.getInt(columnIndexWeek);
        int day = transactionCursor.getInt(columnIndexDay);
        int second = -1;

        switch (grouping) {
        case DAY:
            currentHeaderId = year * 1000 + day;
            break;
        case WEEK:
            currentHeaderId = year * 1000 + week;
            break;
        case MONTH:
            currentHeaderId = year * 1000 + month;
            break;
        case YEAR:
            currentHeaderId = year * 1000;
            break;
        default:
            currentHeaderId = 1;
        }
        if (currentHeaderId != prevHeaderId) {
            if (table != null) {
                document.add(table);
            }
            switch (grouping) {
            case DAY:
                second = transactionCursor.getInt(columnIndexDay);
                break;
            case MONTH:
                second = transactionCursor.getInt(columnIndexMonth);
                break;
            case WEEK:
                second = transactionCursor.getInt(columnIndexWeek);
                break;
            }
            table = helper.newTable(2);
            table.setWidthPercentage(100f);
            PdfPCell cell = helper.printToCell(grouping.getDisplayTitle(ctx, year, second, transactionCursor),
                    FontType.HEADER);
            table.addCell(cell);
            Long sumExpense = DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumExpense);
            Long sumIncome = DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumIncome);
            Long sumTransfer = DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumTransfer);
            Long delta = sumIncome - sumExpense + sumTransfer;
            Long interimBalance = DbUtils.getLongOr0L(groupCursor, columIndexGroupSumInterim);
            Long previousBalance = interimBalance - delta;
            cell = helper.printToCell(String.format("%s %s %s = %s",
                    Utils.convAmount(previousBalance, currency), Long.signum(delta) > -1 ? "+" : "-",
                    Utils.convAmount(Math.abs(delta), currency), Utils.convAmount(interimBalance, currency)),
                    FontType.HEADER);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            document.add(table);
            table = helper.newTable(3);
            table.setWidthPercentage(100f);
            cell = helper.printToCell("+ " + Utils.convAmount(sumIncome, currency), FontType.NORMAL);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = helper.printToCell("- " + Utils.convAmount(sumExpense, currency), FontType.NORMAL);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = helper.printToCell("<-> "
                    + Utils.convAmount(DbUtils.getLongOr0L(groupCursor, columnIndexGroupSumTransfer), currency),
                    FontType.NORMAL);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            table.setSpacingAfter(2f);
            document.add(table);
            LineSeparator sep = new LineSeparator();
            document.add(sep);
            table = helper.newTable(4);
            table.setWidths(new int[] { 1, 5, 3, 2 });
            table.setSpacingBefore(2f);
            table.setSpacingAfter(2f);
            table.setWidthPercentage(100f);
            prevHeaderId = currentHeaderId;
            groupCursor.moveToNext();
        }
        long amount = transactionCursor.getLong(columnIndexAmount);
        String catText = transactionCursor.getString(columnIndexLabelMain);

        PdfPCell cell = helper.printToCell(
                Utils.convDateTime(transactionCursor.getString(columnIndexDate), itemDateFormat),
                FontType.NORMAL);
        table.addCell(cell);
        if (DbUtils.getLongOrNull(transactionCursor, columnIndexTransferPeer) != null) {
            catText = ((amount < 0) ? "=> " : "<= ") + catText;
        } else {
            Long catId = DbUtils.getLongOrNull(transactionCursor, KEY_CATID);
            if (SPLIT_CATID.equals(catId)) {
                Cursor splits = cr().query(Transaction.CONTENT_URI, null,
                        KEY_PARENTID + " = " + transactionCursor.getLong(columnIndexRowId), null, null);
                splits.moveToFirst();
                catText = "";
                while (splits.getPosition() < splits.getCount()) {
                    String splitText = DbUtils.getString(splits, KEY_LABEL_MAIN);
                    if (splitText.length() > 0) {
                        if (DbUtils.getLongOrNull(splits, KEY_TRANSFER_PEER) != null) {
                            splitText = "[" + splitText + "]";
                        } else {
                            String label_sub = DbUtils.getString(splits, KEY_LABEL_SUB);
                            if (label_sub.length() > 0)
                                splitText += TransactionList.CATEGORY_SEPARATOR + label_sub;
                        }
                    } else {
                        splitText = ctx.getString(R.string.no_category_assigned);
                    }
                    splitText += " " + Utils
                            .convAmount(splits.getLong(splits.getColumnIndexOrThrow(KEY_AMOUNT)), currency);
                    String splitComment = DbUtils.getString(splits, KEY_COMMENT);
                    if (splitComment != null && splitComment.length() > 0) {
                        splitText += " (" + splitComment + ")";
                    }
                    catText += splitText;
                    if (splits.getPosition() != splits.getCount() - 1) {
                        catText += "; ";
                    }
                    splits.moveToNext();
                }
                splits.close();
            } else if (catId == null) {
                catText = ctx.getString(R.string.no_category_assigned);
            } else {
                String label_sub = transactionCursor.getString(columnIndexLabelSub);
                if (label_sub != null && label_sub.length() > 0) {
                    catText = catText + TransactionList.CATEGORY_SEPARATOR + label_sub;
                }
            }
        }
        String referenceNumber = transactionCursor.getString(columnIndexReferenceNumber);
        if (referenceNumber != null && referenceNumber.length() > 0)
            catText = "(" + referenceNumber + ") " + catText;
        cell = helper.printToCell(catText, FontType.NORMAL);
        String payee = transactionCursor.getString(columnIndexPayee);
        if (payee == null || payee.length() == 0) {
            cell.setColspan(2);
        }
        table.addCell(cell);
        if (payee != null && payee.length() > 0) {
            table.addCell(helper.printToCell(payee, FontType.UNDERLINE));
        }
        FontType t = amount < 0 ? FontType.EXPENSE : FontType.INCOME;
        cell = helper.printToCell(Utils.convAmount(amount, currency), t);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);
        String comment = transactionCursor.getString(columnIndexComment);
        if (comment != null && comment.length() > 0) {
            cell = helper.printToCell(comment, FontType.ITALIC);
            cell.setColspan(2);
            table.addCell(helper.emptyCell());
            table.addCell(cell);
            table.addCell(helper.emptyCell());
        }
        transactionCursor.moveToNext();
    }
    // now add all this to the document
    document.add(table);
    groupCursor.close();
}

From source file:Output.QuotePDf.java

private PdfPTable commodityTable() throws DocumentException {
    PdfPTable table = new PdfPTable(4);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    float[] columnWidths = new float[] { 55f, 70f, 55f, 65f };
    table.setWidths(columnWidths);//from  w w  w  . ja v  a  2s  . c  om

    cell = new PdfPCell(new Phrase("Port(s) of Load:", labelFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(pol, textFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("via:", labelFont));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(tship, textFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Port(s) of Discharge:", labelFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(pod, textFont));
    cell.setColspan(3);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Commodity:", labelFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(commodityClass, textFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Handling:", labelFont));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(cargoHandling, textFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Accompanying:", labelFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    if (accessories) {
        cell = new PdfPCell(new Phrase(accessories_accompanying, textFont));
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
    } else {
        cell = new PdfPCell(new Phrase("N/A", textFont));
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("Description", labelFont));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(description, textFont));
    cell.setColspan(3);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    return table;
}

From source file:pdf.FooterHeader.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {//www  .  ja  v  a  2  s. c  o  m
        if (document.getPageNumber() > 1) {
            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("Seite %d von", 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);
    }

    PdfContentByte cb = writer.getDirectContent();
    if (document.getPageNumber() > 1) {
        footer = new Phrase(document.getPageNumber() - 2);
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
                (document.right() - document.left() - 30) / 2 + document.leftMargin(), document.bottom() + 10,
                0);
    }

}

From source file:pdf.PDFDesign.java

private PdfPTable createLine3Table(Item item, int s1, int s2, int s3) throws DocumentException {
    if (s1 != 0 && s1 != 0 && s3 != 0) {
        bigPriceNumberFont.setSize(s1);/*w  ww  .  j  ava2 s . c  o  m*/
        decimalPriceNumberFont.setSize(s2);
        decimalPriceNumberFont.setSize(s3);
    } else {
        bigPriceNumberFont.setSize(70);
    }
    Paragraph p3 = new Paragraph();
    p3.setFont(bigPriceNumberFont);
    p3.add(item.getPrice().substring(0, item.getPrice().length() - 3));

    Paragraph p3_2 = new Paragraph();
    p3_2.setFont(decimalPriceNumberFont);
    p3_2.add(item.getPrice().substring(item.getPrice().length() - 2, item.getPrice().length()));

    Paragraph p3_3 = new Paragraph();
    p3_3.setFont(decimalPriceNumberFont);
    p3_3.add(item.getCurrency());

    PdfPTable table = new PdfPTable(2);
    if (item.getPrice().length() == 6) {
        table.setWidths(new float[] { 2.8f, 1 });
    } else if (item.getPrice().length() == 5) {
        table.setWidths(new float[] { 1.8f, 1 });
    } else {
        table.setWidths(new float[] { 1.5f, 1 });
    }
    PdfPCell cell = new PdfPCell(p3);
    cell.setRowspan(2);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    if (s1 != 0 && s1 != 0 && s3 != 0) {
        cell.setLeading(42.0f, 0f);
    } else {
        cell.setLeading(55.0f, 0f);
    }
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell(p3_2);
    cell.setRowspan(1);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell(p3_3);
    cell.setRowspan(1);
    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(0);
    table.addCell(cell);

    return table;
}

From source file:pdf.PDFDesign.java

private PdfPCell createEuroInnerInnerPrice(String price, String curr, boolean isFirst)
        throws DocumentException {

    Font bigPriceFont = new Font(droidsans, 40, Font.BOLD, color);
    Font smallPriceFont = new Font(droidsans, 18, Font.NORMAL, color);
    Font unitFont = new Font(droidsans, 12, Font.NORMAL, color);

    PdfPTable table = new PdfPTable(2);
    table.setWidths(new float[] { 3f, 1f });
    PdfPCell cell;//from   ww  w  . ja va2  s. c  o  m
    Paragraph para;

    para = new Paragraph("");
    para.setFont(bigPriceFont);
    if (price.length() >= 4) {
        para.add(price.substring(0, price.length() - 3));
    }
    cell = new PdfPCell(para);
    cell.setRowspan(2);
    cell.setFixedHeight(57f);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(0);
    table.addCell(cell);

    para = new Paragraph("");
    para.setFont(smallPriceFont);
    if (price.length() >= 4) {
        para.add(price.substring(price.length() - 2, price.length()));
    }
    cell = new PdfPCell(para);
    cell.setRowspan(1);
    cell.setFixedHeight(35f);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(0);
    table.addCell(cell);

    para = new Paragraph();
    para.setFont(unitFont);
    para.add(curr);
    cell = new PdfPCell(para);
    cell.setRowspan(1);
    cell.setFixedHeight(22f);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorder(0);
    table.addCell(cell);

    PdfPCell finalCell = new PdfPCell(table);
    finalCell.setBorder(0);
    /*if (isFirst) {
     finalCell.setBorder(Rectangle.RIGHT);
     }*/
    return finalCell;
}

From source file:pdf.PDFDesign.java

private PdfPCell createEuro_6_InnerInnerPrice(String price, String curr, boolean isFirst)
        throws DocumentException {
    PdfPTable table = new PdfPTable(2);
    table.setWidths(new float[] { 3f, 1.2f });
    PdfPCell cell;/*  w ww .j  a  v  a2 s  .c  o m*/
    Paragraph para;

    para = new Paragraph("");
    para.setFont(new Font(droidsans, 60, Font.BOLD, color));
    if (price.length() >= 4) {
        para.add(price.substring(0, price.length() - 3));
    }
    cell = new PdfPCell(para);
    cell.setRowspan(2);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setLeading(50f, 0f);
    cell.setBorder(0);
    table.addCell(cell);

    para = new Paragraph("");
    para.setFont(new Font(droidsans, 28, Font.NORMAL, color));
    if (price.length() >= 4) {
        para.add(price.substring(price.length() - 2, price.length()));
    }
    cell = new PdfPCell(para);
    cell.setRowspan(1);
    cell.setFixedHeight(32f);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(0);
    table.addCell(cell);

    para = new Paragraph();
    para.setFont(new Font(droidsans, 16, Font.NORMAL, color));
    para.add(curr);
    cell = new PdfPCell(para);
    cell.setRowspan(1);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorder(0);
    table.addCell(cell);

    PdfPCell finalCell = new PdfPCell(table);
    finalCell.setBorder(0);
    /*if (isFirst) {
    finalCell.setBorder(Rectangle.RIGHT);
    }*/
    return finalCell;
}

From source file:PdfCreation.PdfTableWriter.java

public Paragraph newParagraph(String text, boolean alignCenter, boolean alignLeft, boolean alignRight) {
    Paragraph ourParagraph = new Paragraph();
    if (alignCenter && !alignLeft && !alignRight) {
        ourParagraph.setAlignment(Element.ALIGN_CENTER);
    } else if ((!alignCenter && !alignLeft && !alignRight) && (!alignCenter && alignLeft && !alignRight)) {
        ourParagraph.setAlignment(Element.ALIGN_LEFT);
    } else if (!alignCenter && !alignLeft && alignRight) {
        ourParagraph.setAlignment(Element.ALIGN_RIGHT);
    }/* www  .  j  a v a 2  s . co m*/
    //    ourParagraph.setFont(new Font(Font.FontFamily.COURIER, 11));
    ourParagraph.add(text);
    return ourParagraph;
}

From source file:pkgAgenda_Virtual.frmActividades.java

public void PDFpersonales() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*from  w ww .j  a v  a  2 s  .  c  om*/

    try {
        FacturaPdf = new FileOutputStream("archives/ActividadesPersonales.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Personales de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        PdfPTable tblHoy = new PdfPTable(4);
        PdfPTable tblAntes = new PdfPTable(4);
        PdfPTable tblDespues = new PdfPTable(4);
        tblHoy.addCell("Titulo");
        tblHoy.addCell("Fecha");
        tblHoy.addCell("Hora");
        tblHoy.addCell("Lugar");
        tblAntes.addCell("Titulo");
        tblAntes.addCell("Fecha");
        tblAntes.addCell("Hora");
        tblAntes.addCell("Lugar");
        tblDespues.addCell("Titulo");
        tblDespues.addCell("Fecha");
        tblDespues.addCell("Hora");
        tblDespues.addCell("Lugar");

        //sdfhfjhsdfsd
        int valor;

        rs = H.Buscar("SELECT nom_act, fecha_act, hora_act, lugar_act FROM Actividades WHERE cod_usu = "
                + H.Usuario + " AND id_tipoact = 2");
        while (rs.next()) {
            String fecharecibida = rs.getString(2).substring(0, 10);
            valor = H.FechaAnterior(fecharecibida);
            if (valor == 2) {
                tblHoy.addCell(H.desencriptar(rs.getString(1)));
                tblHoy.addCell(fecharecibida);
                tblHoy.addCell(rs.getString(3).substring(0, 5));
                tblHoy.addCell(H.desencriptar(rs.getString(4)));
            } else if (valor == 1) {
                tblAntes.addCell(H.desencriptar(rs.getString(1)));
                tblAntes.addCell(fecharecibida);
                tblAntes.addCell(rs.getString(3).substring(0, 5));
                tblAntes.addCell(H.desencriptar(rs.getString(4)));
            } else if (valor == 0) {
                tblDespues.addCell(H.desencriptar(rs.getString(1)));
                tblDespues.addCell(fecharecibida);
                tblDespues.addCell(rs.getString(3).substring(0, 5));
                tblDespues.addCell(H.desencriptar(rs.getString(4)));
            }
        }

        //askjdhskfjhdf
        documento.add(new Paragraph("Actividades Pasadas"));
        documento.add(new Paragraph(" "));
        documento.add(tblAntes);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Hoy"));
        documento.add(new Paragraph(" "));
        documento.add(tblHoy);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Futuras"));
        documento.add(new Paragraph(" "));
        documento.add(tblDespues);
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmActividades.java

public void PDFdeestudio() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*ww w .j  av a2  s.  c om*/

    try {
        FacturaPdf = new FileOutputStream("archives/ActividadesdeEstudio.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Estudio de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        PdfPTable tblHoy = new PdfPTable(4);
        PdfPTable tblAntes = new PdfPTable(4);
        PdfPTable tblDespues = new PdfPTable(4);
        tblHoy.addCell("Asignatura");
        tblHoy.addCell("Tarea");
        tblHoy.addCell("Fecha");
        tblHoy.addCell("Hora");
        tblAntes.addCell("Asignatura");
        tblAntes.addCell("Tarea");
        tblAntes.addCell("Fecha");
        tblAntes.addCell("Hora");
        tblDespues.addCell("Asignatura");
        tblDespues.addCell("Tarea");
        tblDespues.addCell("Fecha");
        tblDespues.addCell("Hora");

        //sdfhfjhsdfsd
        int valor;

        rs = H.Buscar("SELECT nom_act, des_act, fecha_act, hora_act FROM Actividades WHERE cod_usu = "
                + H.Usuario + " AND id_tipoact = 1");
        while (rs.next()) {
            String fecharecibida = rs.getString(3).substring(0, 10);
            valor = H.FechaAnterior(fecharecibida);
            if (valor == 2) {
                tblHoy.addCell(H.desencriptar(rs.getString(1)));
                tblHoy.addCell(H.desencriptar(rs.getString(2)));
                tblHoy.addCell(fecharecibida);
                tblHoy.addCell(rs.getString(4).substring(0, 5));
            } else if (valor == 1) {
                tblAntes.addCell(H.desencriptar(rs.getString(1)));
                tblAntes.addCell(H.desencriptar(rs.getString(2)));
                tblAntes.addCell(fecharecibida);
                tblAntes.addCell(rs.getString(4).substring(0, 5));
            } else if (valor == 0) {
                tblDespues.addCell(H.desencriptar(rs.getString(1)));
                tblDespues.addCell(H.desencriptar(rs.getString(2)));
                tblDespues.addCell(fecharecibida);
                tblDespues.addCell(rs.getString(4).substring(0, 5));
            }
        }

        //askjdhskfjhdf
        documento.add(new Paragraph("Actividades Pasadas"));
        documento.add(new Paragraph(" "));
        documento.add(tblAntes);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Hoy"));
        documento.add(new Paragraph(" "));
        documento.add(tblHoy);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Futuras"));
        documento.add(new Paragraph(" "));
        documento.add(tblDespues);
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmAgenda.java

public void PDF() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*  ww w. ja v  a 2 s.c  o m*/

    try {
        FacturaPdf = new FileOutputStream("archives/Notas.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Notas de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        PdfPTable tabla = new PdfPTable(2);
        tabla.addCell("Titulo");
        tabla.addCell("Descripcion");

        //sdfhfjhsdfsd

        rs = H.Buscar(
                "SELECT nom_nota, des_nota FROM Notas WHERE cod_usu = " + H.Usuario + " ORDER BY nom_nota ASC");
        while (rs.next()) {
            tabla.addCell(rs.getString(1));
            tabla.addCell(rs.getString(2));
        }

        //askjdhskfjhdf
        documento.add(tabla);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}