Example usage for com.itextpdf.text Paragraph add

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

Introduction

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

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:ECS.create.java

create() {
    //geting the file path from Page.
    String dpath = Page.dpath;/*from w ww . j  a  v a2  s  .com*/
    try {
        //define program "information" as data
        information data = new information();

        //crate a PDF File
        Document cs = new Document();
        //locate where the PDF save.
        FileOutputStream local = new FileOutputStream(dpath);
        //New PDF location
        PdfWriter writer = PdfWriter.getInstance(cs, local);

        //Edit Propety of the PDF
        cs.addTitle("Title@CoverSheet");
        cs.addAuthor("Author@rensanning");
        cs.addSubject("Subject@iText sample");
        cs.addKeywords("Keywords@iText");
        cs.addCreator("Creator@iText");

        //Seting the Font of the text in the PDF
        Font title = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);
        //Font stitle = new Font(Font.FontFamily.COURIER, 18,Font.ITALIC | Font.UNDERLINE);
        Font stitle = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
        Font usual = new Font(Font.FontFamily.TIMES_ROMAN, 18);

        // open the PDF File
        cs.open();

        PdfContentByte canvas = writer.getDirectContent();

        // insert the information in the PDF
        //group the information into paragrph
        Paragraph sinfo = new Paragraph();
        //using the data form the database which geting by program "information"
        sinfo.add(new Chunk("Name: " + data.fn + " " + data.ln, title));
        //cs.add(Chunk.NEWLINE);
        sinfo.add(new Chunk("               "));
        sinfo.add(new Chunk("SID: " + data.sid, title));
        sinfo.setLeading(40);
        //sinfo.add(Chunk.NEWLINE);
        cs.add(sinfo);

        Paragraph cinfo = new Paragraph();
        cinfo.add(new Chunk("Course: " + data.cid + "   " + data.cn, stitle));
        cinfo.setLeading(30);
        cinfo.add(Chunk.NEWLINE);
        cs.add(cinfo);

        Paragraph minfo = new Paragraph();
        minfo.add(new Chunk("Module: ", stitle));
        minfo.add(new Chunk(data.mid + " " + data.mn, usual));
        minfo.setLeading(30);
        minfo.add(Chunk.NEWLINE);
        cs.add(minfo);

        // insert the information in the PDF
        Paragraph cwinfo = new Paragraph();
        cwinfo.add(new Chunk("Coursework ID: ", stitle));
        cwinfo.add(new Chunk(data.cwid, usual));
        cwinfo.add(Chunk.NEWLINE);
        cwinfo.add(new Chunk("Coursework Tile: ", stitle));
        cwinfo.add(new Chunk(data.cwt, usual));
        cwinfo.add(Chunk.NEWLINE);
        cwinfo.add(new Chunk("Coursework Deadline is on ", stitle));
        cwinfo.add(new Chunk(data.cwed, usual));
        cwinfo.setLeading(30);
        cs.add(cwinfo);

        cs.add(new Paragraph("Rule: \n" + " I am the Boss", usual));

        //Phrase phrase1= new Phrase("This is sentence 1. ", title);
        //ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase1, 30, 600, 0); 
        //cs.add(new Paragraph("Name: " + data.fn + " " + data.ln, title));
        //cs.add(new Chunk("SID: " + data.sid));

        //Close the PDF file
        cs.close();
    } catch (DocumentException | FileNotFoundException ex) {
        System.out.println(ex);
    }
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void createTable(Paragraph preface, Invoice invoice) {
    PdfPTable table = new PdfPTable(2);

    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    table.addCell("Klantgegevens");
    table.addCell("Bedrijfsgegevens");
    table.addCell(invoice.getClientName());
    table.addCell(invoice.getCompanyName());
    table.addCell(invoice.getClientAddress());
    table.addCell(invoice.getCompanyAddress());
    table.addCell(invoice.getClientPostcodeCity());
    table.addCell(invoice.getCompanyPostcodeCity());
    table.addCell("");
    table.addCell("KVK nummer: " + invoice.getCompanyKVK());
    //table.addCell("");
    //table.addCell("Bankgegevens bedrijf");
    //table.addCell("");
    //table.addCell("BTW-nummer bedrijf");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    preface.add(table);
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void createTable2(Paragraph preface, Invoice invoice) {
    PdfPTable table = new PdfPTable(1);

    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    table.addCell(" Factuur nummer: " + invoice.getInvoiceNumber());
    table.addCell(" Factuuratum: " + DateFormatter.dateToString(invoice.getDate()));
    table.addCell(" Vervaldatum: " + DateFormatter.dateToString(invoice.getExpirationDate()));
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    preface.add(table);
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void createTable3(Paragraph preface, Invoice invoice) {
    PdfPTable table = new PdfPTable(4);

    //PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    //cell.setColspan(3);
    // table.addCell(cell);
    table.addCell(" Behandelcode ");
    table.addCell(" Aantal sessies ");
    table.addCell(" Prijs per sessie ");
    table.addCell(" Totaal ");
    table.addCell(invoice.getTreatmentCode());
    table.addCell(invoice.getAmountSessions());
    table.addCell("  " + invoice.getPricePerSession());
    table.addCell("  " + invoice.getTotalPrice().toString());
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    preface.add(table);
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void createTable4(Paragraph preface, Invoice invoice) {
    PdfPTable table = new PdfPTable(2);

    //PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    //cell.setColspan(3);
    // table.addCell(cell);

    table.addCell("Oude eigenrisico");
    table.addCell("Vergoede bedrag");
    table.addCell(" " + invoice.getOldDeductible().toString());
    table.addCell(" " + invoice.getAmountReimbursed());
    table.addCell("Huidige eigenrisco");
    table.addCell("Te betalen");
    table.addCell(" " + invoice.getDeductible().toString());
    table.addCell(" " + invoice.getAmountToPay().toString());
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    preface.add(table);

}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void createTable5(Paragraph preface) {
    PdfPTable table = new PdfPTable(1);

    //PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    //cell.setColspan(3);
    // table.addCell(cell);
    table.addCell("Gelieve te betalen binnen 30 dagen");
    table.addCell(" ");
    table.addCell(" ");

    preface.add(table);
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void addTitlePage(Document document, Invoice invoice) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    // addEmptyLine(preface, (int) 0.5);
    // Lets write a big header
    preface.add(new Paragraph("Factuur"));

    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, (int) 1);
    preface.add(paragraph);/*  w  ww.j a va 2  s . com*/

    createTable(preface, invoice);

    createTable2(preface, invoice);

    createTable3(preface, invoice);

    createTable4(preface, invoice);

    createTable5(preface);

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

From source file:edu.bedelias.utils.ReportsService.java

private static void addTitlePage(String title, String user, Document document) throws DocumentException {

    Paragraph preface = new Paragraph();

    // We add one empty line
    addEmptyLine(preface, 1);/* w w  w. ja  va 2s .  c o  m*/

    // Lets write a big header
    if (title == null) {
        title = PDF_TITLE;
    }
    preface.add(new Paragraph(title, catFont));
    addEmptyLine(preface, 1);

    // Will create: Report generated by: _name, _date
    // System.getProperty("user.name")
    preface.add(new Paragraph("Reporte generado por: " + user + ", " + new Date(), smallBold));
    addEmptyLine(preface, 3);

    // preface.add(new Paragraph("Nuevo Sistema de Gestion de Bedelias",
    // 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.com ;-).",
    // redFont));
    document.add(preface);

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

From source file:edu.bedelias.utils.ReportsService.java

private static void addStudentGrid(java.util.List<Student> students, Document document)
        throws DocumentException {
    Paragraph results = new Paragraph();

    // Add a table
    PdfPTable table = new PdfPTable(3);

    PdfPCell c1 = new PdfPCell(new Phrase("CI Estudiante"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//from   w ww  .  j a v  a 2 s  .c  o m

    c1 = new PdfPCell(new Phrase("Nombre Completo"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Resultado"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    for (Student s : students) {
        table.addCell(s.getCedula());
        table.addCell(s.getName());
        table.addCell("");
    }

    results.add(table);

    // Now add all this to the document
    document.add(results);
}

From source file:edu.clemson.lph.pdfgen.PDFGen.java

License:Open Source License

private void printDoc() {
    if (sSourceFile == null || osDest == null) {
        logger.error("Cannot print nothing");
        return;//from  w w w .  j a  v a 2s. c om
    }
    boolean bBold = false;
    boolean bCenter = false;
    boolean bItalic = false;
    boolean bSmallItalic = false;
    boolean bUnderline = false;
    try {
        Document doc = new Document();
        float fCorr = doc.getPageSize().getWidth() / 8.5f;
        doc.setMargins(1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr);

        PdfWriter.getInstance(doc, osDest);
        doc.open();
        BufferedReader br = new BufferedReader(new FileReader(sSourceFile));
        String sLine = br.readLine();
        while (sLine != null) {
            bBold = false;
            bCenter = false;
            if (sLine.startsWith(".")) {
                String sRest = sLine.substring(1);
                String sCodes = sRest.substring(0, sRest.indexOf('.'));
                sLine = sRest.substring(sRest.indexOf('.') + 1);
                if ("image".equals(sCodes)) {
                    String sFileName = sLine;
                    com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName);
                    image.setAlignment(Element.ALIGN_CENTER);
                    doc.add(image);
                    sLine = br.readLine();
                    continue;
                } else if ("himage".equals(sCodes)) {
                    String sFileName = sLine;
                    com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName);
                    image.scaleToFit(500, 40);
                    image.setAlignment(Element.ALIGN_CENTER);
                    doc.add(image);
                    Paragraph p = new Paragraph(" ");
                    doc.add(p);
                    sLine = br.readLine();
                    continue;
                } else if ("fimage".equals(sCodes)) {
                    int iBlanks = 9; // How do I figure out how many to get to end?
                    for (int i = 0; i < iBlanks; i++) {
                        Paragraph p = new Paragraph(" ");
                        doc.add(p);
                    }
                    String sFileName = sLine;
                    com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName);
                    image.scaleToFit(500, 40);
                    image.setAlignment(Element.ALIGN_CENTER);
                    doc.add(image);
                    sLine = br.readLine();
                    continue;
                } else if ("list".equals(sCodes)) {
                    String sFullLine = doSub(sLine);
                    StringTokenizer tok = new StringTokenizer(sFullLine, "\n");
                    List list = new List(List.UNORDERED);
                    while (tok.hasMoreTokens()) {
                        String sNextLine = tok.nextToken();
                        ListItem listItem = new ListItem(sNextLine, fNormal);
                        list.add(listItem);
                    }
                    doc.add(list);
                    sLine = br.readLine();
                    continue;
                }
                if (sCodes.contains("b"))
                    bBold = true;
                if (sCodes.contains("c"))
                    bCenter = true;
                if (sCodes.contains("i"))
                    bItalic = true;
                if (sCodes.contains("si"))
                    bSmallItalic = true;
                if (sCodes.contains("u"))
                    bUnderline = true;
            }
            if (sLine.trim().length() == 0)
                sLine = " ";

            String sFullLine = doSub(sLine);
            Paragraph p = new Paragraph();
            if (bBold)
                p.setFont(fBold);
            else if (bSmallItalic)
                p.setFont(fSmallItalic);
            else if (bItalic)
                p.setFont(fItalic);
            else if (bUnderline)
                p.setFont(fUnderline);
            else
                p.setFont(fNormal);
            if (bCenter) {
                p.setAlignment(Element.ALIGN_CENTER);
            } else {
                p.setAlignment(Element.ALIGN_LEFT);
            }
            p.add(sFullLine);
            doc.add(p);
            sLine = br.readLine();
        }
        br.close();
        doc.close();
    } catch (FileNotFoundException e) {
        logger.error("Could not find source file " + sSourceFile + " or destination", e);
    } catch (IOException e) {
        logger.error("Could not read file " + sSourceFile, e);
    } catch (DocumentException e) {
        logger.error("Error creating iText Document", e);
    }
}