Example usage for com.itextpdf.text FontFactory HELVETICA

List of usage examples for com.itextpdf.text FontFactory HELVETICA

Introduction

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

Prototype

String HELVETICA

To view the source code for com.itextpdf.text FontFactory HELVETICA.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException {

    // This creates our new PDF document and declares its orientation
    Document pdfDoc;/*from w w  w  . ja  v a  2  s  . c om*/
    if (orientationIsPortrait) {
        pdfDoc = new Document(PageSize.LETTER); // portrait
    } else {
        pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape
    }
    PdfWriter.getInstance(pdfDoc, out);

    // Measurements are always in points (72 per inch)
    // This sets up 1/2 inch margins side margins and 0.35in top and bottom
    // margins
    pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH,
            0.35f * POINTS_PER_INCH);
    pdfDoc.open();

    // Header cell with challenge title to add to both scoresheets
    final Paragraph titleParagraph = new Paragraph();
    final Chunk titleChunk = new Chunk(m_pageTitle,
            FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.setAlignment(Element.ALIGN_CENTER);
    titleParagraph.add(titleChunk);

    titleParagraph.add(Chunk.NEWLINE);
    final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(),
            FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.add(swVersionChunk);
    if (null != m_revision) {

        final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision,
                FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));

        titleParagraph.add(revisionChunk);
    }

    final PdfPCell head = new PdfPCell();
    head.setColspan(2);
    head.setBorder(1);
    head.setPaddingTop(0);
    head.setPaddingBottom(3);
    head.setBackgroundColor(new BaseColor(64, 64, 64));
    head.setVerticalAlignment(Element.ALIGN_TOP);
    head.addElement(titleParagraph);

    // Cells for score field, and 2nd check initials
    final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL);
    final PdfPCell desC = new PdfPCell(des);
    desC.setBorder(0);
    desC.setPaddingTop(9);
    desC.setPaddingRight(36);
    desC.setHorizontalAlignment(Element.ALIGN_RIGHT);
    final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL);
    final PdfPCell sciC = new PdfPCell(sci);
    sciC.setBorder(0);
    sciC.setPaddingTop(9);
    sciC.setPaddingRight(36);
    sciC.setHorizontalAlignment(Element.ALIGN_RIGHT);

    // Create a table with a grid cell for each scoresheet on the page
    PdfPTable wholePage = getTableForPage(orientationIsPortrait);
    wholePage.setWidthPercentage(100);
    for (int i = 0; i < m_numSheets; i++) {
        if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) {
            pdfDoc.newPage();
            wholePage = getTableForPage(orientationIsPortrait);
            wholePage.setWidthPercentage(100);
        }

        // This table is a single score sheet
        final PdfPTable scoreSheet = new PdfPTable(2);
        // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM
        // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER
        scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        scoreSheet.getDefaultCell().setPaddingRight(1);
        scoreSheet.getDefaultCell().setPaddingLeft(0);

        scoreSheet.addCell(head);

        final PdfPTable teamInfo = new PdfPTable(7);
        teamInfo.setWidthPercentage(100);
        teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f });

        // Time label cell
        final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL);
        timeP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell());
        timeLc.addElement(timeP);
        teamInfo.addCell(timeLc);
        // Time value cell
        final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL);
        final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell());
        timeVc.addElement(timeV);
        teamInfo.addCell(timeVc);

        // Table label cell
        final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL);
        tblP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell());
        tblLc.addElement(tblP);
        teamInfo.addCell(tblLc);
        // Table value cell
        final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL);
        final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell());
        tblVc.addElement(tblV);
        teamInfo.addCell(tblVc);

        // Round number label cell
        final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL);
        rndP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell());
        rndlc.addElement(rndP);
        teamInfo.addCell(rndlc);
        // Round number value cell
        final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL);
        final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell());
        // rndVc.setColspan(2);
        rndVc.addElement(rndV);
        teamInfo.addCell(rndVc);

        final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp1.setColspan(2);
        temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp1);

        // Team number label cell
        final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL);
        nbrP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrlc.addElement(nbrP);
        teamInfo.addCell(nbrlc);
        // Team number value cell
        final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]),
                COURIER_10PT_NORMAL);
        final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrVc.addElement(nbrV);
        teamInfo.addCell(nbrVc);

        // Team division label cell
        final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL);
        divP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell());
        divlc.addElement(divP);
        divlc.setColspan(2);
        teamInfo.addCell(divlc);
        // Team division value cell
        final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL);
        final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell());
        divVc.setColspan(2);
        divVc.addElement(divV);
        teamInfo.addCell(divVc);

        final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp2.setColspan(2);
        temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp2);

        // Team name label cell
        final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL);
        nameP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell());
        namelc.setColspan(2);
        namelc.addElement(nameP);
        teamInfo.addCell(namelc);
        // Team name value cell
        final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL);
        final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell());
        nameVc.setColspan(5);
        nameVc.addElement(nameV);
        teamInfo.addCell(nameVc);

        // add team info cell to the team table
        final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell());
        teamInfoCell.addElement(teamInfo);
        teamInfoCell.setColspan(2);

        scoreSheet.addCell(teamInfoCell);

        if (null != m_goalsTable) {
            final PdfPCell goalCell = new PdfPCell(m_goalsTable);
            goalCell.setBorder(0);
            goalCell.setPadding(0);
            goalCell.setColspan(2);
            scoreSheet.addCell(goalCell);
        }

        scoreSheet.addCell(desC);
        scoreSheet.addCell(sciC);

        if (null != m_copyright) {
            final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i);
            final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell());
            copyrightC.addElement(copyright);
            copyrightC.setBorder(0);
            copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER);
            copyrightC.setColspan(2);

            scoreSheet.addCell(copyrightC);
        }

        // the cell in the whole page table that will contain the single score
        // sheet
        final PdfPCell scoresheetCell = new PdfPCell(scoreSheet);
        scoresheetCell.setBorder(0);
        scoresheetCell.setPadding(0);

        // Interior borders between scoresheets on a page
        if (!orientationIsPortrait) {
            if (i % 2 == 0) {
                scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH);
            } else {
                scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH);
            }
        }

        // Add the current scoresheet to the page
        wholePage.addCell(scoresheetCell);

        // Add the current table of scoresheets to the document
        if (orientationIsPortrait || (i % 2 != 0)) {
            pdfDoc.add(wholePage);
        }
    }

    // Add a blank cells to complete the table of the last page
    if (!orientationIsPortrait && m_numSheets % 2 != 0) {
        final PdfPCell blank = new PdfPCell();
        blank.setBorder(0);
        wholePage.addCell(blank);
        pdfDoc.add(wholePage);
    }

    pdfDoc.close();
}

