Example usage for com.lowagie.text Chunk Chunk

List of usage examples for com.lowagie.text Chunk Chunk

Introduction

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

Prototype

public Chunk(DrawInterface separator, float tabPosition) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:org.egov.works.web.actions.tender.TenderNegotiationPDFGenerator.java

License:Open Source License

public void generatePDF() {
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(10);/*from   w ww  .j  a va 2s  . c om*/
    final List<String> tenderTypeList = worksService.getTendertypeList();
    if (tenderTypeList != null && !tenderTypeList.isEmpty())
        percTenderType = tenderTypeList.get(0);
    final String headerText = pdfLabel.get("tenderNegotiationpdf.header");
    try {
        final Paragraph headerTextPara = new Paragraph(
                new Chunk(headerText, new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
        headerTextPara.setAlignment(Element.ALIGN_CENTER);
        document.add(headerTextPara);
        document.add(makePara(cityName, Element.ALIGN_RIGHT));
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getWorksPackage() != null) {
            worksPackgeReq = YES;
            worksPackage = tenderResponse.getTenderEstimate().getWorksPackage();
        }
        String deptName = "";
        if (YES.equalsIgnoreCase(worksPackgeReq)) {
            deptName = tenderResponse.getTenderEstimate().getWorksPackage().getDepartment().getName();
            document.add(makePara(deptName, Element.ALIGN_RIGHT));
            if (getWardList(worksPackage) != null)
                document.add(makePara(
                        pdfLabel.get("tenderNegotiationpdf.ward") + "/"
                                + pdfLabel.get("tenderNegotiationpdf.zone") + getWardList(worksPackage),
                        Element.ALIGN_LEFT));
        } else {
            if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getExecutingDepartment() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getExecutingDepartment()
                            .getName() != null)
                deptName = tenderResponse.getTenderEstimate().getAbstractEstimate().getExecutingDepartment()
                        .getName();
            document.add(makePara(deptName, Element.ALIGN_RIGHT));
            if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getWard().getParent() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getWard() != null)
                document.add(makePara(pdfLabel.get("tenderNegotiationpdf.ward") + "/"
                        + pdfLabel.get("tenderNegotiationpdf.zone")
                        + tenderResponse.getTenderEstimate().getAbstractEstimate().getWard().getName() + "/"
                        + tenderResponse.getTenderEstimate().getAbstractEstimate().getWard().getParent()
                                .getName(),
                        Element.ALIGN_LEFT));
        }
        if (YES.equalsIgnoreCase(worksPackgeReq))
            document.add(makePara(
                    pdfLabel.get("tenderNegotiationpdf.nameofwork")
                            + tenderResponse.getTenderEstimate().getWorksPackage().getName(),
                    Element.ALIGN_LEFT));
        else if (tenderResponse != null && tenderResponse.getTenderEstimate() != null)
            document.add(makePara(
                    pdfLabel.get("tenderNegotiationpdf.nameofwork")
                            + tenderResponse.getTenderEstimate().getAbstractEstimate().getName(),
                    Element.ALIGN_LEFT));
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getTenderHeader() != null
                && tenderResponse.getTenderEstimate().getTenderHeader().getTenderNo() != null)
            document.add(makePara(
                    pdfLabel.get("tenderNumber")
                            + tenderResponse.getTenderEstimate().getTenderHeader().getTenderNo(),
                    Element.ALIGN_LEFT));
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getWorksPackage() != null)
            document.add(makePara(
                    pdfLabel.get("tenderFileNo")
                            + tenderResponse.getTenderEstimate().getWorksPackage().getTenderFileNumber(),
                    Element.ALIGN_LEFT));
        document.add(spacer());
        String tenderDate = "";
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getTenderHeader() != null
                && tenderResponse.getTenderEstimate().getTenderHeader().getTenderDate() != null)
            tenderDate = sdf.format(tenderResponse.getTenderEstimate().getTenderHeader().getTenderDate());
        document.add(
                makePara(pdfLabel.get("tenderNegotiationpdf.tenderdate") + tenderDate, Element.ALIGN_RIGHT));
        document.add(spacer());
        PdfPTable contractorTable = null;
        if (tenderResponse != null) {
            contractorTable = createContractorTable(tenderResponse);
            document.add(contractorTable);
        }
        document.add(spacer());

        if (tenderResponse != null
                && tenderResponse.getTenderEstimate().getTenderType().equalsIgnoreCase(percTenderType)) {
            PdfPTable negotiationTable = null;
            negotiationTable = createNegotiationTable(tenderResponse,
                    tenderResponse.getTenderResponseContractors().get(0).getContractor());
            document.add(negotiationTable);
            document.add(spacer());
            if (negotiationTable != null && negotiationTable.getRows().size() > 8)
                document.newPage();

        } else if (tenderResponse != null
                && !tenderResponse.getTenderEstimate().getTenderType().equalsIgnoreCase(percTenderType))
            createNegotiationTableForContractors(tenderResponse);

        if (tenderResponse != null && tenderResponse.getNegotiationPreparedBy() != null
                && tenderResponse.getNegotiationPreparedBy().getEmployeeName() != null)
            document.add(makePara(pdfLabel.get("tenderNegotiationpdf.preparedby") + " "
                    + tenderResponse.getNegotiationPreparedBy().getEmployeeName()));
        document.add(spacer());
        document.add(spacer());
        document.add(makePara(pdfLabel.get("tenderNegotiationpdf.checkedby")));
        document.newPage();

        PdfPTable approvaldetailsTable = null;
        if (tenderResponse != null)
            approvaldetailsTable = createApprovalDetailsTable(tenderResponse);

        if (approvaldetailsTable != null && approvaldetailsTable.getRows().size() != 1) {
            document.add(makePara(pdfLabel.get("tenderNegotiationpdf.approvaldetails")));
            document.add(spacer());
            document.add(approvaldetailsTable);
        }
        document.close();
    } catch (final DocumentException e) {
        throw new ApplicationRuntimeException(TENDER_PDF_ERROR, e);
    }
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Chunk newChunk(String s) throws DocumentException, IOException {
    if (s == null) {
        s = "";// w ww. j  a v a 2 s .c om
    }
    Chunk c = new Chunk(s, newFont());
    return c;
}

