Example usage for com.lowagie.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph(float leading, String string) 

Source Link

Document

Constructs a Paragraph with a certain String and a certain leading.

Usage

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

private void addOverviewReport(Document document) throws DocumentException {
    Paragraph res_title = new Paragraph("Overview Of Analysis Results", fontHeading1);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);
    document.add(res_title);//from   w w  w  .ja v  a 2 s  .c  om

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForOverallIssues(all_tree_items);
        }
    });
    document.add(table);
    document.add(Chunk.NEWLINE);

    res_title = new Paragraph("Details", fontHeading1);
    document.add(res_title);

    res_title = new Paragraph("Critical Severity Issues", fontHeading2);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForIssues(all_tree_items, AnalyserConstants.Priority.CRITICAL);
            ;
        }
    });
    if (table != null) {
        document.add(res_title);
        document.add(table);
        document.add(Chunk.NEWLINE);
    }

    res_title = new Paragraph("High Severity Issues", fontHeading2);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForIssues(all_tree_items, AnalyserConstants.Priority.HIGH);
        }
    });
    if (table != null) {
        document.add(res_title);
        document.add(table);
        document.add(Chunk.NEWLINE);
    }

    res_title = new Paragraph("Normal Severity Issues", fontHeading2);
    res_title.setSpacingAfter(SPACING_AFTER_HEADER_TEXT);

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            table = getTableForIssues(all_tree_items, AnalyserConstants.Priority.NORMAL);
        }
    });
    if (table != null) {
        document.add(res_title);
        document.add(table);
    }
}

From source file:com.preparatic.archivos.PdfGenerator.java

License:Apache License

/**
  * Ade una pregunta al test.//from w w  w .ja v a  2 s  . c  om
  * 
  * @param resultados
  * @throws Exception
  */
 private void agregarPregunta(PreguntaTest pregunta, boolean isLast) {
     // Creamos una lista para las respuestas.
     listaRespuestas = new com.lowagie.text.List(true, true);

     listaRespuestas.add(new ListItem(pregunta.getRespuesta_a(), miFuentePregs));
     listaRespuestas.add(new ListItem(pregunta.getRespuesta_b(), miFuentePregs));
     listaRespuestas.add(new ListItem(pregunta.getRespuesta_c(), miFuentePregs));
     listaRespuestas.add(new ListItem(pregunta.getRespuesta_d(), miFuentePregs));

     // Incorporamos la lista de respuestas en un nico Prrafo
     Paragraph parrafoPregunta = new Paragraph(pregunta.getPregunta(), miFuentePregs);
     parrafoPregunta.setKeepTogether(true);
     parrafoPregunta.add(listaRespuestas);
     if (!isLast)
         parrafoPregunta.setSpacingAfter(distanciaInterPregunta);

     // Metemos la pregunta como un Li en ListaPreguntas.
     ListItem li = new ListItem(parrafoPregunta);
     li.setKeepTogether(true);
     listaPreguntas.add(li);
     String cadenaSolucion = pregunta.getRespuesta_correcta().toUpperCase();
     if (pregunta.getTemas() != null)
         cadenaSolucion += " (T" + pregunta.getTemas() + ")";
     listaSoluciones.add(new ListItem(cadenaSolucion, miFuenteSols));
 }

From source file:com.preparatic.archivos.PdfGenerator.java

License:Apache License

private void agregarPregunta(ResultSet resultados) throws Exception {

     // Creamos una lista para las respuestas.
     listaRespuestas = new com.lowagie.text.List(true, true);

     listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_A"), miFuentePregs));
     listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_B"), miFuentePregs));
     listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_C"), miFuentePregs));
     listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_D"), miFuentePregs));

     // Incorporamos la lista de respuestas en un nico Prrafo
     Paragraph parrafoPregunta = new Paragraph(resultados.getString("PREGUNTA"), miFuentePregs);
     parrafoPregunta.setKeepTogether(true);
     parrafoPregunta.add(listaRespuestas);
     if (!resultados.isLast())
         parrafoPregunta.setSpacingAfter(distanciaInterPregunta);

     // Metemos la pregunta como un Li en ListaPreguntas.
     ListItem li = new ListItem(parrafoPregunta);
     li.setKeepTogether(true);//from   www . j  a v a  2s .  c o m
     listaPreguntas.add(li);
     String cadenaSolucion = resultados.getString("RESPUESTA_CORRECTA").toUpperCase();
     if (resultados.getString(7) != null)
         cadenaSolucion += " (T" + resultados.getString("TEMAS") + ")";
     listaSoluciones.add(new ListItem(cadenaSolucion, miFuenteSols));
 }