From source file:hsa.awp.admingui.report.printer.PdfPrinter.java

License:Open Source License

@Override
public void print(ExportList list) {

    if (outputStream == null) {
        throw new IllegalArgumentException("OutputStream undefined, please use setOutputStream()");
    }//from www  .j  av  a 2s .c  om

    if (!(list instanceof PdfPrintable)) {
        throw new IllegalArgumentException("PdfPrinter can only print PdfPrintables");
    }

    PdfPrintable pdfPrintable = (PdfPrintable) list;
    Document document = setUpDocument(pdfPrintable);

    try {
        document.open();

        int numberOfColumns = pdfPrintable.getPdfProperties().getCellProperties().size();
        int numberOfRows = list.getRows().size();

        PdfPTable table = new PdfPTable(numberOfColumns);

        float[] widths = new float[numberOfColumns];

        for (int i = 0; i < widths.length; i++) {
            widths[i] = pdfPrintable.getPdfProperties().getCellProperties().get(i).getWidth();
        }

        table.setWidths(widths);

        /* header */
        for (PdfCellProperties cellProperties : pdfPrintable.getPdfProperties().getCellProperties()) {
            PdfPCell cell = new PdfPCell(
                    new Phrase(cellProperties.getHeadline(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
        }

        /* content */
        int rowIndex = 0;
        for (Row row : list.getRows()) {
            int columnIndex = 0;
            for (String content : row.getContent()) {
                if (content != null) {
                    PdfPCell cell = new PdfPCell(
                            new Phrase(content, FontFactory.getFont(FontFactory.HELVETICA)));
                    cell.setHorizontalAlignment(pdfPrintable.getPdfProperties().getCellProperties()
                            .get(columnIndex).getAlignment().getPdfAlign());
                    table.addCell(cell);
                } else {
                    table.addCell("");
                }
                columnIndex++;
            }
            rowIndex++;
        }

        //      /* footer */
        //      if (footerFound) {
        //        for (PdfTableColumn tableColumn : cols) {
        //          table.addCell(tableColumn.getFooter());
        //        }
        //      }

        document.add(table);

        document.add(new Phrase(" "));

        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:hsa.awp.admingui.report.util.HeaderFooter.java

License:Open Source License

/**
 * this method is called by Pageevent./*from  w w w  . j  a  v a2s.  c om*/
 *
 * @param writer   write of the document
 * @param document document it self
 */
public void onEndPage(PdfWriter writer, Document document) {

    Rectangle rect = writer.getBoxSize("art");
    /* title */
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT,
            new Phrase(title, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16)), rect.getLeft(),
            rect.getTop() + 20, 0);
    /* subtitle */
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT,
            new Phrase(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 9)), rect.getLeft(),
            rect.getTop() + 9, 0);
    /* date */

    DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    java.util.Date date = new java.util.Date();

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT,
            new Phrase(dateFormat.format(date)), rect.getRight(), rect.getTop() + 15, 0);
    /* pagenumber */
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase(String.format("Seite %d", writer.getPageNumber())),
            (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 25, 0);
}

