Example usage for com.itextpdf.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph() 

Source Link

Document

Constructs a Paragraph.

Usage

From source file:com.microware.intrahealth.Createpdf2.java

private static void addContent(Document document, String Header[], ArrayList<HashMap<String, String>> data,
        String[] sHeader2, int Flag) throws Exception {

    Paragraph preface = new Paragraph();

    //  preface.setAlignment(Element.ALIGN_CENTER);

    addEmptyLine(preface, 1);//from   w  w w . j a  v a  2  s  .c o m
    preface.add(mypara(sHeader[0], 1));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader[1], 1));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader[2], 2));
    addEmptyLine(preface, 1);
    createTable(preface, Header, data);
    preface.add(mypara(sHeader2[0], 2));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader2[1] + " " + data.size(), 2));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader2[2] + " " + data.size(), 2));
    addEmptyLine(preface, 1);
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader2[3], 3));
    addEmptyLine(preface, 1);

    //

    document.add(preface);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void addContent(Document document, String Header1[], String[] Page1, String[] Page1Value,
        String heading1, String Page1Remark,

        String[] Header2, String[] Page2_1, String[] Page2_1source, String[] Page2_1value, String[] Page2_2,
        String[] Page2_2source, String[] Page2_2value, String[] Page2_3, String[] Page2_3source,
        String[] Page2_3value, String heading2, String heading3, String heading4, String heading5,
        String Remark2Value,/*from w  ww.  ja v  a  2  s .co m*/

        String[] Header3, String[] Page31, String[] Page3Census1, String[] Page3Value1, String[] Page32,
        String[] Page3Census2, String[] Page3Value2, String heading6, String heading7, String heading8,
        String Page3Remark,

        String[] Header4, String[] Page4_1, String[] Page4Value1, String[] Page4_2, String[] Page4Value2,
        String[] Page4_3, String[] Page4Value3, String heading9, String heading10, String heading11,
        String heading12, String Page4Remark1, String Page4Remark3,

        String[] Header5, String[] Page5Value1, String[] Page5Value2, String[] Page5Value3,
        String[] Page5Value4, String[] Page5_2, String[] Page5Value5, String[] Page5_3, String[] Page5Value6,
        String text5, String value5, String heading13, String heading14, String heading15, String Page5Remark1,
        String Page5Remark2,

        String[] Header6, String[] Page6Value1, String[] Page6Value2, String[] Page6Value3,
        String[] Page6Value4, String text6, String value6, String heading16,

        String[] Header7_1, String[] Page7Value1, String[] Page7Value2, String[] Page7Value3,
        String[] Page7Value4, String[] Page7Value5, String[] Header7_2, String[] Page7Value6,
        String[] Page7Value7, String[] Page7Value8, String[] Page7Value9, String[] Page7Value10,
        String[] Page7Value11, String text7_1, String value7_1, String text7_2, String value7_2,
        String heading17, String heading18, String heading19, String pdf1, String pdf2, int Flag)
        throws Exception {

    Paragraph preface = new Paragraph();
    Image img;
    sHeader[0] = "Question";
    sHeader[1] = "Source";
    sHeader[2] = "Data";

    // We add one empty line

    if (iflag == 26) {
        iflag = 0;
    }

    if (Flag == 2) {

    }

    if (iflag == 0) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(pdf1, catFont1));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(pdf2, catFont2));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading1, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page1, Page1Value);
        addEmptyLine(preface, 1);
        iflag = 1;
    }
    if (iflag == 1) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page1Remark);
        addEmptyLine(preface, 1);
        iflag = 2;
    }

    if (iflag == 2) {
        preface.add(new Paragraph(heading2, catFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_1, Page2_1source, Page2_1value);
        addEmptyLine(preface, 1);
        iflag = 3;
    }
    if (iflag == 3) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading3, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading4, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_2, Page2_2source, Page2_2value);
        addEmptyLine(preface, 1);
        iflag = 4;
    }
    if (iflag == 4) {
        preface.add(new Paragraph(heading5, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_3, Page2_3source, Page2_3value);
        addEmptyLine(preface, 1);
        iflag = 5;
    }
    if (iflag == 5) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Remark2Value);
        addEmptyLine(preface, 1);
        iflag = 6;
    }

    if (iflag == 6) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading6, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading7, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header3, Page31, Page3Census1, Page3Value1);
        addEmptyLine(preface, 1);
        iflag = 7;
    }
    if (iflag == 7) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page3Remark);
        addEmptyLine(preface, 1);
        iflag = 8;
    }
    if (iflag == 8) {
        preface.add(new Paragraph(heading8, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header3, Page32, Page3Census2, Page3Value2);
        addEmptyLine(preface, 1);
        iflag = 9;
    }

    if (iflag == 9) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading9, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_1, Page4Value1);
        addEmptyLine(preface, 1);
        iflag = 10;
    }
    if (iflag == 10) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page4Remark1);
        addEmptyLine(preface, 1);
        iflag = 11;
    }
    if (iflag == 11) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading10, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading11, subFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_2, Page4Value2);
        addEmptyLine(preface, 1);
        iflag = 12;
    }
    if (iflag == 12) {
        preface.add(new Paragraph(heading12, subFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_3, Page4Value3);
        addEmptyLine(preface, 1);
        iflag = 13;
    }
    if (iflag == 13) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page4Remark3);
        addEmptyLine(preface, 1);
        iflag = 14;
    }

    if (iflag == 14) {
        preface.add(new Paragraph(heading13, catFont));
        addEmptyLine(preface, 1);
        createTable3(preface, Header5, Page5Value1, Page5Value2, Page5Value3, Page5Value4);
        addEmptyLine(preface, 1);
        iflag = 15;
    }
    if (iflag == 15) {
        createTable7(preface, text5, value5);
        addEmptyLine(preface, 1);
        iflag = 16;
    }
    if (iflag == 16) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading14, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page5_2, Page5Value5);
        addEmptyLine(preface, 1);
        iflag = 17;
    }
    if (iflag == 17) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page5Remark1);
        addEmptyLine(preface, 1);
        iflag = 18;
    }
    if (iflag == 18) {
        preface.add(new Paragraph(heading15, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page5_3, Page5Value6);
        addEmptyLine(preface, 1);
        iflag = 19;
    }
    if (iflag == 19) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page5Remark2);
        addEmptyLine(preface, 1);
        iflag = 20;
    }

    if (iflag == 20) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading16, catFont));
        addEmptyLine(preface, 1);
        createTable3(preface, Header6, Page6Value1, Page6Value2, Page6Value3, Page6Value4);
        addEmptyLine(preface, 1);
        iflag = 21;
    }
    if (iflag == 21) {
        createTable7(preface, text6, value6);
        addEmptyLine(preface, 1);
        iflag = 22;
    }

    if (iflag == 22) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading17, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading18, subFont));
        addEmptyLine(preface, 1);
        createTable4(preface, Header1, text7_1, value7_1);
        addEmptyLine(preface, 1);
        iflag = 23;
    }
    if (iflag == 23) {
        createTable5(preface, Header7_1, Page7Value1, Page7Value2, Page7Value3, Page7Value4, Page7Value5);
        addEmptyLine(preface, 1);
        iflag = 24;
    }
    if (iflag == 24) {
        preface.add(new Paragraph(heading19, subFont));
        addEmptyLine(preface, 1);
        createTable6(preface, Header7_2, Page7Value6, Page7Value7, Page7Value8, Page7Value9, Page7Value10,
                Page7Value11);
        addEmptyLine(preface, 1);
        iflag = 25;
    }
    if (iflag == 25) {
        createTable7(preface, text7_2, value7_2);
        addEmptyLine(preface, 1);
        iflag = 26;
    }

    document.add(preface);

}

