Search in sources :

Example 6 with Rectangle

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

the class DefaultPdfDataEntryFormService method insertTable_DataSetSections.

private void insertTable_DataSetSections(PdfPTable mainTable, PdfWriter writer, Rectangle rectangle, Collection<DataElement> dataElements, String sectionName) throws IOException, DocumentException {
    boolean hasBorder = true;
    // Add Section Name and Section Spacing
    insertTable_TextRow(writer, mainTable, TEXT_BLANK);
    if (sectionName != null && !sectionName.isEmpty()) {
        insertTable_TextRow(writer, mainTable, sectionName, pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_SECTIONHEADER));
    }
    // Create A Table To Add For Each Section
    PdfPTable table = new PdfPTable(2);
    table.setWidths(new int[] { 2, 1 });
    table.setWidthPercentage(100.0f);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    // row.
    for (DataElement dataElement : dataElements) {
        for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
            String categoryOptionComboDisplayName = "";
            // Hide Default category option combo name
            if (!categoryOptionCombo.isDefault()) {
                categoryOptionComboDisplayName = categoryOptionCombo.getDisplayName();
            }
            addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), dataElement.getFormNameFallback() + " " + categoryOptionComboDisplayName, Element.ALIGN_RIGHT);
            String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + dataElement.getUid() + "_" + categoryOptionCombo.getUid();
            ValueType valueType = dataElement.getValueType();
            // Yes Only case - render as check-box
            if (ValueType.TRUE_ONLY == valueType) {
                addCell_WithCheckBox(table, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            } else if (ValueType.BOOLEAN == valueType) {
                // Create Yes - true, No - false, Select..
                String[] optionList = new String[] { "[No Value]", "Yes", "No" };
                String[] valueList = new String[] { "", "true", "false" };
                // addCell_WithRadioButton(table, writer, strFieldLabel);
                addCell_WithDropDownListField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, optionList, valueList);
            } else if (valueType.isNumeric()) {
                Rectangle rectNum = new Rectangle(TEXTBOXWIDTH_NUMBERTYPE, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
                addCell_WithTextField(table, rectNum, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, PdfFieldCell.TYPE_TEXT_NUMBER);
            } else {
                addCell_WithTextField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            }
        }
    }
    PdfPCell cell_withInnerTable = new PdfPCell(table);
    cell_withInnerTable.setBorder(Rectangle.NO_BORDER);
    mainTable.addCell(cell_withInnerTable);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) PdfPCell(com.lowagie.text.pdf.PdfPCell) PdfPTable(com.lowagie.text.pdf.PdfPTable) ValueType(org.hisp.dhis.common.ValueType) Rectangle(com.lowagie.text.Rectangle) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 7 with Rectangle

use of com.lowagie.text.Rectangle 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 8 with Rectangle

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

the class PdfFieldCell method cellLayout.