From source file:com.prime.location.billing.InvoicedBillingManager.java

/**
 * Print invoice//from   ww  w.j  av a  2s . c  o  m
 */
public void printInvoice() {
    try { //catch better your exceptions, this is just an example
        FacesContext context = FacesContext.getCurrentInstance();

        Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f);

        String fileName = "PDFFile";

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(pdf, baos);
        TableHeader event = new TableHeader();
        event.setHeader("Header Here");
        writer.setPageEvent(event);

        if (!pdf.isOpen()) {
            pdf.open();
        }

        PdfPCell cell;

        PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 });
        cell = new PdfPCell(new Paragraph("INVOICE",
                FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        header.addCell(cell);
        header.setTotalWidth(527);
        header.setLockedWidth(true);

        cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription()));
        cell.setColspan(2);
        cell.setBorder(Rectangle.NO_BORDER);
        header.addCell(cell);

        cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId()));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        header.addCell(cell);

        cell = new PdfPCell(
                new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate())));
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        header.addCell(cell);

        pdf.add(header);

        PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 });
        table.setSpacingBefore(15f);

        table.setTotalWidth(527);
        table.setLockedWidth(true);
        //table.setWidths(new int[]{3, 1, 1});

        table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY);

        table.addCell("Date");
        table.addCell("Name");
        table.addCell("Service");
        table.addCell("Rate");

        table.getDefaultCell().setBackgroundColor(null);

        cell = new PdfPCell(new Phrase("Total(US$): "));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setColspan(3);
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount())));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cell);

        // There are three special rows
        table.setHeaderRows(2);
        // One of them is a footer
        table.setFooterRows(1);
        Font f = FontFactory.getFont(FontFactory.HELVETICA, 10);
        //add remaining
        for (AgencyBilling billing : selectedInvoice.getBillings()) {
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.getDefaultCell().setIndent(2);
            table.getDefaultCell().setFixedHeight(20);

            table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f));
            table.addCell(new Phrase(billing.getPerson().getName(), f));
            table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f));
            cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            table.addCell(cell);

        }

        pdf.add(table);

        writer.getAcroForm().setNeedAppearances(true);

        //document.add(new Phrase(TEXT));
        //Keep modifying your pdf file (add pages and more)
        pdf.close();

        writePDFToResponse(context.getExternalContext(), baos, fileName);

        context.responseComplete();

    } catch (Exception e) {
        //e.printStackTrace();          
    }
}

From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java

License:Open Source License

/**
 * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
 *///from w  w  w .j a  v  a  2s  .  c  om