From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java

License:Open Source License

public int handle(final User user, final User manager, final ExpenseNote en)
        throws MalformedURLException, IOException, DocumentException {

    log.info("Building list of expenses ...");
    List<Expense> expenses = Expense.list(en);
    log.info("Retrieved " + expenses.size() + " expenses from the datastore");

    log.info("Creating ExpenseNoteDocOutputStream");
    ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en);

    Document document = new Document();
    PdfWriter.getInstance(document, stream);
    document.open();/*  w  w w . j a  v  a2  s  .co  m*/

    document.addTitle("Expense note " + en.id + " of " + user.name);
    document.addSubject("Expense note generated by Rogerthat Enterprise!");
    document.addKeywords("expense note");
    document.addAuthor(user.name);
    document.addCreator("Rogerthat OneApp Enterprise Mobility");

    Paragraph preface = new Paragraph();

    preface.add(new Paragraph("TP Vision expense note", titleFont));
    preface.add(new Paragraph(" "));

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Date date = new Date();
    preface.add(new Paragraph("Date: " + dateFormat.format(date)));
    preface.add(new Paragraph("Requestor: " + user.name));
    preface.add(new Paragraph("Approver: " + manager.name));
    preface.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(110);
    table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 });
    addHeader(table, "Id");
    addHeader(table, "Date");
    addHeader(table, "Nature");
    addHeader(table, "Description");
    addHeader(table, "Account");
    addHeader(table, "Amount");
    addHeader(table, "Voucher");
    table.setHeaderRows(1);

    Collections.sort(expenses, new Comparator<Expense>() {
        @Override
        public int compare(Expense e1, Expense e2) {
            return (int) (e1.date - e2.date);
        }
    });
    int i = 0;
    double total = 0;
    for (Expense expense : expenses) {
        PdfPCell c1 = new PdfPCell(new Phrase("" + ++i));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.addCell(dateFormat.format(new Date(expense.date * 1000)));
        table.addCell(expense.nature);
        table.addCell(expense.description);
        table.addCell("" + expense.account);
        c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency));
        c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(c1);
        table.addCell(expense.voucher);
        total += expense.amount;
    }

    preface.add(table);

    preface.add(new Paragraph(" "));
    preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont));

    document.add(preface);

    i = 0;
    for (Expense expense : expenses) {
        i++;
        if (expense.receipt == null)
            continue;

        document.newPage();
        Paragraph receipt = new Paragraph();
        receipt.add(new Paragraph("Attachment " + i, titleFont));
        document.add(receipt);
        Image image = Image.getInstance(new URL(expense.receipt));
        image.setRotationDegrees(-90);
        float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100;

        image.scalePercent(scaler);
        document.add(image);
    }

    document.close();
    stream.close();

    return stream.getSize();

}

