Search in sources :

Example 26 with Paragraph

use of com.lowagie.text.Paragraph in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printGraphPdf.

private void printGraphPdf(GraphCommon graph, Chapter chapter) throws Exception {
    Section section;
    String tmp;
    if (graph instanceof SubGraph) {
        SubGraph subgraph = (SubGraph) graph;
        String id = subgraph.getDisplayId(nodeIdType);
        if (id == null || id.length() == 0)
            id = subgraph.getId().toString();
        tmp = "Subprocess " + id + ": \"" + subgraph.getName().replace('\n', ' ') + "\"";
    } else {
        tmp = "Process Description";
    }
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    sTitle.setSpacingBefore(10);
    section = chapter.addSection(sTitle, options.contains(SECTION_NUMBER) ? 2 : 0);
    String summary = (graph instanceof SubGraph) ? ((SubGraph) graph).getProcessVO().getProcessDescription() : ((Graph) graph).getProcessVO().getProcessDescription();
    if (summary != null && summary.length() > 0)
        printBoldParagraphsPdf(section, summary);
    if (options.contains(DOCUMENTATION)) {
        String detail = graph.getProcessVO().getAttribute(WorkAttributeConstant.DOCUMENTATION);
        if (detail != null && detail.length() > 0) {
            printHtmlParagraphsPdf(section, detail, options.contains(SECTION_NUMBER) ? 2 : 0);
        }
    }
    if (options.contains(ATTRIBUTES) && !graph.getProcessVO().getAttributes().isEmpty() && graph instanceof SubGraph) {
        printAttributesPdf(section, graph.getProcessVO().getAttributes(), options.contains(SECTION_NUMBER) ? 2 : 0);
    }
}
Also used : Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Section(com.lowagie.text.Section) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Paragraph(com.lowagie.text.Paragraph)

Example 27 with Paragraph

use of com.lowagie.text.Paragraph in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printAttributesPdf.

private void printAttributesPdf(Section section, List<AttributeVO> attrs, int parentLevel) {
    Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont);
    Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
    for (AttributeVO attr : attrs) {
        if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue()))
            continue;
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont));
        String v = attr.getAttributeValue();
        if (v == null)
            v = "";
        phrase.add(new Chunk(": " + v, normalFont));
        list.add(new ListItem(phrase));
    }
    subsection.add(list);
}
Also used : AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) List(java.util.List) ArrayList(java.util.ArrayList) Phrase(com.lowagie.text.Phrase) ListItem(com.lowagie.text.ListItem) Chunk(com.lowagie.text.Chunk) Section(com.lowagie.text.Section) Paragraph(com.lowagie.text.Paragraph)

Example 28 with Paragraph

use of com.lowagie.text.Paragraph in project ofbiz-framework by apache.

the class PdfSurveyServices method buildPdfFromSurveyResponse.

/**
 */
public static Map<String, Object> buildPdfFromSurveyResponse(DispatchContext dctx, Map<String, ? extends Object> rcontext) {
    Map<String, Object> context = UtilMisc.makeMapWritable(rcontext);
    Delegator delegator = dctx.getDelegator();
    Map<String, Object> results = ServiceUtil.returnSuccess();
    String surveyResponseId = (String) context.get("surveyResponseId");
    String contentId = (String) context.get("contentId");
    String surveyId = null;
    Document document = new Document();
    try {
        if (UtilValidate.isNotEmpty(surveyResponseId)) {
            GenericValue surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("surveyResponseId", surveyResponseId).queryOne();
            if (surveyResponse != null) {
                surveyId = surveyResponse.getString("surveyId");
            }
        }
        if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) {
            GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne();
            if (survey != null) {
                String acroFormContentId = survey.getString("acroFormContentId");
                if (UtilValidate.isNotEmpty(acroFormContentId)) {
                    context.put("contentId", acroFormContentId);
                }
            }
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        List<GenericValue> responses = EntityQuery.use(delegator).from("SurveyResponseAnswer").where("surveyResponseId", surveyResponseId).queryList();
        for (GenericValue surveyResponseAnswer : responses) {
            String value = null;
            String surveyQuestionId = (String) surveyResponseAnswer.get("surveyQuestionId");
            GenericValue surveyQuestion = EntityQuery.use(delegator).from("SurveyQuestion").where("surveyQuestionId", surveyQuestionId).queryOne();
            String questionType = surveyQuestion.getString("surveyQuestionTypeId");
            // DEJ20060227 this isn't used, if needed in the future should get from SurveyQuestionAppl.externalFieldRef String fieldName = surveyQuestion.getString("description");
            if ("OPTION".equals(questionType)) {
                value = surveyResponseAnswer.getString("surveyOptionSeqId");
            } else if ("BOOLEAN".equals(questionType)) {
                value = surveyResponseAnswer.getString("booleanResponse");
            } else if ("NUMBER_LONG".equals(questionType) || "NUMBER_CURRENCY".equals(questionType) || "NUMBER_FLOAT".equals(questionType)) {
                Double num = surveyResponseAnswer.getDouble("numericResponse");
                if (num != null) {
                    value = num.toString();
                }
            } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
            // not really a question; ingore completely
            } else {
                value = surveyResponseAnswer.getString("textResponse");
            }
            Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);
            Paragraph p = new Paragraph(chunk);
            document.add(p);
        }
        ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());
        results.put("outByteBuffer", outByteBuffer);
    } catch (GenericEntityException | DocumentException e) {
        Debug.logError(e, module);
        results = ServiceUtil.returnError(e.getMessage());
    }
    return results;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document) Chunk(com.lowagie.text.Chunk) ByteBuffer(java.nio.ByteBuffer) Paragraph(com.lowagie.text.Paragraph) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) DocumentException(com.lowagie.text.DocumentException) PdfObject(com.lowagie.text.pdf.PdfObject)