From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java

License:Apache License

/**
 * Adds a page for a given week.//  w ww.  j av  a  2 s.co m
 * @param i the week number
 * @param doc the document to update
 * @param bean a generation bean (not null)
 * @throws DocumentException
 */
private void addPageForWeek(int weekNumber, Document doc, GenerationDataBean bean) throws DocumentException {

    doc.newPage();
    final Font boldFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA);
    Calendar calendar = Utils.findCalendar(weekNumber);

    // Title
    Paragraph paragraph = new Paragraph("Bordereau de Dclaration des Temps", boldFont);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    doc.add(paragraph);

    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Meta: week
    final PdfPTable metaTable = new PdfPTable(1);

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Semaine : ", boldFont));
    paragraph.add(new Chunk(String.valueOf(weekNumber), normalFont));

    PdfPCell c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    metaTable.addCell(c);

    // Meta: date
    Calendar endOfWeekCalendar = ((Calendar) calendar.clone());
    endOfWeekCalendar.add(Calendar.DATE, 4);
    String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(endOfWeekCalendar.getTime());

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Date : ", boldFont));
    paragraph.add(new Chunk(formattedDate, normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    metaTable.addCell(c);

    doc.add(metaTable);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Signatures
    final PdfPTable signaturesTable = new PdfPTable(2);
    paragraph = new Paragraph();
    paragraph.add(new Chunk("Nom : ", boldFont));
    paragraph.add(new Chunk(bean.getName(), normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Responsable : ", boldFont));
    paragraph.add(new Chunk(bean.getManagerName(), normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    c = new PdfPCell(new Paragraph("Signature : ", boldFont));
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    c = new PdfPCell(new Paragraph("Signature : ", boldFont));
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    doc.add(signaturesTable);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Calendar
    final PdfPTable timeTable = new PdfPTable(7);
    timeTable.addCell(new PdfPCell());

    for (int i = 0; i < 5; i++) {
        final String date = this.sdf.format(calendar.getTime());
        timeTable.addCell(newCell(date, 10));
        calendar.add(Calendar.DATE, 1);
    }

    timeTable.addCell(newCell("Total", 10));
    timeTable.addCell(newCell("Heures Effectues", 20));

    for (int i = 0; i < 5; i++)
        timeTable.addCell(newCell("", 20));

    if (bean.getTotalHours() > 0)
        timeTable.addCell(newCell(bean.getTotalHours() + " h", 20));

    timeTable.completeRow();
    doc.add(timeTable);
}

From source file:org.com.controller.ProductController.java

@RequestMapping(value = "/repProduct", method = RequestMethod.GET)
public void productReport(Model m, HttpServletResponse response, HttpServletRequest request,
        OutputStream outputStream) throws Exception {
    String name = "ProductReport-";
    Date d = new Date();
    name = name + d.toString() + ".pdf";
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=" + name);
    Rectangle pagesize = new Rectangle(216f, 720f);
    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, outputStream);
    document.open();/*from   w  w  w.  ja v  a 2s. c o m*/
    document.addTitle("PRODUCT DETAILSA REPORT");
    document.add(new Paragraph("PRODUCT DETAILSA REPORT ",
            FontFactory.getFont(FontFactory.HELVETICA, 28, BaseColor.CYAN)));
    document.add(new Paragraph("DATE: " + new Date()));
    document.add(new Paragraph("-------------------------------------------------------- "));
    document.add(new Paragraph(" "));
    ProductDaoImpl pdi = new ProductDaoImpl();
    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell("ID");
    table.addCell("TITLE");
    table.addCell("PUBLISHER");
    table.addCell("PRICE");
    ArrayList<ProductTable> list = pdi.getAllProduct();
    for (ProductTable u : list) {
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPid().toString());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getPname());
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPublisher());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getSprice().toString());
    }
    document.add(table);
    document.close();

}