From source file:com.mx.ipn.clases.PDF.java

public void crearpdf(String nombre, String appat, String apmat)
        throws FileNotFoundException, DocumentException {
    // Creacion del documento con los margenes
    // Creacion del documento con los margenes
    Document document = new Document(PageSize.A4, 35, 30, 50, 50);
    try {//from  www  .  j a  va 2  s.  c om

        // El archivo pdf que vamos a generar
        FileOutputStream fileOutputStream = new FileOutputStream("AvisoPrivacidad.pdf");

        // Obtener la instancia del PdfWriter
        PdfWriter.getInstance(document, fileOutputStream);

        // Abrir el documento
        document.open();

        // Crear las fuentes para el contenido y los titulos
        Font fontContenido = FontFactory.getFont(FontFactory.TIMES_ROMAN.toString(), 9, Font.NORMAL,
                BaseColor.DARK_GRAY);
        Font fontTitulos = FontFactory.getFont(FontFactory.TIMES_BOLD, 11, Font.UNDERLINE, BaseColor.DARK_GRAY);
        Font nomb = FontFactory.getFont(FontFactory.TIMES_BOLD, 9, Font.NORMAL, BaseColor.DARK_GRAY);

        // Creacion del parrafo
        Paragraph paragraph = new Paragraph();

        // Agregar un titulo con su respectiva fuente
        paragraph.add(new Phrase("Aviso de Privacidad", fontTitulos));
        paragraph.setAlignment(Element.ALIGN_CENTER);

        // Agregar saltos de linea
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));

        // Agregar contenido con su respectiva fuente
        paragraph.add(new Phrase(
                "Con fundamento en los artculos 15, 16 y de acuerdo a lo Previsto en la Ley Federal de Proteccin de Datos"
                        + "Personales, hacemos de su conocimiento que ZERCHERS, S.A. de C.V., es una empresa legalmente"
                        + "constituido de conformidad con las leyes mexicanas, con domicilio en Av. Juan de Dios Btiz s/n, Gustavo"
                        + "A. Madero, Nueva Industrial Vallejo, 07700 Ciudad de Mxico; y como responsable del tratamiento de sus"
                        + "datos personales, del uso que se le d a los mismos y de su proteccin. Hace de su conocimiento que la"
                        + "informacin de nuestros clientes es tratada de forma estrictamente confidencial por lo que, al proporcionar"
                        + "sus datos personales. Estos sern utilizados nica y exclusivamente para los siguientes fines: "
                        + "Proveer los servicios y productos que ha solicitado; notificarle sobre nuevos servicios o productos que"
                        + "tengan relacin con los ya contratados o adquiridos; comunicarle sobre cambios en los mismos; evaluar la"
                        + "calidad de los servicios que brindamos; mantener actualizada nuestra base de datos con sus datos"
                        + "recientes y en general, para dar cumplimiento a las obligaciones que hemos contrado con usted.",
                fontContenido));

        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(
                " Para las finalidades antes mencionadas, requerimos obtener los siguientes datos personales:",
                fontContenido));
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        // Agregar el parrafo al documento
        document.add(paragraph);

        document.add(Tabla_Simple());
        paragraph = new Paragraph();
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));

        paragraph.add(new Phrase(
                "Para prevenir el acceso no autorizado a sus datos personales y con el fin de asegurar que la informacin sea "
                        + "utilizada para los fines establecidos en este aviso de privacidad, hemos establecido diversos procedimientos"
                        + " con la finalidad de evitar el uso o divulgacin no autorizados de sus datos, permitindonos tratarlos debidamente."
                        + "  As mismo, le informamos que sus datos personales pueden ser Transmitidos para ser tratados por personas "
                        + "distintas a esta empresa.   Todos sus datos personales son tratados de acuerdo a la legislacin aplicable y "
                        + "vigente en el pas, por ello le informamos que usted tiene en todo momento los derechos (ARCO) de acceder, "
                        + "rectificar, cancelar u oponerse al tratamiento que le damos a sus datos personales; derecho que podr "
                        + "hacer valer a travs del ?rea de Privacidad encargada de la seguridad de datos personales en el "
                        + "Telfono 5729 6000.",
                fontContenido));
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);

        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));

        paragraph.add(new Phrase(
                " A travs de estos canales usted podr actualizar sus datos y especificar el medio por el cual desea recibir "
                        + "informacin, ya que en caso de no contar con esta especificacin de su parte, ZERCHERS, S.A. de C.V., "
                        + "establecer libremente el canal que considere pertinente para enviarle informacin.  Este aviso de"
                        + " privacidad podr ser modificado por ZERCHERS, S.A. de C.V., dichas modificaciones sern oportunamente "
                        + "informadas a travs de correo electrnico, telfono, pgina web o cualquier otro medio de comunicacin"
                        + " que ZERCHERS, S.A. de C.V., determine para tal efecto.",
                fontContenido));
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));

        paragraph.add(new Phrase(" ATENTAMENTE", nomb));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(" Direccin General TT/SisPLD", nomb));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(" Consiento que mis datos personales sensibles sean tratados conforme a"
                + "los trminos y condiciones del presente aviso de privacidad.", fontContenido));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase("Nombre: " + nombre + " " + appat + " " + apmat, nomb));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase("____________________________________", fontContenido));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(Chunk.NEWLINE));
        paragraph.add(new Phrase(" ltima Fecha de Emisin:  Mayo 13, 2016", fontContenido));

        document.add(paragraph);

        // Cerrar el documento
        document.close();

        // Abrir el archivo
        File file = new File("AvisoPrivacidad.pdf");
        Desktop.getDesktop().open(file);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.mx.ipn.clases.PDF.java