From source file:org.inbio.modeling.core.manager.impl.ExportManagerImpl.java

License:Open Source License

private void addTableRow(Table t, String title, String value) throws BadElementException {

    // Fonts Definition
    Font boldFont = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);
    Cell cell = new Cell(new Chunk(title, boldFont));
    cell.setHeader(true);//from www . j a v a  2  s .com
    t.addCell(cell);
    t.addCell(value);
}

From source file:org.inbio.modeling.core.manager.impl.ExportManagerImpl.java

License:Open Source License

private void addTableHeader(Table t, String text) throws BadElementException {
    Chunk chunk = new Chunk(text, new Font(Font.TIMES_ROMAN, 15, Font.BOLD));
    Cell cell = new Cell(chunk);
    cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
    cell.setHeader(true);//from ww  w  .java  2  s  .  c  om
    cell.setColspan(2);
    t.addCell(cell);

}

From source file:org.inbio.modeling.core.manager.impl.ExportManagerImpl.java

License:Open Source License

private void addImageSection(Document d, String mapName, Long currentSessionId)
        throws BadElementException, MalformedURLException, IOException, DocumentException {

    Image mapImage = Image.getInstance(mapsHome + mapName + "_T_" + currentSessionId + ".png");
    mapImage.scaleToFit(550, 413);/*from   w  w w.j  av a 2 s . c om*/
    mapImage.setAlignment(Image.ALIGN_LEFT);

    // scale
    Image scaleImage = Image.getInstance(mapsHome + "scale.jpg");
    scaleImage.scaleToFit(30, 150);
    scaleImage.setAlignment(Image.ALIGN_RIGHT);

    Paragraph images = new Paragraph();
    images.setAlignment(Paragraph.ALIGN_RIGHT);

    //upper scale leyend
    images.add(new Chunk(this.getI18nString("pdfReport.scaleUpper") + "\n\n\n\n\n\n\n",
            new Font(Font.COURIER, 8, Font.BOLDITALIC)));
    // Map
    images.add(new Chunk(mapImage, 1F, 1F));
    // Scale
    images.add(new Chunk(scaleImage, 1F, 1F));
    // lower scale leyend
    images.add(new Chunk("\n" + this.getI18nString("pdfReport.scaleLower") + "\n",
            new Font(Font.COURIER, 8, Font.BOLDITALIC)));

    d.add(images);
}

From source file:org.jivesoftware.openfire.archive.ConversationUtils.java

License:Open Source License

