Example usage for com.lowagie.text Paragraph setAlignment

List of usage examples for com.lowagie.text Paragraph setAlignment

Introduction

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

Prototype

public void setAlignment(String alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:org.posterita.core.TabularReport.java

License:Open Source License

public String createPDFReport() throws DocumentException, FileNotFoundException {
    String filename = RandomStringGenerator.randomstring() + ".pdf";
    String filepath = ReportManager.getReportPath(filename);

    FileOutputStream fos = new FileOutputStream(filepath);

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);

    document.open();//  w w  w  .  j  av a  2s  .  com

    Font style1 = new Font(Font.HELVETICA, 16.0f, Font.BOLD);
    Font style2 = new Font(Font.HELVETICA, 12.0f);
    //write content
    Paragraph p = new Paragraph(new Chunk(title, style1));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    p = new Paragraph(new Chunk(subtitle, style2));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    p = new Paragraph("\n\n");
    document.add(p);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);
    for (Object[] row : reportData) {
        for (Object data : row) {
            PdfPCell cell = new PdfPCell(new Phrase(data.toString()));
            table.addCell(cell);
        }
    }

    document.add(table);
    document.close();

    return filename;
}

From source file:org.posterita.core.TabularReport2.java

License:Open Source License

public String createPDFReport() throws DocumentException, FileNotFoundException {
    String filename = RandomStringGenerator.randomstring() + ".pdf";
    String filepath = ReportManager.getReportPath(filename);

    FileOutputStream fos = new FileOutputStream(filepath);

    Document document = new Document(PageSize.A4.rotate());
    PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);

    document.open();//w  w w  . jav  a 2s  .  c  o m

    Font style1 = new Font(Font.HELVETICA, 16.0f, Font.BOLD);
    Font style2 = new Font(Font.HELVETICA, 14.0f);
    Font style3 = new Font(Font.HELVETICA, 10.0f);

    //write content
    Paragraph p = new Paragraph(new Chunk(title, style1));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    p = new Paragraph(new Chunk(subtitle, style2));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    p = new Paragraph("\n\n");
    document.add(p);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);
    table.setWidthPercentage(100.0f);

    //int[] widths = new int[]{1,2,1,4};
    //table.setWidths(widths);

    for (Object[] row : reportData) {
        for (Object data : row) {
            PdfPCell cell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(cell);
        }
    }

    document.add(table);
    document.close();

    return filename;
}

From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java

License:Open Source License

/**
 * Implement the paragraph alignment//from  w  ww. j  a  va2 s  . c  o m
 *
 * @param para the paragraph to align
 * @param pData the PdfData container holding the current settings of the PDF output
 */
void doParagraphAlignment(final Paragraph para, final PdfData pData) {
    switch (pData.getAlignment()) {
    case Alignment.CENTER:
        para.setAlignment(Element.ALIGN_CENTER);
        break;
    case Alignment.JUST:
        para.setAlignment(Element.ALIGN_JUSTIFIED);
        break;
    case Alignment.LEFT:
        para.setAlignment(Element.ALIGN_LEFT);
        break;
    case Alignment.RIGHT:
        para.setAlignment(Element.ALIGN_RIGHT);
        break;
    default: // ignore in case of other possibility
        break;
    }
}

From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java

License:Educational Community License