Example 29 with Paragraph

use of com.lowagie.text.Paragraph in project boxmaker by rahulbot.

the class Renderer method openDoc.

/**
 * Create the document to write to (needed before any rendering can happen).
 * @param widthMm	the width of the document in millimeters
 * @param heightMm	the height of the document in millimeters
 * @param fileName  the name of the file to save
 * @throws FileNotFoundException
 * @throws DocumentException
 */
private void openDoc(float widthMm, float heightMm, String fileName) throws FileNotFoundException, DocumentException {
    float docWidth = widthMm * DPI * INCH_PER_MM;
    float docHeight = heightMm * DPI * INCH_PER_MM;
    // System.out.println("doc = "+docWidth+" x "+docHeight);
    doc = new Document(new Rectangle(docWidth, docHeight));
    docPdfWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath));
    String appNameVersion = BoxMakerConstants.APP_NAME + " " + BoxMakerConstants.VERSION;
    doc.addAuthor(appNameVersion);
    doc.open();
    doc.add(new Paragraph("Produced by " + BoxMakerConstants.APP_NAME + " " + BoxMakerConstants.VERSION + "\n" + "  on " + new Date() + "\n" + BoxMakerConstants.WEBSITE_URL));
}
Also used : FileOutputStream(java.io.FileOutputStream) Rectangle(com.lowagie.text.Rectangle) Document(com.lowagie.text.Document) Date(java.util.Date) Paragraph(com.lowagie.text.Paragraph)

Example 30 with Paragraph

use of com.lowagie.text.Paragraph in project dhis2-core by dhis2.

the class DefaultPdfDataEntryFormService method setDataSet_DocumentTopSection.

private void setDataSet_DocumentTopSection(Document document, DataSet dataSet) throws DocumentException {
    document.add(new Paragraph(dataSet.getDisplayName(), pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_TITLE)));
    document.add(new Paragraph(dataSet.getDisplayDescription(), pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_DESCRIPTION)));
}
Also used : Paragraph(com.lowagie.text.Paragraph)

Aggregations

Paragraph (com.lowagie.text.Paragraph)43 Font (com.lowagie.text.Font)14 DocumentException (com.lowagie.text.DocumentException)13 Color (java.awt.Color)13 Document (com.lowagie.text.Document)12 Chunk (com.lowagie.text.Chunk)11 Cell (com.lowagie.text.Cell)9 Phrase (com.lowagie.text.Phrase)7 Section (com.lowagie.text.Section)7 PdfPCell (com.lowagie.text.pdf.PdfPCell)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 ArrayList (java.util.ArrayList)6 Table (com.lowagie.text.Table)5 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)5 ListItem (com.lowagie.text.ListItem)4 PdfPTable (com.lowagie.text.pdf.PdfPTable)4 IOException (java.io.IOException)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 ExpressionException (cbit.vcell.parser.ExpressionException)3