private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<String, Font> colorMap) {
    Font roomEvent = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.ITALIC, new Color(0xFF, 0x00, 0xFF));

    try {//from   ww w  .ja  v a2s  .c o  m
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new PDFEventListener());
        document.open();

        Paragraph p = new Paragraph(
                LocaleUtils.getLocalizedString("archive.search.pdf.title", MonitoringConstants.NAME),
                FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
        document.add(p);
        document.add(Chunk.NEWLINE);

        ConversationInfo coninfo = new ConversationUtils().getConversationInfo(conversation.getConversationID(),
                false);

        String participantsDetail;
        if (coninfo.getAllParticipants() == null) {
            participantsDetail = coninfo.getParticipant1() + ", " + coninfo.getParticipant2();
        } else {
            participantsDetail = String.valueOf(coninfo.getAllParticipants().length);
        }

        Paragraph chapterTitle = new Paragraph(
                LocaleUtils.getLocalizedString("archive.search.pdf.participants", MonitoringConstants.NAME)
                        + " " + participantsDetail,
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));

        document.add(chapterTitle);

        Paragraph startDate = new Paragraph(
                LocaleUtils.getLocalizedString("archive.search.pdf.startdate", MonitoringConstants.NAME) + " "
                        + coninfo.getDate(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(startDate);

        Paragraph duration = new Paragraph(
                LocaleUtils.getLocalizedString("archive.search.pdf.duration", MonitoringConstants.NAME) + " "
                        + coninfo.getDuration(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(duration);

        Paragraph messageCount = new Paragraph(
                LocaleUtils.getLocalizedString("archive.search.pdf.messagecount", MonitoringConstants.NAME)
                        + " " + conversation.getMessageCount(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(messageCount);
        document.add(Chunk.NEWLINE);

        Paragraph messageParagraph;

        for (ArchivedMessage message : conversation.getMessages()) {
            String time = JiveGlobals.formatTime(message.getSentDate());
            String from = message.getFromJID().getNode();
            if (conversation.getRoom() != null) {
                from = message.getToJID().getResource();
            }
            String body = message.getBody();
            String prefix;
            if (!message.isRoomEvent()) {
                prefix = "[" + time + "] " + from + ":  ";
                Font font = colorMap.get(message.getFromJID().toString());
                if (font == null) {
                    font = colorMap.get(message.getFromJID().toBareJID());
                }
                if (font == null) {
                    font = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);
                }
                messageParagraph = new Paragraph(new Chunk(prefix, font));
            } else {
                prefix = "[" + time + "] ";
                messageParagraph = new Paragraph(new Chunk(prefix, roomEvent));
            }
            messageParagraph.add(body);
            messageParagraph.add(" ");
            document.add(messageParagraph);
        }

        document.close();
        return baos;
    } catch (DocumentException e) {
        Log.error("error creating PDF document: " + e.getMessage(), e);
        return null;
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerInvoiceWriteoffBatchServiceImpl.java

License:Open Source License

protected void writeFileNameSectionTitle(com.lowagie.text.Document pdfDoc, String filenameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD);

    //  file name title, get title only, on windows & unix platforms
    String fileNameOnly = filenameLine.toUpperCase();
    int indexOfSlashes = fileNameOnly.lastIndexOf("\\");
    if (indexOfSlashes < fileNameOnly.length()) {
        fileNameOnly = fileNameOnly.substring(indexOfSlashes + 1);
    }//ww w  .j  a  v a  2  s .c o m
    indexOfSlashes = fileNameOnly.lastIndexOf("/");
    if (indexOfSlashes < fileNameOnly.length()) {
        fileNameOnly = fileNameOnly.substring(indexOfSlashes + 1);
    }

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    Chunk chunk = new Chunk(fileNameOnly, font);
    chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5);
    paragraph.add(chunk);

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerInvoiceWriteoffBatchServiceImpl.java

License:Open Source License

protected void writeInvoiceSectionTitle(com.lowagie.text.Document pdfDoc, String customerNameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    paragraph.add(new Chunk(customerNameLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {/*from  w w w .j a v  a  2 s .  co m*/
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerInvoiceWriteoffBatchServiceImpl.java

License:Open Source License

protected void writeInvoiceSectionMessage(com.lowagie.text.Document pdfDoc, String resultLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    paragraph.add(new Chunk(resultLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {/*from ww  w . j  av  a2  s  .  c o  m*/
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java

License:Open Source License

protected void writeFileNameSectionTitle(Document pdfDoc, String filenameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    Chunk chunk = new Chunk(filenameLine, font);
    chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5);
    paragraph.add(chunk);/*w  w w. j  a v a 2 s  .  c o  m*/

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}