public ActionForward executeAction() throws PureException {
    int nYear = request.getRequiredInt("year", "");

    Rectangle rectPageSize = new Rectangle(PageSize.A4);
    rectPageSize.setBackgroundColor(Color.WHITE);
    rectPageSize.setBorderColor(Color.BLACK);
    rectPageSize = rectPageSize.rotate();
    Document doc = new Document(rectPageSize, 10, 10, 10, 10);
    doc.addTitle(nYear + "");
    doc.addAuthor("PureInfo");
    try {
        BaseFont bfontTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font fontTitle = new Font(bfontTitle, 18, Font.NORMAL);
        Paragraph paraTitle = new Paragraph(nYear + "",
                fontTitle);
        paraTitle.setAlignment(ElementTags.ALIGN_CENTER);

        BaseFont bfontContent = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font fontContent = new Font(bfontContent, 10, Font.NORMAL);

        FileFactory fileFactory = FileFactory.getInstance();
        String sPath = fileFactory.lookupPathConfigByFlag(FileFactory.FLAG_DOWNLOADTEMP, true).getLocalPath();

        FileUtil.insurePathExists(sPath);
        PdfWriter.getInstance(doc, new FileOutputStream(new File(sPath, "patent.pdf")));

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

        String[] arrTitles = new String[] { "", "", "", "", "", "",
                "", "", "" };
        PdfPTable pTable = new PdfPTable(arrTitles.length);
        pTable.setWidths(new int[] { 5, 10, 9, 9, 20, 15, 12, 10, 10 });

        for (int i = 0; i < arrTitles.length; i++) {
            PdfPCell pCell = new PdfPCell();
            Paragraph para = new Paragraph(arrTitles[i], fontContent);
            para.setAlignment(ElementTags.ALIGN_CENTER);

            pCell.addElement(para);
            pTable.addCell(pCell);
        }

        /**
         * 
         */
        IPatentMgr mgr = (IPatentMgr) ArkContentHelper.getContentMgrOf(Patent.class);
        List patents = mgr.findAllAuthorizedOf(nYear);
        int i = 0;
        for (Iterator iter = patents.iterator(); iter.hasNext(); i++) {
            Patent patent = (Patent) iter.next();
            this.addPatentCell(pTable, String.valueOf(i + 1), fontContent);
            this.addPatentCell(pTable, patent.getPatentSid(), fontContent);
            this.addPatentCell(pTable, ForceConstants.DATE_FORMAT.format(patent.getApplyDate()), fontContent);
            this.addPatentCell(pTable, patent.getWarrantDate() == null ? ""
                    : ForceConstants.DATE_FORMAT.format(patent.getWarrantDate()), fontContent);
            this.addPatentCell(pTable, patent.getName(), fontContent);
            this.addPatentCell(pTable, patent.getAllAuthosName(), fontContent);
            this.addPatentCell(pTable, patent.getRightPerson(), fontContent);
            this.addPatentCell(pTable, getCollegeName(patent), fontContent);
            this.addPatentCell(pTable, patent.getPatentTypeName(), fontContent);
        }

        doc.add(pTable);
        doc.close();

    } catch (DocumentException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace(System.err);
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace(System.err);
    }

    List list = new ArrayList();
    list.add(new Pair("/download/patent.pdf", ""));
    request.setAttribute("forward", list);
    return mapping.findForward("success");
}

From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java

License:Open Source License

private void addPatentCell(PdfPTable _pTable, String _sValue, Font _font) {
    PdfPCell pCell = new PdfPCell();
    Paragraph para = new Paragraph(_sValue, _font);
    para.setAlignment(Align.CENTER);//from   w ww . ja v  a 2  s . co  m
    pCell.addElement(para);
    _pTable.addCell(pCell);
    //        return _pTable;
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

@Override
protected void buildPdfContent(final Document document, final Entity entity, final Locale locale)
        throws DocumentException {
    String documentTitle = translationService.translate("costCalculation.costCalculationDetails.report.title",
            locale);/*from w  w  w .  j  a  v a 2 s.  co  m*/
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);

    pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, new Date());

    DataDefinition dataDefCostCalculation = dataDefinitionService
            .get(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION);
    Entity costCalculation = dataDefCostCalculation.find("where id = " + entity.getId().toString())
            .uniqueResult();

    PdfPTable leftPanelColumn = addLeftPanelToReport(costCalculation, locale);

    PdfPTable rightPanelColumn = addRightPanelToReport(costCalculation, locale);

    PdfPTable panelTable = pdfHelper.createPanelTable(2);

    panelTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    panelTable.addCell(leftPanelColumn);
    panelTable.addCell(rightPanelColumn);
    panelTable.setSpacingAfter(20);
    panelTable.setSpacingBefore(20);

    panelTable.setTableEvent(null);
    panelTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    document.add(panelTable);

    document.add(new Paragraph(
            translationService.translate("costCalculation.costCalculationDetails.report.paragraph", locale),
            FontUtils.getDejavuBold11Dark()));
    PdfPTable materialsTable = addMaterialsTable(costCalculation, locale);
    document.add(materialsTable);

    document.add(Chunk.NEWLINE);
    document.add(new Paragraph(
            translationService.translate("costCalculation.costCalculationDetails.report.paragraph2", locale),
            FontUtils.getDejavuBold11Dark()));

    CalculateOperationCostMode calculateOperationCostMode = CalculateOperationCostMode
            .parseString(costCalculation.getStringField(CostCalculationFields.CALCULATE_OPERATION_COSTS_MODE));

    if (CalculateOperationCostMode.HOURLY.equals(calculateOperationCostMode)) {
        document.add(addHourlyCostsTable(costCalculation, locale));
    } else if (CalculateOperationCostMode.PIECEWORK.equals(calculateOperationCostMode)) {
        document.add(addTableAboutPieceworkCost(costCalculation, locale));
    } else {
        throw new IllegalStateException("Unsupported CalculateOperationCostMode");
    }

    printMaterialAndOperationNorms(document, costCalculation, locale);
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

