Example usage for com.lowagie.text Section add

List of usage examples for com.lowagie.text Section add

Introduction

In this page you can find the example usage for com.lowagie.text Section add.

Prototype

public boolean add(Object o) 

Source Link

Document

Adds a Paragraph, List, Table or another Section to this Section.

Usage

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

protected void printMostViolatedRules(Project project, Section section) {
    List<Rule> mostViolatedRules = project.getMostViolatedRules();
    Iterator<Rule> it = mostViolatedRules.iterator();

    List<String> left = new LinkedList<String>();
    List<String> right = new LinkedList<String>();
    int limit = 0;
    while (it.hasNext() && limit < 5) {
        Rule rule = it.next();//  w  w w .  j  a v a  2s  . c om
        left.add(rule.getName());
        right.add(String.valueOf(rule.getViolationsNumberFormatted()));
        limit++;
    }

    PdfPTable mostViolatedRulesTable = Style.createSimpleTable(left, right,
            getTextProperty("general.most_violated_rules"), getTextProperty("general.no_violated_rules"));
    section.add(mostViolatedRulesTable);
}

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

protected void printMostViolatedFiles(Project project, Section section) {
    List<FileInfo> files = project.getMostViolatedFiles();
    Iterator<FileInfo> it = files.iterator();
    List<String> left = new LinkedList<String>();
    List<String> right = new LinkedList<String>();

    while (it.hasNext()) {
        FileInfo file = it.next();/*  w  ww.j  ava 2s  .c  om*/
        left.add(file.getName());
        right.add(file.getViolations());
    }

    PdfPTable mostViolatedFilesTable = Style.createSimpleTable(left, right,
            getTextProperty("general.most_violated_files"), getTextProperty("general.no_violated_files"));
    section.add(mostViolatedFilesTable);
}

From source file:org.sonar.report.pdf.TeamWorkbookPDFReporter.java

License:Open Source License

private void printMostViolatedRulesDetails(Project project, Section section13) {
    Iterator<Rule> it = project.getMostViolatedRules().iterator();

    while (it.hasNext()) {
        Rule rule = it.next();/*from   www  . j  av  a2  s  .c o m*/
        List<String> files = new LinkedList<String>();
        List<String> lines = new LinkedList<String>();
        Iterator<Violation> itViolations = rule.getTopViolations().iterator();
        while (itViolations.hasNext()) {
            Violation violation = itViolations.next();
            String[] components = violation.getResource().split("\\.");
            files.add(components[components.length - 1]);
            lines.add(violation.getLine());
        }
        section13.add(createViolationsDetailedTable(rule.getName(), files, lines));
    }
}

From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java

License:Open Source License

private void printChapterSection(ChapterAutoNumber chapter, String sectionName)
        throws DocumentException, IOException {
    String sectionDisplayName = getTextProperty("extendedpdf." + sectionName);
    String imagePath = screenshotsDir + File.separator + sectionName + ".png";
    File file = new File(imagePath);
    if (file.exists() && !file.isDirectory()) {
        Section section = chapter.addSection(new Paragraph(sectionDisplayName, Style.TITLE_FONT));
        Image image = Image.getInstance(imagePath);
        section.add(image);
        section.add(Chunk.NEWLINE);//from w w w.j  a va 2 s  . com
    }
}

From source file:org.tpspencer.tal.mvc.document.DocumentWriterImpl.java

License:Apache License