public PdfPTable Tabla_Simple() throws BadElementException, IOException {
    Paragraph paragraph1 = new Paragraph();
    Font nomb = FontFactory.getFont(FontFactory.TIMES_BOLD, 9, Font.NORMAL, BaseColor.DARK_GRAY);
    Image image;/*from  w w  w  . ja  v  a2s  .c o m*/

    // Obtenemos el logo de datojava
    image = Image.getInstance(getClass().getResource("/com/ipn/mx/imagenes/logo.png"));
    image.scaleAbsolute(70f, 60f);

    //creamos la tabla con 3 columnas
    PdfPTable mitablasimple = new PdfPTable(2);
    PdfPCell cellimage = new PdfPCell(image);

    // Propiedades de la celda

    cellimage.setBorderColor(BaseColor.WHITE);
    cellimage.setHorizontalAlignment(Element.ALIGN_CENTER);

    paragraph1.add(new Phrase("1. Nombre completo Y/O Razn Social.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("2. Direccin.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("3. Registro Federal de Contribuyentes Y/O CURP.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("4. Telfonos de Oficina y mviles.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("5. Actividad econmica e ingreso promedio.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("6. Correo Electrnico. ", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    PdfPCell cell = new PdfPCell(paragraph1);

    // Propiedades de la celda

    cell.setBorderColor(BaseColor.WHITE);
    cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    mitablasimple.addCell(cell);
    mitablasimple.addCell(cellimage);
    //retornamos la tabla

    return mitablasimple;
}

From source file:com.mycompany.mavenproject2.VirtualkeyController.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from   www  .jav a  2  s.  co  m
    // Lets write a big header
    preface.add(new Paragraph("Report Item On History", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    /*  preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          smallBold));*/
    preface.add(new Paragraph("Address 1"));
    //addEmptyLine(preface, 1);
    preface.add(new Paragraph("Address 2"));
    // addEmptyLine(preface, 1);
    preface.add(new Paragraph("City"));
    // addEmptyLine(preface, 1);
    preface.add(new Paragraph("Store"));
    //addEmptyLine(preface, 3);
    //preface.add(new Paragraph("This document describes something which is very important ",smallBold));
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(),
            smallBold));
    addEmptyLine(preface, 2);
    createTable("category_detail", preface);
    //addEmptyLine(preface, 8);

    /*preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
        redFont));*/
    //preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$        smallBold));
    document.add(preface);
    // Start a new page
    //document.newPage();
}

From source file:com.nubean.michutil.PDFConverter.java

License:Open Source License

private Paragraph getParagraph(javax.swing.text.Element pe) throws javax.swing.text.BadLocationException {
    int count = pe.getElementCount();
    Paragraph para = new Paragraph();
    for (int i = 0; i < count; i++) {
        javax.swing.text.Element ele = pe.getElement(i);
        if (ele.isLeaf()) {
            para.add(getChunk(ele));/*w w  w .j  a v a 2  s. c o  m*/
        } else {
            return getParagraph(ele);
        }
    }
    return para;
}

From source file:com.pdg.ticket.utils.FirstPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from  ww  w.  j  a  v  a  2s .co  m*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.de ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.pdi.util.PdfGenerator.java

public static void generarPresupuesto(String lugar, Date fecha, float cantidad, String tipo, Cliente cliente,
        float precio, Aliado aliado, String path) {

    try {//from  w  w  w. j ava  2 s .  c o m

        NEGRITA_12_VERDE.setColor(145, 189, 57);

        long miliSemana = System.currentTimeMillis() + (86400 * 7 * 1000);
        Date vtoPresup = new Date(miliSemana);
        float precioPers = precio / cantidad;
        int precioTotalInt = Math.round(precio);
        int precioPersInt = Math.round(precioPers);
        int cantPersonasInt = Math.round(cantidad);

        //Referencia al objeto Doc
        Document document = new Document(PageSize.A4, //Dimensiones
                36, //margIzq
                36, //margDer
                36, //margenSup
                36); // margenInf

        //Creamos el archivo fisico
        FileOutputStream salida = new FileOutputStream(path);

        //Referencia e inicializacion del objeto que "escribe" el PDF
        PdfWriter writer = PdfWriter.getInstance(document, salida);
        writer.setInitialLeading(0);

        //Imagen Logo
        Image logoPDI = Image.getInstance("Logo PDI.png");
        logoPDI.scaleToFit(215, 205);
        logoPDI.setAlignment(Chunk.ALIGN_LEFT);
        //image.setAbsolutePosition(200, 200);

        //Imagen QR
        Image qr = Image.getInstance("QR PDI.png");
        qr.scaleToFit(211, 165);
        qr.setAbsolutePosition(295, PageSize.A4.getHeight() - 390);

        //Parrafo info evento
        Paragraph infoEvento = new Paragraph();
        infoEvento.add(new Chunk("Informacin del Evento", NEGRITA_SUB_12));
        infoEvento.add(Chunk.NEWLINE);
        infoEvento.add(negritaNormal("Solicitante: ", cliente.toString()));
        infoEvento.add(negritaNormal("Evento: ", tipo));
        infoEvento.add(negritaNormal("Cantidad de personas: ", Integer.toString(cantPersonasInt)));
        infoEvento.add(negritaNormal("Fecha: ", General.formatoFecha.format(fecha)));
        infoEvento.add(negritaNormal("Lugar:  ", lugar));
        infoEvento.add(Chunk.NEWLINE);
        infoEvento.setAlignment(Paragraph.ALIGN_LEFT);

        //Parrafo Modalidad del Servicio
        Paragraph modalidadServicio = new Paragraph();
        modalidadServicio.add(new Chunk("Modalidad Servicio Integral", NEGRITA_SUB_12));
        modalidadServicio.add(Chunk.NEWLINE);
        modalidadServicio.add(new Chunk("Nuestro servicio incluye la totalidad de lo referido a"
                + " los elementos necesarios para el despacho de bebidas: Barras, Bartenders,"
                + " Artculos de Coctelera, Insumos de calidad para los tragos y Mucha Buena Onda."
                + " Con esta modalidad aseguramos la expedicin de "
                + "los tragos desde las 00hs hasta las 05hs, para que se desentiendan del asunto "
                + "y disfruten al mximo.", NORMAL_12));
        modalidadServicio.setAlignment(Paragraph.ALIGN_LEFT);

        //Parrafo Ver Carta
        Paragraph verCarta = new Paragraph();
        verCarta.add(negritaNormal("\u2022 Carta de Tragos: ", "Ver archivo adjunto."));
        verCarta.setIndentationLeft(20);
        verCarta.add(Chunk.NEWLINE);
        verCarta.setAlignment(Paragraph.ALIGN_LEFT);

        //Parrafo Titulo Info Contratacion
        Paragraph infoContratacionTitulo = new Paragraph();
        infoContratacionTitulo.add(new Chunk("Informacin de Contratacin", NEGRITA_SUB_12));
        infoContratacionTitulo.setAlignment(Paragraph.ALIGN_LEFT);

        //Parrafo Inf de Contratacion
        Paragraph infoContratacion = new Paragraph();
        infoContratacion.add(negritaNormal("\u2022 Mtodo de contratacin y reserva de la fecha: ",
                "A travs de contrato firmado por ambas partes. "));
        Phrase lineaCosto = new Phrase();
        lineaCosto.add(new Chunk("\u2022 Costo: ", NEGRITA_12));
        lineaCosto.add(new Chunk("$" + Integer.toString(precioPersInt) + " ", NEGRITA_14));
        lineaCosto.add(new Chunk("por persona ", NEGRITA_12));
        lineaCosto.add(new Chunk("(Total: $" + Integer.toString(precioTotalInt) + ")", NEGRITA_14));
        infoContratacion.add(lineaCosto);
        infoContratacion.add(Chunk.NEWLINE);
        infoContratacion.add(negritaNormal("\u2022 Forma de Pago : ",
                "50% al momento de la firma del contrato y 50% como mximo una semana antes del evento. "));
        infoContratacion.add(Chunk.NEWLINE);
        infoContratacion.setIndentationLeft(20);
        infoContratacion.setFirstLineIndent(0);
        infoContratacion.setAlignment(Paragraph.ALIGN_LEFT);

        //Parrafo Despedida
        Paragraph despedida = new Paragraph();
        despedida.add(new Phrase("Quedamos al aguardo de tus comentarios,", NEGRITA_14));
        despedida.add(Chunk.NEWLINE);
        despedida.add(new Phrase("Muchas Gracias.", NEGRITA_14));
        despedida.add(Chunk.NEWLINE);
        despedida.add(Chunk.NEWLINE);
        despedida.setAlignment(Paragraph.ALIGN_LEFT);

        //Parrafo Firma
        Paragraph firma = new Paragraph();
        firma.add(new Phrase("Piel de Iguana Tragos.-", NEGRITA_CUR_14));
        firma.add(Chunk.NEWLINE);
        firma.add(new Phrase("Cel.: 3462-15337860", NEGRITA_12_VERDE));
        firma.setAlignment(Paragraph.ALIGN_RIGHT);

        float llxLink = 279;
        float llyLink = PageSize.A4.getHeight() - 145;
        float anchoLink = 199;
        float altoLink = 16;

        //Link al facebook
        URL urlPDI = new URL("https://www.facebook.com/pieldeiguanatragos.vt");
        PdfAction irAlFace = new PdfAction(urlPDI);
        Rectangle linkLocation = new Rectangle(llxLink, llyLink, llxLink + anchoLink, llyLink + altoLink);
        PdfAnnotation link = PdfAnnotation.createLink(writer, linkLocation, PdfAnnotation.HIGHLIGHT_NONE,
                irAlFace);
        link.setBorder(new PdfBorderArray(0, 0, 0));
        writer.addAnnotation(link);

        //Espacios Vacios
        Paragraph dosEspacios = new Paragraph();
        dosEspacios.add(Chunk.NEWLINE);
        dosEspacios.add(Chunk.NEWLINE);

        //Hay que abrir el Documento, llenarlo con los elemntos creados
        //en el orden que queremos y cerrarlo
        document.open();

        PdfContentByte cb = writer.getDirectContent();

        ColumnText ct = new ColumnText(cb);
        Phrase recuadro = new Phrase();
        recuadro.add(new Chunk("Piel de Iguana Tragos", NEGRITA_SUB_14));
        recuadro.add(Chunk.NEWLINE);
        recuadro.add(new Chunk("Servicio de tragos para eventos", NEGRITA_12));
        recuadro.add(Chunk.NEWLINE);
        recuadro.add(Chunk.NEWLINE);
        recuadro.add(new Chunk("\"Piel de Iguana, para que tu noche nica sea inigualable.\"", NORMAL_CUR_12));
        recuadro.add(Chunk.NEWLINE);
        recuadro.add(Chunk.NEWLINE);
        Image logoFB = Image.getInstance("Icono FB.png");
        logoFB.scaleToFit(13, 13);
        recuadro.add(new Chunk(logoFB, 0, -3));
        recuadro.add(new Chunk("/pieldeiguanatragos.vt  -> Click Aqu!", NORMAL_12));
        recuadro.add(Chunk.NEWLINE);
        recuadro.add(Chunk.NEWLINE);
        recuadro.add(new Chunk("Vencimiento del Prepuesto " + General.formatoFecha.format(vtoPresup),
                NORMAL_SUB_12));

        float llx = 279;
        float lly = PageSize.A4.getHeight() - 185;
        float ancho = 228;
        float alto = 150;

        ct.setSimpleColumn(recuadro, //Texto
                llx, //punta inf izquierda (x)
                lly, //punta inf izquierda (y) PageSize.A4.getHeight() - 185
                llx + ancho, //ancho del cuadro
                lly + alto, // alto del cuadro
                15, //espaciado
                Element.ALIGN_LEFT // Alineacion
        );

        ct.go();

        document.add(logoPDI);
        document.add(qr);
        document.add(dosEspacios);
        document.add(infoEvento);
        document.add(modalidadServicio);
        document.add(verCarta);
        document.add(infoContratacionTitulo);
        document.add(infoContratacion);
        document.add(despedida);
        document.add(firma);
        document.close();
        System.out.println("Archivo creado");
        int rta = JOptionPane.showConfirmDialog(VentanaMaestra.eventosCurrent,
                "Se guard el presupesto en:\n" + path + "\nDesea abrirlo?", "Presupuesto guardado",
                JOptionPane.YES_NO_OPTION);

        if (rta == JOptionPane.YES_OPTION) {
            if (Desktop.isDesktopSupported()) {
                try {
                    File myFile = new File(path);
                    Desktop.getDesktop().open(myFile);
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(VentanaMaestra.eventosCurrent,
                            "No se puede abrir el archivo. Ubiquelo en su equipo" + "y abralo manualmente.",
                            "Error al abrir el archivo", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(VentanaMaestra.eventosCurrent,
                        "No se puede abrir el archivo. Ubiquelo en su equipo" + "y abralo manualmente.",
                        "Error al abrir el archivo", JOptionPane.ERROR_MESSAGE);
            }

        }

    } catch (FileNotFoundException ex) {
        System.out.println("Error: " + ex.toString());
    } catch (DocumentException ex) {
        System.out.println("Error: " + ex.toString());
    } catch (IOException ex) {
        System.out.println("Error: " + ex.toString());
    }

}

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds title section.//from  w  w  w .jav a 2 s  . c om
 * @param info the project info object
 * @return PDF input stream
 * @throws PhrescoException 
 */
public static InputStream getTitleSection(ApplicationInfo info) throws PhrescoException {
    if (isDebugEnabled) {
        S_LOGGER.debug(" Entering Method DocumentUtil.getTitleSection(ProjectInfo info)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("getTitleSection() projectCode=" + info.getCode());
    }
    try {
        //create output stream
        com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PdfWriter.getInstance(docu, os);
        docu.open();

        //add standard title section with supplied info object
        Paragraph paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setFont(DocConstants.TITLE_FONT);
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        paragraph.add(info.getName());
        addBlankLines(paragraph, MAGICNUMBER.BLANKLINESFOUR);
        docu.add(paragraph);

        paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_CENTER);
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        String techName = info.getTechInfo().getName();
        if (StringUtils.isNotEmpty(info.getTechInfo().getVersion())) {
            paragraph.add(techName + " - " + info.getTechInfo().getVersion());
        } else {
            paragraph.add(techName);
        }
        docu.add(paragraph);

        paragraph = new Paragraph();
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.add(DocumentMessages.getString("Documents.version.name") + getVersion(info)); //$NON-NLS-1$
        addBlankLines(paragraph, MAGICNUMBER.BLANKLINESSEVEN);
        docu.add(paragraph);

        if (StringUtils.isNotEmpty(info.getDescription())) {
            paragraph = new Paragraph();
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            paragraph.setFont(DocConstants.DESC_FONT);
            paragraph.setFirstLineIndent(MAGICNUMBER.BLANKLINESEIGHT);
            docu.add(paragraph);

        }

        docu.close();

        //Create an inputstream to return.
        return new ByteArrayInputStream(os.toByteArray());
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }

}