public void addTitlePage(String evaltitle, String groupNames, String startDate, String endDate,
        String responseInformation, byte[] bannerImageBytes, String evalSystemTitle, String informationTitle) {
    try {//from  w w w.  j a  v  a 2s.  c o m
        float pagefooter = paragraphFont.getSize();

        PdfContentByte cb = pdfWriter.getDirectContent();

        float docMiddle = (document.right() - document.left()) / 2 + document.leftMargin();

        Paragraph emptyPara = new Paragraph(" ");
        emptyPara.setSpacingAfter(100.0f);

        // Title
        Paragraph titlePara = new Paragraph("\n\n\n" + evaltitle, frontTitleFont);
        titlePara.setAlignment(Element.ALIGN_CENTER);
        document.add(titlePara);

        // Groups

        Paragraph groupPara = new Paragraph(groupNames, frontAuthorFont);
        groupPara.setSpacingBefore(25.0f);
        groupPara.setAlignment(Element.ALIGN_CENTER);
        document.add(groupPara);

        // Little info area? I don't know, it was on the mockup though
        Paragraph infoPara = new Paragraph(informationTitle, frontInfoFont);
        infoPara.setAlignment(Element.ALIGN_CENTER);
        infoPara.setSpacingBefore(90.0f);
        document.add(infoPara);

        // Started on
        Paragraph startedPara = new Paragraph(startDate, frontInfoFont);
        startedPara.setAlignment(Element.ALIGN_CENTER);
        startedPara.setSpacingBefore(25.0f);
        document.add(startedPara);

        // Ended on
        Paragraph endedPara = new Paragraph(endDate, frontInfoFont);
        endedPara.setAlignment(Element.ALIGN_CENTER);
        endedPara.setSpacingBefore(25.0f);
        document.add(endedPara);

        // Reply Rate
        Paragraph replyRatePara = new Paragraph(responseInformation, frontInfoFont);
        replyRatePara.setAlignment(Element.ALIGN_CENTER);
        replyRatePara.setSpacingBefore(25.0f);
        document.add(replyRatePara);

        // Logo and Tagline
        cb.beginText();
        cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, evalSystemTitle, docMiddle, document.bottom() + 20, 0);
        cb.endText();

        if (bannerImageBytes != null) {
            Image banner = Image.getInstance(bannerImageBytes);
            cb.addImage(banner, banner.getWidth(), 0, 0, banner.getHeight(),
                    docMiddle - (banner.getWidth() / 2), document.bottom() + 35);
        }

        document.newPage();

        responseArea = new ColumnText(cb);
        responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2,
                document.bottom() + pagefooter);
        responseArea.go();
    } catch (DocumentException | IOException de) {
        throw UniversalRuntimeException.accumulate(de, "Unable to create title page");
    }
}

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

License:Open Source License

private void printDashboard(Project project, Section section) throws DocumentException {
    PdfPTable dashboard = new PdfPTable(3);
    dashboard.getDefaultCell().setBorderColor(Color.WHITE);
    Font titleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK);
    Font dataFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.GRAY);
    Font dataFont2 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD, new Color(100, 150, 190));

    PdfPTable linesOfCode = new PdfPTable(1);
    linesOfCode.getDefaultCell().setBorderColor(Color.WHITE);
    linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), titleFont));
    linesOfCode.addCell(new Phrase(project.getMeasure("ncss").getFormatValue(), dataFont));
    linesOfCode.addCell(//from  w  w  w  .j  a v a 2s .  c  o m
            new Phrase(project.getMeasure("packages_count").getFormatValue() + " packages", dataFont2));
    linesOfCode
            .addCell(new Phrase(project.getMeasure("classes_count").getFormatValue() + " classes", dataFont2));
    linesOfCode.addCell(
            new Phrase(project.getMeasure("functions_count").getFormatValue() + " methods", dataFont2));
    linesOfCode.addCell(new Phrase(
            project.getMeasure("duplicated_lines_ratio").getFormatValue() + " duplicated lines", dataFont2));

    PdfPTable comments = new PdfPTable(1);
    comments.getDefaultCell().setBorderColor(Color.WHITE);
    comments.addCell(new Phrase(getTextProperty("general.comments"), titleFont));
    comments.addCell(new Phrase(project.getMeasure("comment_ratio").getFormatValue(), dataFont));
    comments.addCell(
            new Phrase(project.getMeasure("comment_lines").getFormatValue() + " comment lines", dataFont2));

    PdfPTable codeCoverage = new PdfPTable(1);
    codeCoverage.getDefaultCell().setBorderColor(Color.WHITE);
    codeCoverage.addCell(new Phrase(getTextProperty("general.test_count"), titleFont));
    codeCoverage.addCell(new Phrase(project.getMeasure("test_count").getFormatValue(), dataFont));
    codeCoverage.addCell(
            new Phrase(project.getMeasure("test_success_percentage").getFormatValue() + " success", dataFont2));
    codeCoverage
            .addCell(new Phrase(project.getMeasure("code_coverage").getFormatValue() + " coverage", dataFont2));

    PdfPTable complexity = new PdfPTable(1);
    complexity.getDefaultCell().setBorderColor(Color.WHITE);
    complexity.addCell(new Phrase(getTextProperty("general.complexity"), titleFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_function").getFormatValue(), dataFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_class").getFormatValue() + " /class", dataFont2));
    complexity.addCell(new Phrase(project.getMeasure("ccn").getFormatValue() + " decision points", dataFont2));

    PdfPTable rulesCompliance = new PdfPTable(1);
    rulesCompliance.getDefaultCell().setBorderColor(Color.WHITE);
    rulesCompliance.addCell(new Phrase(getTextProperty("general.rules_compliance"), titleFont));
    rulesCompliance.addCell(new Phrase(project.getMeasure("rules_compliance").getFormatValue(), dataFont));

    PdfPTable violations = new PdfPTable(1);
    violations.getDefaultCell().setBorderColor(Color.WHITE);
    violations.addCell(new Phrase(getTextProperty("general.violations"), titleFont));
    violations.addCell(new Phrase(project.getMeasure("rules_violations").getFormatValue(), dataFont));

    dashboard.addCell(linesOfCode);
    dashboard.addCell(comments);
    dashboard.addCell(codeCoverage);
    dashboard.addCell(complexity);
    dashboard.addCell(rulesCompliance);
    dashboard.addCell(violations);
    dashboard.setSpacingBefore(8);
    section.add(dashboard);
    Image ccnDistGraph = getCCNDistribution(project);
    if (ccnDistGraph != null) {
        section.add(ccnDistGraph);
        Paragraph imageFoot = new Paragraph(getTextProperty("metrics.ccn_classes_count_distribution"),
                Style.FOOT_FONT);
        imageFoot.setAlignment(Paragraph.ALIGN_CENTER);
        section.add(imageFoot);
    }
}

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