From source file:org.dspace.disseminate.CitationDocument.java

/**
 * Takes a DSpace {@link Bitstream} and uses its associated METADATA to
 * create a cover page.//from  ww w .  j  a  v  a 2s . com
 *
 * @param cDoc The cover page document to add cited information to.
 * @param writer
 * @param cMeta
 *            METADATA retrieved from the parent collection.
 * @throws IOException
 * @throws DocumentException
 */
private void generateCoverPage(Document cDoc, PdfWriter writer, CitationMeta cMeta) throws DocumentException {
    cDoc.open();
    writer.setCompressionLevel(0);

    Item item = cMeta.getItem();

    //Set up some fonts
    Font helv26 = FontFactory.getFont(FontFactory.HELVETICA, 26f, BaseColor.BLACK);
    Font helv16 = FontFactory.getFont(FontFactory.HELVETICA, 16f, BaseColor.BLACK);
    Font helv12 = FontFactory.getFont(FontFactory.HELVETICA, 12f, BaseColor.BLACK);
    Font helv12_italic = FontFactory.getFont(FontFactory.HELVETICA_OBLIQUE, 12f, BaseColor.BLACK);
    Font helv11_bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11f, BaseColor.BLACK);
    Font helv9 = FontFactory.getFont(FontFactory.HELVETICA, 9f, BaseColor.BLACK);

    // 1 - Header:
    //  University Name
    //  Repository Name                                                        repository.url
    Paragraph university = new Paragraph("The Ohio State University", helv11_bold);
    cDoc.add(university);

    PdfPTable repositoryTable = new PdfPTable(2);
    repositoryTable.setWidthPercentage(100);

    Chunk repositoryName = new Chunk("Knowledge Bank", helv11_bold);
    PdfPCell nameCell = new PdfPCell();
    nameCell.setBorderWidth(0);
    nameCell.addElement(repositoryName);

    Chunk repositoryURL = new Chunk("kb.osu.edu", helv11_bold);
    repositoryURL.setAnchor("http://kb.osu.edu");

    PdfPCell urlCell = new PdfPCell();
    urlCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    urlCell.setBorderWidth(0);
    urlCell.addElement(repositoryURL);

    repositoryTable.addCell(nameCell);
    repositoryTable.addCell(urlCell);

    repositoryTable.setSpacingAfter(5);

    cDoc.add(repositoryTable);

    // Line Separator
    LineSeparator lineSeparator = new LineSeparator();
    cDoc.add(lineSeparator);

    // 2 - Bread Crumbs
    // Community Name                                                          Collection Name
    PdfPTable breadcrumbTable = new PdfPTable(2);
    breadcrumbTable.setWidthPercentage(100);

    Chunk communityName = new Chunk(getOwningCommunity(item), helv9);
    PdfPCell commCell = new PdfPCell();
    commCell.setBorderWidth(0);
    commCell.addElement(communityName);

    Chunk collectionName = new Chunk(getOwningCollection(item), helv9);
    PdfPCell collCell = new PdfPCell();
    collCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    collCell.setBorderWidth(0);
    collCell.addElement(collectionName);

    breadcrumbTable.addCell(commCell);
    breadcrumbTable.addCell(collCell);

    breadcrumbTable.setSpacingBefore(5);
    breadcrumbTable.setSpacingAfter(5);

    cDoc.add(breadcrumbTable);

    // Line Separator
    cDoc.add(lineSeparator);

    // 3 - Metadata
    // date.issued
    // dc.title
    // dc.creator; dc.creator
    Paragraph dateIssued = new Paragraph(getFirstMetadata(item, "dc.date.issued"), helv12);
    dateIssued.setSpacingBefore(20);
    cDoc.add(dateIssued);

    Paragraph title = new Paragraph(item.getName(), helv26);
    title.setSpacingBefore(15);
    cDoc.add(title);

    Paragraph creators = new Paragraph(getAllMetadataSeperated(item, "dc.creator"), helv16);
    creators.setSpacingBefore(30);
    creators.setSpacingAfter(20);
    cDoc.add(creators);

    // Line Separator
    cDoc.add(lineSeparator);

    // 4 - Citation
    // dc.identifier.citation
    // dc.identifier.uri
    Paragraph citation = new Paragraph(getFirstMetadata(item, "dc.identifier.citation"), helv12);

    Chunk identifierChunk = new Chunk(getFirstMetadata(item, "dc.identifier.uri"), helv12);
    identifierChunk.setAnchor(getFirstMetadata(item, "dc.identifier.uri"));

    Paragraph identifier = new Paragraph();
    identifier.add(identifierChunk);

    cDoc.add(citation);
    cDoc.add(identifier);

    // 5 - License
    // Downloaded from the Knowledge Bank, The Ohio State University's institutional repository
    Paragraph license = new Paragraph(
            "Downloaded from the Knowledge Bank, The Ohio State University's institutional repository",
            helv12_italic);
    license.setSpacingBefore(10);
    cDoc.add(license);

    cDoc.close();
}