@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
    try {
        PdfContentByte canvasText = canvases[PdfPTable.TEXTCANVAS];
        if (type == TYPE_RADIOBUTTON) {
            if (parent != null) {
                float leftLoc = rect.getLeft();
                float rightLoc = rect.getLeft() + RADIOBUTTON_WIDTH;
                String text;
                String value;
                for (int i = 0; i < texts.length; i++) {
                    text = texts[i];
                    value = values[i];
                    Rectangle radioRec = new Rectangle(leftLoc, rect.getTop() - height, rightLoc, rect.getTop());
                    RadioCheckField rf = new RadioCheckField(writer, radioRec, "RDBtn_" + text, value);
                    if (value != null && value.equals(checkValue)) {
                        rf.setChecked(true);
                    }
                    rf.setBorderColor(GrayColor.GRAYBLACK);
                    rf.setBackgroundColor(GrayColor.GRAYWHITE);
                    rf.setCheckType(RadioCheckField.TYPE_CIRCLE);
                    parent.addKid(rf.getRadioField());
                    leftLoc = rightLoc;
                    rightLoc += width;
                    ColumnText.showTextAligned(canvasText, Element.ALIGN_LEFT, new Phrase(text), leftLoc + RADIOBUTTON_TEXTOFFSET, height, 0);
                    leftLoc = rightLoc;
                    rightLoc += RADIOBUTTON_WIDTH;
                }
                writer.addAnnotation(parent);
            }
        } else if (type == TYPE_BUTTON) {
            // Add the push button
            PushbuttonField button = new PushbuttonField(writer, rect, name);
            button.setBackgroundColor(new GrayColor(0.75f));
            button.setBorderColor(GrayColor.GRAYBLACK);
            button.setBorderWidth(1);
            button.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
            button.setTextColor(GrayColor.GRAYBLACK);
            button.setFontSize(PdfDataEntryFormUtil.UNITSIZE_DEFAULT);
            button.setText(text);
            button.setLayout(PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT);
            button.setScaleIcon(PushbuttonField.SCALE_ICON_ALWAYS);
            button.setProportionalIcon(true);
            button.setIconHorizontalAdjustment(0);
            formField = button.getField();
            formField.setAction(PdfAction.javaScript(jsAction, writer));
        } else if (type == TYPE_CHECKBOX) {
            float extraCheckBoxOffset_Left = 2.0f;
            float extraCheckBoxOffset_Top = 1.5f;
            formField.setWidget(new Rectangle(rect.getLeft() + OFFSET_LEFT + extraCheckBoxOffset_Left, rect.getTop() - height - OFFSET_TOP - extraCheckBoxOffset_Top, rect.getLeft() + width + OFFSET_LEFT + extraCheckBoxOffset_Left, rect.getTop() - OFFSET_TOP - extraCheckBoxOffset_Top), PdfAnnotation.HIGHLIGHT_NONE);
        } else {
            if (type == TYPE_TEXT_ORGUNIT) {
                formField.setAdditionalActions(PdfName.BL, PdfAction.javaScript("if(event.value == '') app.alert('Please enter org unit identifier');", writer));
            }
            // TYPE_TEXT_NUMBER and TYPE_CHECKBOX cases included as well here
            formField.setWidget(new Rectangle(rect.getLeft() + OFFSET_LEFT, rect.getTop() - height - OFFSET_TOP, rect.getLeft() + width + OFFSET_LEFT, rect.getTop() - OFFSET_TOP), PdfAnnotation.HIGHLIGHT_NONE);
        }
        writer.addAnnotation(formField);
    } catch (DocumentException ex) {
        throw new RuntimeException(ex.getMessage());
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}
Also used : RadioCheckField(com.lowagie.text.pdf.RadioCheckField) DocumentException(com.lowagie.text.DocumentException) Rectangle(com.lowagie.text.Rectangle) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Phrase(com.lowagie.text.Phrase) GrayColor(com.lowagie.text.pdf.GrayColor) IOException(java.io.IOException) PushbuttonField(com.lowagie.text.pdf.PushbuttonField)

Example 9 with Rectangle

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

the class DefaultPdfDataEntryFormService method addCell_WithCheckBox.

private void addCell_WithCheckBox(PdfPTable table, PdfWriter writer, PdfPCell cell, String strfldName) throws IOException, DocumentException {
    float sizeDefault = PdfDataEntryFormUtil.UNITSIZE_DEFAULT;
    RadioCheckField checkbox = new RadioCheckField(writer, new Rectangle(sizeDefault, sizeDefault), "Yes", "On");
    checkbox.setBorderWidth(1);
    checkbox.setBorderColor(Color.BLACK);
    PdfFormField checkboxfield = checkbox.getCheckField();
    checkboxfield.setFieldName(strfldName + "_" + PdfFieldCell.TPYEDEFINE_NAME + PdfFieldCell.TYPE_CHECKBOX);
    setCheckboxAppearance(checkboxfield, writer.getDirectContent(), sizeDefault);
    cell.setCellEvent(new PdfFieldCell(checkboxfield, sizeDefault, sizeDefault, PdfFieldCell.TYPE_CHECKBOX, writer));
    table.addCell(cell);
}
Also used : RadioCheckField(com.lowagie.text.pdf.RadioCheckField) PdfFormField(com.lowagie.text.pdf.PdfFormField) Rectangle(com.lowagie.text.Rectangle)

Aggregations

Rectangle (com.lowagie.text.Rectangle)9 PdfPTable (com.lowagie.text.pdf.PdfPTable)4 PdfPCell (com.lowagie.text.pdf.PdfPCell)3 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)2 RadioCheckField (com.lowagie.text.pdf.RadioCheckField)2 IOException (java.io.IOException)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 ExceptionConverter (com.lowagie.text.ExceptionConverter)1 Paragraph (com.lowagie.text.Paragraph)1 Phrase (com.lowagie.text.Phrase)1 DefaultFontMapper (com.lowagie.text.pdf.DefaultFontMapper)1 GrayColor (com.lowagie.text.pdf.GrayColor)1 PdfFormField (com.lowagie.text.pdf.PdfFormField)1 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 PushbuttonField (com.lowagie.text.pdf.PushbuttonField)1 Graphics2D (java.awt.Graphics2D)1 PageFormat (java.awt.print.PageFormat)1