public void writeImage(String image, String legend, AppElement element) {
    Section section = sections.size() > 0 ? sections.peek() : chapter;

    URL url = this.getClass().getResource(image);
    if (url == null)
        return;// w w  w.  j  a  v a2  s .c  o m

    try {
        Image img = Image.getInstance(url);
        if (img != null) {
            img.scaleToFit(document.getPageSize().getWidth() - 100, document.getPageSize().getHeight() - 100);
            section.add(img);
            if (legend != null)
                writeParagraph(legend, element);
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot add given image to document", e);
    }
}

From source file:questions.importpages.HelloWorldImportedPages.java

/**
 * Generates a PDF file with bookmarks.//from w  ww . j  a v  a 2 s .  c o  m
 * 
 * @param filename
 *            the filename of the PDF file.
 */
private static void createPdf(String filename) {
    // we create a document with multiple pages and bookmarks
    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        document.add(new Paragraph(
                "In this document, we are going to say hello to different beings in different languages."));
        document.newPage();
        Paragraph hello = new Paragraph(
                "(English:) hello, " + "(Esperanto:) he, alo, saluton, (Latin:) heu, ave, "
                        + "(French:) all\u00f4, (Italian:) ciao, (German:) hallo, he, heda, holla, "
                        + "(Portuguese:) al\u00f4, ol\u00e1, hei, psiu, bom d\u00eda, (Dutch:) hallo, dag, "
                        + "(Spanish:) ola, eh, (Catalan:) au, bah, eh, ep, "
                        + "(Swedish:) hej, hejsan(Danish:) hallo, dav, davs, goddag, hej, "
                        + "(Norwegian:) hei; morn, (Papiamento:) halo; hallo; k\u00ed tal, "
                        + "(Faeroese:) hall\u00f3, hoyr, (Turkish:) alo, merhaba, (Albanian:) tungjatjeta");
        Chapter universe = new Chapter("To the Universe:", 1);
        Section section;
        section = universe.addSection("to the World:");
        section.add(hello);
        section = universe.addSection("to the Sun:");
        section.add(hello);
        section = universe.addSection("to the Moon:");
        section.add(hello);
        section = universe.addSection("to the Stars:");
        section.add(hello);
        document.add(universe);
        Chapter people = new Chapter("To the People:", 2);
        section = people.addSection("to mothers and fathers:");
        section.add(hello);
        section = people.addSection("to brothers and sisters:");
        section.add(hello);
        section = people.addSection("to wives and husbands:");
        section.add(hello);
        section = people.addSection("to sons and daughters:");
        section.add(hello);
        section = people.addSection("to complete strangers:");
        section.add(hello);
        document.add(people);
        document.setPageSize(PageSize.A4.rotate());
        Chapter animals = new Chapter("To the Animals:", 3);
        section = animals.addSection("to cats and dogs:");
        section.add(hello);
        section = animals.addSection("to birds and bees:");
        section.add(hello);
        section = animals.addSection("to farm animals and wild animals:");
        section.add(hello);
        section = animals.addSection("to bugs and beatles:");
        section.add(hello);
        section = animals.addSection("to fish and shellfish:");
        section.add(hello);
        document.add(animals);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.objects.ChaptersAndMemory.java

/**
 * Generates a PDF file with autonumbered chapters and an open bookmark tab
 * //  w w w . j  a  v a2 s  .  c o  m
 * @param args
 *            no arguments needed here
 */
public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document();
    try {
        // step 2:
        // we create a writer
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document
        Phrase text = new Phrase("Quick brown fox jumps over the lazy dog. ");
        ChapterAutoNumber chapter1 = new ChapterAutoNumber("This is a sample sentence:");
        chapter1.setBookmarkTitle("The fox");
        chapter1.setBookmarkOpen(false);
        chapter1.setComplete(false);
        Section section1 = chapter1.addSection("Quick");
        section1.add(text);
        section1.add(text);
        section1.add(text);
        document.add(chapter1);
        Section section2 = chapter1.addSection("Fox");
        section2.add(text);
        section2.setComplete(false);
        document.add(chapter1);
        section2.add(text);
        section2.add(text);
        section2.setComplete(true);
        chapter1.setComplete(true);
        document.add(chapter1);
        ChapterAutoNumber chapter2 = new ChapterAutoNumber("Jumps");
        chapter2.setComplete(false);
        Section section = chapter2.addSection("Over");
        section.setComplete(false);
        section.add(text);
        section.add(text);
        section.add(text);
        Section subsection1 = section.addSection("Lazy");
        subsection1.setIndentationLeft(30);
        subsection1.add(text);
        subsection1.setComplete(false);
        document.add(chapter2);
        subsection1.add(text);
        subsection1.add(text);
        subsection1.add(text);
        subsection1.add(text);
        subsection1.setComplete(true);
        Section subsection2 = section.addSection("Dog");
        subsection2.setIndentationRight(30);
        subsection2.add(text);
        subsection2.add(text);
        subsection2.add(text);
        subsection2.add(text);
        subsection2.add(text);
        Section subsection3 = section.addSection("Did you see it?");
        subsection3.setIndentation(50);
        subsection3.add(text);
        subsection3.add(text);
        subsection3.add(text);
        subsection3.add(text);
        subsection3.add(text);
        section.setComplete(true);
        document.add(chapter2);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

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

From source file:sg.edu.nus.util.ReportWriter.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a  little list
    createList(subCatPart);/*from www  .j av  a 2s.c  o  m*/

    // Add a small table
    createTable(subCatPart);
    // Now a small table

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

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

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

}

From source file:sg.edu.nus.util.ReportWriter.java

private static void createTable(Section subCatPart) throws BadElementException {
    Table t = new Table(3, 2);

    t.setBorderColor(Color.GRAY);
    t.setPadding(4);//from   ww w  . j a va2s.c  om
    t.setSpacing(4);
    t.setBorderWidth(1);

    Cell c1 = new Cell("Table Header 1");
    c1.setHeader(true);
    t.addCell(c1);
    c1 = new Cell("Table Header 2");
    t.addCell(c1);
    c1 = new Cell("Table Header 3");
    t.addCell(c1);
    t.endHeaders();

    t.addCell("1.0");
    t.addCell("1.1");
    t.addCell("1.2");
    t.addCell("2.1");
    t.addCell("2.2");
    t.addCell("2.3");

    subCatPart.add(t);

}