From source file:org.flowable.app.rest.runtime.RelatedContentResource.java

License:Apache License

void createPdf(String dest, ArrayList<String> info) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();//  w  ww. jav  a  2s .  c om
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Chunk chunk = new Chunk("Relatrio", chapterFont);
    Chapter chapter = new Chapter(new Paragraph(chunk), 1);
    chapter.setNumberDepth(0);

    int i = 0;
    for (; i < info.size(); i++) {
        chapter.add(new Paragraph(info.get(i), paragraphFont));
    }
    document.add(chapter);
    document.close();
}

From source file:org.jaqpot.core.service.data.ReportService.java

public void report2PDF(Report report, OutputStream os) {

    Document document = new Document();
    document.setPageSize(PageSize.A4);//  w  ww .  ja v  a 2s . com
    document.setMargins(50, 45, 80, 40);
    document.setMarginMirroring(false);

    try {
        PdfWriter writer = PdfWriter.getInstance(document, os);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);

    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    document.open();

    /** setup fonts for pdf */
    Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);

    /** print link to jaqpot*/
    Chunk chunk = new Chunk(
            "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage",
            ffont);
    chunk.setAnchor("http://www.jaqpot.org");

    Paragraph paragraph = new Paragraph(chunk);
    paragraph.add(Chunk.NEWLINE);

    Chapter chapter = new Chapter(paragraph, 1);
    chapter.setNumberDepth(0);

    /** get title */
    String title = null;
    if (report.getMeta() != null && report.getMeta().getTitles() != null
            && !report.getMeta().getTitles().isEmpty())
        title = report.getMeta().getTitles().iterator().next();

    /** print title aligned centered in page */
    if (title == null)
        title = "Report";
    chunk = new Chunk(title, chapterFont);
    paragraph = new Paragraph(chunk);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(Chunk.NEWLINE);

    chapter.add(paragraph);

    /** report Description */
    if (report.getMeta() != null && report.getMeta().getDescriptions() != null
            && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        paragraph = new Paragraph();
        paragraph.add(new Chunk("Description: ", paragraphFontBold));
        paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"),
                paragraphFont));
        chapter.add(paragraph);
        chapter.add(Chunk.NEWLINE);
    }

    /** report model, algorithm and/or dataset id */
    if (report.getMeta() != null && report.getMeta().getHasSources() != null
            && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        Iterator<String> sources = report.getMeta().getHasSources().iterator();
        sources.forEachRemaining(o -> {
            if (o != null) {
                String[] source = o.split("/");
                if (source[source.length - 2].trim().equals("model")
                        || source[source.length - 2].trim().equals("algorithm")
                        || source[source.length - 2].trim().equals("dataset")) {
                    Paragraph paragraph1 = new Paragraph();
                    paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase()
                            + source[source.length - 2].substring(1) + ": ", paragraphFontBold));
                    paragraph1.add(new Chunk(source[source.length - 1], paragraphFont));
                    chapter.add(paragraph1);
                    chapter.add(Chunk.NEWLINE);
                }
            }
        });
    }

    /** report single calculations */
    report.getSingleCalculations().forEach((key, value) -> {
        Paragraph paragraph1 = new Paragraph();
        paragraph1 = new Paragraph();
        paragraph1.add(new Chunk(key + ": ", paragraphFontBold));
        paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    });

    /** report date of completion */
    if (report.getMeta() != null && report.getMeta().getDate() != null) {
        Paragraph paragraph1 = new Paragraph();
        paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold));
        paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    }

    try {
        document.add(chapter);
    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    Integer chapterNumber = 0;

    /** report all_data */
    for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) {
        String label = entry.getKey();
        ArrayCalculation ac = entry.getValue();
        PdfPTable table = new PdfPTable(ac.getColNames().size() + 1);
        for (Entry<String, List<Object>> row : ac.getValues().entrySet()) {

            try {
                XMLWorkerHelper.getInstance().parseXHtml(w -> {
                    if (w instanceof WritableElement) {
                        List<Element> elements = ((WritableElement) w).elements();
                        for (Element element : elements) {
                            PdfPCell pdfCell = new PdfPCell();
                            pdfCell.addElement(element);
                            table.addCell(pdfCell);
                        }
                    }
                }, new StringReader(row.getKey()));
            } catch (IOException e) {
                e.printStackTrace();
            }

            for (Object o : row.getValue()) {
                table.addCell(o.toString());
            }
            table.completeRow();
        }
        try {
            Chunk tableChunk = new Chunk(label, tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(Chunk.NEWLINE);
            tableChapter.add(table);
            document.newPage();
            document.add(tableChapter);
        } catch (DocumentException ex) {
            throw new InternalServerErrorException(ex);
        }
    }

    /** report plots */
    for (Entry<String, String> entry : report.getFigures().entrySet()) {
        try {
            byte[] valueDecoded = Base64.decodeBase64(entry.getValue());
            Image l = Image.getInstance(valueDecoded);
            document.newPage();
            //image starts at the half's half of pdf page
            l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2));
            l.scaleToFit(document.getPageSize());

            Chunk tableChunk = new Chunk(entry.getKey(), tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(l);
            document.add(tableChapter);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }
    document.close();
}