License:Open Source License

@Override
protected void printTocTitle(Toc tocDocument) throws DocumentException {
    Paragraph tocTitle = new Paragraph(super.getTextProperty("main.table.of.contents"), Style.TOC_TITLE_FONT);
    tocTitle.setAlignment(Element.ALIGN_CENTER);
    tocDocument.getTocDocument().add(tocTitle);
    tocDocument.getTocDocument().add(Chunk.NEWLINE);
}

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

License:Open Source License

@Override
protected void printTocTitle(Toc tocDocument) throws com.lowagie.text.DocumentException {
    Paragraph tocTitle = new Paragraph(super.getTextProperty("main.table.of.contents"), Style.TOC_TITLE_FONT);
    tocTitle.setAlignment(Element.ALIGN_CENTER);
    tocDocument.getTocDocument().add(tocTitle);
    tocDocument.getTocDocument().add(Chunk.NEWLINE);
}

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

License:Open Source License

@Override
protected void printTocTitle(Toc tocDocument) throws com.lowagie.text.DocumentException {
    Paragraph tocTitle = new Paragraph(super.getTextProperty("extendedpdf.main.table.of.contents"),
            Style.TOC_TITLE_FONT);
    tocTitle.setAlignment(Element.ALIGN_CENTER);
    tocDocument.getTocDocument().add(tocTitle);
    tocDocument.getTocDocument().add(Chunk.NEWLINE);
}

From source file:org.squale.welcom.outils.pdf.advanced.WPdfSummary.java

License:Open Source License

/**
 * @param doc le document//  www . j av  a  2 s .  c o m
 * @throws DocumentException exception pouvant etre levee
 */
private void createSummary(final Document doc) throws DocumentException {

    // Document doc = new Document(A4);
    doc.open();
    // doc.newPage();

    // PLace de header
    doc.add(new Paragraph("a"));
    doc.add(new Paragraph("a"));

    final Paragraph p = new Paragraph("SOMMAIRE");
    p.setAlignment(Element.ALIGN_CENTER);
    doc.add(p);

    final List list = getBookmark();
    if (list != null) {
        final Iterator it = list.iterator();
        while (it.hasNext()) {
            final HashMap h = (HashMap) it.next();
            final Hashtable ht = new Hashtable(h);

            final String anchor = (String) ht.get("Page");
            final int page = Integer.parseInt(anchor.substring(0, anchor.indexOf(' ')));
            doc.add(new Paragraph(
                    (String) ht.get("Title") + "............................ page " + (page + 1)));

            /*
             * Anchor anchor = new Anchor((String)ht.get("Title")); //anchor1.set anchor.setReference("#2" );
             * doc.add(anchor);
             */

            /*
             * final Enumeration enumeration = ht.keys(); while (enumeration.hasMoreElements()) { final String key =
             * (String) enumeration.nextElement(); }
             */
        }
    }

    doc.close();
    // return doc;
}

From source file:org.tellervo.desktop.print.ProSheet.java

License:Open Source License

private Paragraph getObjectDescription() {

    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);/*from ww w .ja  va  2 s.com*/
    p.setAlignment(Element.ALIGN_JUSTIFIED);
    p.setSpacingAfter(10);
    p.setSpacingBefore(50);

    if (o.getDescription() != null) {
        p.add(new Chunk(o.getDescription(), bodyFont));
    } else {
        p.add(new Chunk("No description recorded", bodyFont));
    }

    return p;
}