public void printMaterialAndOperationNorms(final Document document, final Entity costCalculation,
        final Locale locale) throws DocumentException {
    if (costCalculation.getBooleanField(CostCalculationFields.PRINT_COST_NORMS_OF_MATERIALS)) {
        document.add(Chunk.NEWLINE);/*from  w w w  .  j a  v a2 s  . com*/
        document.add(new Paragraph(translationService
                .translate("costCalculation.costCalculationDetails.report.paragraph3", locale),
                FontUtils.getDejavuBold11Dark()));
        PdfPTable optionTable = addOptionTablePrintCostNormsOfMaterials(costCalculation, locale);
        document.add(optionTable);
    }

    if (costCalculation.getBooleanField(CostCalculationFields.PRINT_OPERATION_NORMS)) {
        CalculateOperationCostMode calculateOperationCostMode = CalculateOperationCostMode.parseString(
                costCalculation.getStringField(CostCalculationFields.CALCULATE_OPERATION_COSTS_MODE));

        if (CalculateOperationCostMode.PIECEWORK.equals(calculateOperationCostMode)) {
            document.add(Chunk.NEWLINE);
            document.add(
                    new Paragraph(
                            translationService.translate(
                                    "costCalculation.costCalculationDetails.report.paragraph4", locale),
                            FontUtils.getDejavuBold11Dark()));
            document.add(addOptionTablePrintOperationNormsPiecework(costCalculation, locale));
        } else if (CalculateOperationCostMode.HOURLY.equals(calculateOperationCostMode)) {
            document.add(Chunk.NEWLINE);
            document.add(
                    new Paragraph(
                            translationService.translate(
                                    "costCalculation.costCalculationDetails.report.paragraph5", locale),
                            FontUtils.getDejavuBold11Dark()));
            addOptionTablePrintOperationNormsHourly(document, costCalculation, locale);
        }
    }
}

From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private List<String> prepareProductsTableHeader(final Document document,
        final List<Entity> columnsForDeliveries, final Locale locale) throws DocumentException {
    document.add(new Paragraph(
            translationService.translate("deliveries.delivery.report.deliveryProducts.title", locale),
            FontUtils.getDejavuBold11Dark()));

    List<String> productsHeader = Lists.newArrayList();

    for (Entity columnForDeliveries : columnsForDeliveries) {
        String name = columnForDeliveries.getStringField(ColumnForDeliveriesFields.NAME);

        productsHeader.add(translationService.translate(name, locale));
    }//from ww  w.ja  v  a  2  s .  c  o  m

    return productsHeader;
}

From source file:com.qcadoo.mes.deliveries.print.OrderReportPdf.java

License:Open Source License

private List<String> prepareProductsTableHeader(final Document document, final List<Entity> columnsForOrders,
        final Locale locale) throws DocumentException {
    document.add(/*from ww w  .  j av a  2  s  . c om*/
            new Paragraph(translationService.translate("deliveries.order.report.orderedProducts.title", locale),
                    FontUtils.getDejavuBold10Dark()));

    List<String> productsHeader = Lists.newArrayList();

    for (Entity columnForOrders : columnsForOrders) {
        String name = columnForOrders.getStringField(ColumnForOrdersFields.NAME);

        productsHeader.add(translationService.translate(name, locale));
    }

    return productsHeader;
}