From source file:org.javad.pdf.fonts.FontRegistry.java

License:Apache License

public Font getFont(PdfFontDefinition name) {
    Font f = null;//from  ww  w  .  j a  va 2s . com
    initializeFontTable();
    PdfFontBean bean = fontMap.get(name);
    if (bean == null) {
        throw new IllegalArgumentException(
                "The name \"" + name.toString() + "\" was not found in the mapping.");
    }
    if (calculatedFonts.containsKey(bean)) {
        return calculatedFonts.get(bean);
    }
    if (bean.isSystem()) {
        initializeFonts();
        f = findFont(bean.getFontFamily(), bean);
    } else if (bean.getFontMapping() != null) {
        logger.log(Level.FINE, "Using a mapped font for \"{0}\"", name);
        PdfFontMapping mapping = bean.getFontMapping();
        FontFactory.register(mapping.getFilePath(), mapping.getFontAlias());
        f = findFont(mapping.getFontAlias(), bean);
    }
    if (isFontInvalid(f)) {
        logger.log(Level.INFO, "Unable to find a registered font for \"{0}\" using default of Helvetica", name);
        f = FontFactory.getFont(FontFactory.HELVETICA, name.getDefaultSize(), name.getDefaultStyle());
    }
    calculatedFonts.put(bean, f);
    return f;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

License:Open Source License

/**
 * Writes an annotation into the pdf file.
 * //ww  w  . j  a  va 2s. c  om
 * @param annotation
 * @param document
 * @throws DocumentException
 */
private void addAnnotationToPDF(String annotation, Document document) throws DocumentException {
    Paragraph para = new Paragraph();
    Font font = FontFactory.getFont(FontFactory.HELVETICA, 12);
    para.setFont(font);
    para.setLeading(14F);
    para.add(annotation);
    document.add(para);
}