Example usage for com.lowagie.text Element ALIGN_TOP

List of usage examples for com.lowagie.text Element ALIGN_TOP

Introduction

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

Prototype

int ALIGN_TOP

To view the source code for com.lowagie.text Element ALIGN_TOP.

Click Source Link

Document

A possible value for vertical alignment.

Usage

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   ww w  . jav  a  2s. com
    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 PdfPTable addLeftPanelToReport(final Entity costCalculation, final Locale locale) {
    PdfPTable leftPanelColumn = pdfHelper.createPanelTable(1);
    leftPanelColumn.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    Entity order = costCalculation.getBelongsToField(CostCalculationFields.ORDER);
    String calculateOperationCostsMode = costCalculation
            .getStringField(CostCalculationFields.CALCULATE_OPERATION_COSTS_MODE);
    String calculateMaterialCostsMode = costCalculation
            .getStringField(CostCalculationFields.CALCULATE_MATERIAL_COSTS_MODE);

    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            translationService.translate("costCalculation.costCalculation.number.label", locale) + ":",
            costCalculation.getStringField(CostCalculationFields.NUMBER));
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            translationService.translate("costCalculation.costCalculation.product.label", locale) + ":",
            costCalculation.getBelongsToField(CostCalculationFields.PRODUCT)
                    .getStringField(ProductFields.NAME));
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            translationService.translate("costCalculation.costCalculation.technology.label", locale) + ":",
            costCalculation.getBelongsToField(CostCalculationFields.TECHNOLOGY)
                    .getStringField(TechnologyFields.NAME));
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            translationService.translate("costCalculation.costCalculation.quantity.label", locale) + ":",
            numberService.format(costCalculation.getField(CostCalculationFields.QUANTITY)));
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            translationService.translate("costCalculation.costCalculation.order.label", locale) + ":",
            order == null ? "" : order.getStringField(OrderFields.NAME));

    leftPanelColumn.addCell(new Phrase(
            translationService.translate(
                    "costCalculation.costCalculationDetails.window.mainTab.form.parameters", locale) + ":",
            FontUtils.getDejavuBold10Dark()));

    if (!CalculateOperationCostMode.PIECEWORK.getStringValue().equals(calculateOperationCostsMode)) {
        pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
                L_TAB_IN_TEXT + translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.includeAdditionalTime",
                        locale) + ":",
                costCalculation.getBooleanField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME)
                        ? translationService.translate("qcadooView.true", locale)
                        : translationService.translate("qcadooView.false", locale));

        pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
                L_TAB_IN_TEXT + translationService.translate("costCalculation.costCalculation.includeTPZ.label",
                        locale) + ":",
                costCalculation.getBooleanField(CostCalculationFields.INCLUDE_TPZ)
                        ? translationService.translate("qcadooView.true", locale)
                        : translationService.translate("qcadooView.false", locale));
    }/*from ww w  .jav  a2  s.  c o  m*/

    Object reportData = calculateMaterialCostsMode;
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.calculateMaterialCostsMode.label", locale),
            reportData == null ? translationService.translate("qcadooView.form.blankComboBoxValue", locale)
                    : translationService
                            .translate("costCalculation.costCalculation.calculateMaterialCostsMode.value."
                                    + reportData.toString(), locale));

    reportData = calculateOperationCostsMode;
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.calculateOperationCostsMode.label", locale),
            reportData == null ? translationService.translate("qcadooView.form.blankComboBoxValue", locale)
                    : translationService
                            .translate("costCalculation.costCalculation.calculateOperationCostsMode.value."
                                    + reportData.toString(), locale));

    reportData = costCalculation.getStringField(CostCalculationFields.DESCRIPTION);
    pdfHelper.addTableCellAsTwoColumnsTable(leftPanelColumn, L_TAB_IN_TEXT
            + translationService.translate("costCalculation.costCalculation.description.label", locale) + ":",
            (reportData == null ? "" : reportData));

    return leftPanelColumn;
}

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

License:Open Source License

public PdfPTable addRightPanelToReport(final Entity costCalculation, final Locale locale) {
    PdfPTable rightPanelColumn = pdfHelper.createPanelTable(1);
    rightPanelColumn.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    rightPanelColumn.addCell(new Phrase(translationService.translate(
            "costCalculation.costCalculationDetails.window.mainTab.form.technicalProductionCost", locale) + ":",
            FontUtils.getDejavuBold10Dark()));

    Object reportData = costCalculation.getDecimalField(CostCalculationFields.TOTAL_MATERIAL_COSTS);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.totalMaterialCosts.label", locale) + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode());

    reportData = costCalculation.getDecimalField(CostCalculationFields.TOTAL_MACHINE_HOURLY_COSTS);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.totalMachineHourlyCosts.label", locale) + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode());

    reportData = costCalculation.getDecimalField(CostCalculationFields.TOTAL_LABOR_HOURLY_COSTS);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.totalLaborHourlyCosts.label", locale) + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode());

    reportData = costCalculation.getDecimalField(CostCalculationFields.TOTAL_TECHNICAL_PRODUCTION_COSTS);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT/*from  ww w  . j av  a2 s  . c  o m*/
                    + translationService.translate(
                            "costCalculation.costCalculation.totalTechnicalProductionCosts.label", locale)
                    + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode());

    rightPanelColumn.addCell(new Phrase(translationService
            .translate("costCalculation.costCalculationDetails.window.mainTab.form.overheads", locale) + ":",
            FontUtils.getDejavuBold10Dark()));

    reportData = costCalculation.getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN);
    Object reportData2 = costCalculation.getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN_VALUE);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.productionCostMargin.label", locale) + ":",
            (reportData == null ? ""
                    : numberService.format(reportData) + (reportData2 == null ? ""
                            : " %\n (" + "= " + reportData2.toString() + " "
                                    + currencyService.getCurrencyAlphabeticCode() + ")")));

    reportData = costCalculation.getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN);
    reportData2 = costCalculation.getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN_VALUE);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.materialCostMargin.label", locale) + ":",
            (reportData == null ? ""
                    : numberService.format(reportData) + (reportData2 == null ? ""
                            : " %\n (" + "= " + reportData2.toString() + " "
                                    + currencyService.getCurrencyAlphabeticCode() + ")")));

    reportData = costCalculation.getDecimalField(CostCalculationFields.ADDITIONAL_OVERHEAD);
    pdfHelper.addTableCellAsTwoColumnsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.additionalOverhead.label", locale) + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode());

    reportData = costCalculation.getDecimalField(CostCalculationFields.TOTAL_COSTS);
    rightPanelColumn.addCell(new Phrase(translationService
            .translate("costCalculation.costCalculationDetails.window.mainTab.form.totalCost", locale) + ":",
            FontUtils.getDejavuBold10Dark()));

    pdfHelper.addTableCellAsTable(rightPanelColumn, L_TAB_IN_TEXT
            + translationService.translate("costCalculation.costCalculation.totalCosts.label", locale) + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode(),
            FontUtils.getDejavuBold10Dark(), FontUtils.getDejavuRegular10Dark(), 2);

    reportData = costCalculation.getDecimalField(CostCalculationFields.TOTAL_COST_PER_UNIT);
    pdfHelper.addTableCellAsTable(rightPanelColumn,
            L_TAB_IN_TEXT + translationService
                    .translate("costCalculation.costCalculation.totalCostPerUnit.label", locale) + ":",
            (reportData == null ? "" : numberService.format(reportData)) + " "
                    + currencyService.getCurrencyAlphabeticCode(),
            FontUtils.getDejavuBold10Dark(), FontUtils.getDejavuRegular10Dark(), 2);

    return rightPanelColumn;
}

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

License:Open Source License

private void createHeaderTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    PdfPTable dynaminHeaderTable = pdfHelper.createPanelTable(3);

    dynaminHeaderTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    PdfPTable firstColumnHeaderTable = new PdfPTable(1);
    PdfPTable secondColumnHeaderTable = new PdfPTable(1);
    PdfPTable thirdColumnHeaderTable = new PdfPTable(1);

    setSimpleFormat(firstColumnHeaderTable);
    setSimpleFormat(secondColumnHeaderTable);
    setSimpleFormat(thirdColumnHeaderTable);

    dynaminHeaderTable.setSpacingBefore(7);

    Map<String, Object> firstColumn = createFirstColumn(delivery);
    Map<String, Object> secondColumn = createSecondColumn(delivery);
    Map<String, Object> thirdColumn = createThirdColumn(delivery, locale);

    int maxSize = pdfHelper.getMaxSizeOfColumnsRows(Lists.newArrayList(
            Integer.valueOf(firstColumn.values().size()), Integer.valueOf(secondColumn.values().size()),
            Integer.valueOf(thirdColumn.values().size())));

    for (int i = 0; i < maxSize; i++) {
        firstColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(firstColumnHeaderTable, firstColumn,
                locale);// w  w w.j  av  a  2  s . co m
        secondColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(secondColumnHeaderTable, secondColumn,
                locale);
        thirdColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(thirdColumnHeaderTable, thirdColumn,
                locale);
    }

    dynaminHeaderTable.addCell(firstColumnHeaderTable);
    dynaminHeaderTable.addCell(secondColumnHeaderTable);
    dynaminHeaderTable.addCell(thirdColumnHeaderTable);

    document.add(dynaminHeaderTable);
}

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

License:Open Source License

private void createHeaderTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    PdfPTable dynaminHeaderTable = pdfHelper.createPanelTable(3);
    dynaminHeaderTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    PdfPTable firstColumnHeaderTable = new PdfPTable(1);
    PdfPTable secondColumnHeaderTable = new PdfPTable(1);
    PdfPTable thirdColumnHeaderTable = new PdfPTable(1);

    setSimpleFormat(firstColumnHeaderTable);
    setSimpleFormat(secondColumnHeaderTable);
    setSimpleFormat(thirdColumnHeaderTable);

    dynaminHeaderTable.setSpacingBefore(7);

    Map<String, Object> firstColumn = createFirstColumn(delivery);
    Map<String, Object> secondColumn = createSecondColumn(delivery);
    Map<String, Object> thirdColumn = createThirdColumn(delivery);

    int maxSize = pdfHelper.getMaxSizeOfColumnsRows(Lists.newArrayList(
            Integer.valueOf(firstColumn.values().size()), Integer.valueOf(secondColumn.values().size()),
            Integer.valueOf(thirdColumn.values().size())));

    for (int i = 0; i < maxSize; i++) {
        firstColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(firstColumnHeaderTable, firstColumn,
                locale);/* w  w w .j  a v  a  2s . c  om*/
        secondColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(secondColumnHeaderTable, secondColumn,
                locale);
        thirdColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(thirdColumnHeaderTable, thirdColumn,
                locale);
    }

    dynaminHeaderTable.addCell(firstColumnHeaderTable);
    dynaminHeaderTable.addCell(secondColumnHeaderTable);
    dynaminHeaderTable.addCell(thirdColumnHeaderTable);

    document.add(dynaminHeaderTable);
    document.add(Chunk.NEWLINE);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.operation.component.OperationBarcode.java

License:Open Source License

public void print(PdfWriter pdfWriter, Entity operationComponent, Document document) throws DocumentException {
    PdfContentByte cb = pdfWriter.getDirectContent();
    Barcode128 code128 = new Barcode128();
    code128.setCode(//w w  w. ja  v a2 s  .c om
            barcodeOperationComponentService.getCodeFromBarcodeForOperationComponet(operationComponent));
    PdfPTable barcodeTable = new PdfPTable(1);
    barcodeTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    barcodeTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    barcodeTable.getDefaultCell().setBorder(0);
    barcodeTable.setWidthPercentage(10f);
    barcodeTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    Image barcodeImage = code128.createImageWithBarcode(cb, null, null);
    barcodeTable.addCell(barcodeImage);
    document.add(barcodeTable);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOperationTable(PdfWriter pdfWriter, GroupingContainer groupingContainer, Document document,
        OrderOperationComponent orderOperationComponent, Locale locale) throws DocumentException {

    Map<Long, Map<OperationProductColumn, ColumnAlignment>> outputProductsMap = groupingContainer
            .getOperationComponentIdProductOutColumnToAlignment();

    Map<Long, Map<OperationProductColumn, ColumnAlignment>> inputProductsMap = groupingContainer
            .getOperationComponentIdProductInColumnToAlignment();

    Entity operationComponent = orderOperationComponent.getOperationComponent();
    Entity order = orderOperationComponent.getOrder();
    Entity product = order.getBelongsToField(OrderFields.PRODUCT);

    Map<OperationProductColumn, ColumnAlignment> inputProductColumnAlignmentMap = inputProductsMap
            .get(operationComponent.getId());
    Map<OperationProductColumn, ColumnAlignment> outputProductColumnAlignmentMap = outputProductsMap
            .get(operationComponent.getId());

    PdfPTable table = pdfHelper.createPanelTable(3);

    PdfPCell headerCell = new PdfPCell();
    headerCell.setBorder(Rectangle.NO_BORDER);
    headerCell.setColspan(2);//from w  w  w .  j a  va 2s . com

    PdfPCell inputCell = new PdfPCell();
    inputCell.setBorder(Rectangle.NO_BORDER);
    PdfPCell outputCell = new PdfPCell();
    outputCell.setBorder(Rectangle.NO_BORDER);
    PdfPCell codeCell = new PdfPCell();
    codeCell.setBorder(Rectangle.NO_BORDER);
    codeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    codeCell.setVerticalAlignment(Element.ALIGN_TOP);
    codeCell.setRowspan(2);

    // addOperationSummary(headerCell, operationComponent);

    addOrderSummary(headerCell, order, product, operationComponent);

    addOperationProductsTable(inputCell, operationProductInComponents(operationComponent, order),
            inputProductColumnAlignmentMap, ProductDirection.IN, locale);
    addOperationProductsTable(outputCell, operationProductOutComponents(operationComponent, order),
            outputProductColumnAlignmentMap, ProductDirection.OUT, locale);

    codeCell.addElement(createBarcode(pdfWriter, operationComponent));

    float[] tableColumnWidths = new float[] { 70f, 70f, 10f };
    table.setWidths(tableColumnWidths);
    table.setTableEvent(null);
    table.addCell(headerCell);
    table.addCell(codeCell);
    table.addCell(inputCell);
    table.addCell(outputCell);
    table.setKeepTogether(true);
    document.add(table);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public PdfPTable createPanelTable(final int column) {
    PdfPTable mainData = new PdfPTable(column);
    mainData.setWidthPercentage(100f);//from   w  w  w .  j a va 2 s.c  o m
    mainData.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    mainData.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    mainData.getDefaultCell().setPadding(4.0f);
    mainData.setTableEvent(new TableBorderEvent());
    return mainData;
}

From source file:com.tsp.gespro.bo.DegustacionBO.java

/**
 * Representacin impresa PDF//from www  .j  av  a  2  s  .c  om
 */
public ByteArrayOutputStream toPdf(UsuarioBO user) throws Exception {

    SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    PdfITextUtil obj = new PdfITextUtil();

    //Tamao de documento (Tamao Carta)
    com.lowagie.text.Document doc = new com.lowagie.text.Document(PageSize.LETTER);

    //Definicin de Fuentes a usar
    Font letraOcho = new Font(Font.HELVETICA, 8, Font.NORMAL);
    Font letraOchoBold = new Font(Font.HELVETICA, 8, Font.BOLD);
    Font letraNueve = new Font(Font.HELVETICA, 9, Font.NORMAL);
    Font letraNueveBold = new Font(Font.HELVETICA, 9, Font.BOLD);
    Font letraNueveBoldRojo = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.red);
    Font letraNueveBoldAzul = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.blue);
    Font letraOchoVerde = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL, Color.green);
    Font letra14Bold = new Font(Font.HELVETICA, 14, Font.BOLD);

    String msgError = "";

    File fileImageLogo = null;
    try {
        if (user != null)
            fileImageLogo = new ImagenPersonalBO(this.conn)
                    .getFileImagenPersonalByEmpresa(user.getUser().getIdEmpresa());
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        //Preparamos writer de PDF
        PdfWriter writer = PdfWriter.getInstance(doc, baos);
        EventPDF eventPDF = new EventPDF(doc, user, ReportBO.DEGUSTACION_REPRESENTACION_IMPRESA, fileImageLogo);
        writer.setPageEvent(eventPDF);

        //Ajustamos margenes de pgina
        //doc.setMargins(50, 50, 120, 50);
        //doc.setMargins(20, 20, 80, 20);
        doc.setMargins(10, 10, 150, 40);

        //Iniciamos documento
        doc.open();

        //Creamos tabla principal
        PdfPTable mainTable = new PdfPTable(1);
        mainTable.setTotalWidth(550);
        mainTable.setLockedWidth(true);

        //CONTENIDO -------------

        //SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        //Cabecera (Datos Generales)---------------------
        PdfPTable tAux = new PdfPTable(1);

        Cliente clienteDto = null;
        DatosUsuario datosUsuarioVendedor = null;

        try {
            if (this.degustacion.getIdCliente() > 0)
                clienteDto = new ClienteBO(this.degustacion.getIdCliente(), this.conn).getCliente();
            if (this.degustacion.getIdUsuario() > 0)
                datosUsuarioVendedor = new UsuarioBO(this.degustacion.getIdUsuario()).getDatosUsuario();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        //Datos informativos generales
        PdfPTable tInfoGeneral = new PdfPTable(1);
        tInfoGeneral.setTotalWidth(160);
        tInfoGeneral.setLockedWidth(true);

        obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "ID Degustacin",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueveBoldRojo, "" + this.degustacion.getIdDegustacion(),
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);

        obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Fecha Degustacin",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueve,
                DateManage.dateToStringEspanol(this.degustacion.getFechaApertura()),
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Promotor",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueve,
                datosUsuarioVendedor != null
                        ? (datosUsuarioVendedor.getNombre() + " " + datosUsuarioVendedor.getApellidoPat())
                        : "Sin vendedor asignado",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);

        //Pintamos datos informativos Generales en la esquina superior derecha
        PdfContentByte cb = writer.getDirectContent();
        tInfoGeneral.writeSelectedRows(0, -1, doc.right() - 180, doc.top() + 100, cb);

        //Datos de Cliente/Prospecto
        PdfPTable tCliente = new PdfPTable(2);
        tCliente.setTotalWidth(550);
        tCliente.setLockedWidth(true);

        obj.agregaCelda(tCliente, letraNueveBold, Color.lightGray, "Cliente",
                new boolean[] { false, false, false, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 2);

        tAux = new PdfPTable(1);
        tAux.setTotalWidth(275);
        tAux.setLockedWidth(true);

        try {
            obj.agregaCelda(tAux, letraOcho,
                    "Nombre Comercial: " + (clienteDto != null ? clienteDto.getNombreComercial() : ""),
                    new boolean[] { false, true, false, false }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0,
                    new int[0], 1);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        obj.agregaTabla(tCliente, tAux, new boolean[] { false, false, false, false }, Element.ALIGN_LEFT,
                Element.ALIGN_TOP, 0, new int[0], 1);

        obj.agregaCelda(tCliente, letraOcho,
                "" + "DOMICILIO: \n" + (clienteDto != null ? "Calle: " + clienteDto.getCalle() : "") + " "
                        + (clienteDto != null ? clienteDto.getNumero() : "") + " "
                        + (clienteDto != null ? clienteDto.getNumeroInterior() : "")
                        + (clienteDto != null ? " Col: " + clienteDto.getColonia() : "")
                        + (clienteDto != null ? " \nDeleg./Municipio: " + clienteDto.getMunicipio() : "")
                        + (clienteDto != null ? " Estado: " + clienteDto.getEstado() : "")
                        + (clienteDto != null ? " \nC.P. " + clienteDto.getCodigoPostal() : ""),
                new boolean[] { false, true, false, true }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0,
                new int[0], 1);

        obj.agregaTabla(mainTable, tCliente, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER,
                Element.ALIGN_TOP, 0, new int[0], 1);

        //FIN Cabecera (Datos Generales)-----------------

        //DOBLE SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        int colsDetalles = 6;
        PdfPTable tDetalles = new PdfPTable(colsDetalles);//6);
        tDetalles.setTotalWidth(550);
        tDetalles.setWidths(new int[] { 200, 70, 70, 70, 70, 70 });
        tDetalles.setLockedWidth(true);

        /*CABECERA*/
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Producto Degustado",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Inicio",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Termino",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Inicial",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Final",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Piezas Degustadas",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);

        /*FIN DE CABECERA*/
        Degustacion[] degustacionDtos = new Degustacion[0];
        try {
            degustacionDtos = this.findDegustaciones(this.degustacion.getIdDegustacion(),
                    this.degustacion.getIdEmpresa(), -1, -1, "");
        } catch (Exception e) {
        }

        //Listado de Productos
        for (Degustacion item : degustacionDtos) {

            if (item != null) {

                Concepto conceptoDto = null;

                try {
                    ConceptoBO conceptoBO = new ConceptoBO(item.getIdConcepto(), this.conn);
                    conceptoDto = conceptoBO.getConcepto();
                } catch (Exception e) {
                }

                //Producto
                obj.agregaCelda(tDetalles, letraOcho, null, conceptoDto.getNombreDesencriptado(),
                        new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP,
                        15, new int[] { 5, 5, 5, 5 }, 1);

                //Inicio
                obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaApertura()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP,
                        15, new int[] { 5, 5, 5, 5 }, 1);

                //Termino
                obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaCierre()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

                //Inv inicial 
                obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidad()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

                //inv final 
                obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidadCierre()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

                //Piezas 
                obj.agregaCelda(tDetalles, letraOcho, null,
                        "" + (item.getCantidad() - item.getCantidadCierre()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

            }
        }

        obj.agregaTabla(mainTable, tDetalles, new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1);

        //DOBLE SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        /*prods Vendidos durante degustacion*/

        PdfPTable tVenta = new PdfPTable(4);
        tVenta.setTotalWidth(550);
        tVenta.setWidths(new int[] { 70, 140, 170, 120 });
        tVenta.setLockedWidth(true);

        obj.agregaCelda(tVenta, letraNueveBold, Color.lightGray, "Producto Vendido durante Degutacin",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 4);

        Productosvendidos[] pedidoProductoDto = new Productosvendidos[0];

        String filtroBusqueda = " ID_PEDIDO IN ( SELECT ID_PEDIDO FROM sgfens_pedido WHERE ID_EMPRESA = '"
                + this.degustacion.getIdEmpresa() + "' AND ID_TIPO_PEDIDO = 2 AND ID_USUARIO_VENDEDOR = "
                + this.degustacion.getIdUsuario() + " AND " + " ID_ESTATUS_PEDIDO<>2 AND FECHA_PEDIDO BETWEEN '"
                + this.degustacion.getFechaApertura() + "'  AND '" + this.degustacion.getFechaCierre() + "') ";

        try {
            pedidoProductoDto = new ProductosvendidosDaoImpl().findByDynamicWhere(filtroBusqueda, null);
        } catch (Exception e) {
        }

        if (pedidoProductoDto.length > 0) {

            obj.agregaCelda(tVenta, letraOchoBold, null, "Cdigo", new boolean[] { true, true, true, true },
                    Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1);
            obj.agregaCelda(tVenta, letraOchoBold, null, "Nombre", new boolean[] { true, true, true, true },
                    Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1);
            obj.agregaCelda(tVenta, letraOchoBold, null, "Descripcin",
                    new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                    new int[] { 5, 5, 5, 5 }, 1);
            obj.agregaCelda(tVenta, letraOchoBold, null, "Unidades Vendidas",
                    new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                    new int[] { 5, 5, 5, 5 }, 1);

            for (Productosvendidos pedidoProd : pedidoProductoDto) {

                if (pedidoProd != null) {

                    Concepto conceptoDto = null;
                    try {
                        ConceptoBO conceptoBO = new ConceptoBO(pedidoProd.getIdConcepto(), this.conn);
                        conceptoDto = conceptoBO.getConcepto();
                    } catch (Exception e) {
                    }

                    //Cdigo
                    obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getIdentificacion(),
                            new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED,
                            Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1);

                    //Nombre
                    obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getNombreDesencriptado(),
                            new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED,
                            Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1);

                    //Descripcin
                    obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getDescripcion(),
                            new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP,
                            15, new int[] { 5, 5, 5, 5 }, 1);

                    //Unidades Vendidas 
                    obj.agregaCelda(tVenta, letraOcho, null, "" + (pedidoProd.getCantidad()),
                            new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP,
                            15, new int[] { 5, 5, 5, 5 }, 1);

                }

            }
        } else {

            obj.agregaCelda(tVenta, letraOcho, null, "No se registrarn datos.",
                    new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                    new int[] { 5, 5, 5, 5 }, 4);

        }

        obj.agregaTabla(mainTable, tVenta, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER,
                Element.ALIGN_TOP, 0, new int[0], 1);

        //DOBLE SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        /*Comentarios Adicionales*/
        PdfPTable tComenst = new PdfPTable(1);
        tComenst.setTotalWidth(550);
        tComenst.setWidths(new int[] { 550 });
        tComenst.setLockedWidth(true);

        obj.agregaCelda(tComenst, letraNueveBold, Color.lightGray, "Comentarios",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 2);

        obj.agregaCelda(tComenst, letraOcho, null, this.degustacion.getComentariosCierre(),
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 2);

        obj.agregaTabla(mainTable, tComenst, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER,
                Element.ALIGN_TOP, 0, new int[0], 1);

        //FIN DE CONTENIDO --------

        //Aadimos tabla principal construida al documento
        doc.add(mainTable);
        mainTable.flushContent();

    } catch (Exception ex) {
        msgError = "No se ha podido generar la representacin impresa de la Degustacion en formato PDF:<br/>"
                + ex.toString();
    } finally {
        if (doc.isOpen())
            doc.close();
    }

    if (!msgError.equals("")) {
        throw new Exception(msgError);
    }

    return baos;

}

From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java

License:Open Source License

@Override
public void visit(StyleTableCellPropertiesElement ele) {
    StyleTableCellProperties tableCellProperties = currentStyle.getTableCellProperties();
    if (tableCellProperties == null) {
        tableCellProperties = new StyleTableCellProperties();
        currentStyle.setTableCellProperties(tableCellProperties);
    }/*w w w .j a v  a  2 s . c om*/

    // background-color
    String backgroundColor = ele.getFoBackgroundColorAttribute();
    if (StringUtils.isNotEmpty(backgroundColor)) {
        tableCellProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor));
    }

    // border
    String border = ele.getFoBorderAttribute();
    if (StringUtils.isNotEmpty(border)) {
        tableCellProperties.setBorder(new StyleBorder(border, BorderType.ALL));
    }

    // border-bottom
    String borderBottom = ele.getFoBorderBottomAttribute();
    if (StringUtils.isNotEmpty(borderBottom)) {
        tableCellProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM));
    }

    // border-left
    String borderLeft = ele.getFoBorderLeftAttribute();
    if (StringUtils.isNotEmpty(borderLeft)) {
        tableCellProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT));
    }

    // border-bottom
    String borderRight = ele.getFoBorderRightAttribute();
    if (StringUtils.isNotEmpty(borderRight)) {
        tableCellProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT));
    }

    // border-top
    String borderTop = ele.getFoBorderTopAttribute();
    if (StringUtils.isNotEmpty(borderTop)) {
        tableCellProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP));
    }

    // padding
    String padding = ele.getFoPaddingAttribute();
    if (StringUtils.isNotEmpty(padding)) {
        tableCellProperties.setPadding(ODFUtils.getDimensionAsPoint(padding));
    }

    // padding-bottom
    String paddingBottom = ele.getFoPaddingBottomAttribute();
    if (StringUtils.isNotEmpty(paddingBottom)) {
        tableCellProperties.setPaddingBottom(ODFUtils.getDimensionAsPoint(paddingBottom));
    }

    // padding-left
    String paddingLeft = ele.getFoPaddingLeftAttribute();
    if (StringUtils.isNotEmpty(paddingLeft)) {
        tableCellProperties.setPaddingLeft(ODFUtils.getDimensionAsPoint(paddingLeft));
    }

    // padding-right
    String paddingRight = ele.getFoPaddingRightAttribute();
    if (StringUtils.isNotEmpty(paddingRight)) {
        tableCellProperties.setPaddingRight(ODFUtils.getDimensionAsPoint(paddingRight));
    }

    // padding-top
    String paddingTop = ele.getFoPaddingTopAttribute();
    if (StringUtils.isNotEmpty(paddingTop)) {
        tableCellProperties.setPaddingTop(ODFUtils.getDimensionAsPoint(paddingTop));
    }

    // vertical-align
    String verticalAlign = ele.getStyleVerticalAlignAttribute();
    if (StringUtils.isNotEmpty(verticalAlign)) {
        if (StyleVerticalAlignAttribute.Value.BASELINE.toString().equals(verticalAlign)) {
            tableCellProperties.setVerticalAlignment(Element.ALIGN_BASELINE);
        } else if (StyleVerticalAlignAttribute.Value.TOP.toString().equals(verticalAlign)) {
            tableCellProperties.setVerticalAlignment(Element.ALIGN_TOP);
        } else if (StyleVerticalAlignAttribute.Value.MIDDLE.toString().equals(verticalAlign)) {
            tableCellProperties.setVerticalAlignment(Element.ALIGN_MIDDLE);
        } else if (StyleVerticalAlignAttribute.Value.BOTTOM.toString().equals(verticalAlign)) {
            tableCellProperties.setVerticalAlignment(Element.ALIGN_BOTTOM);
        }
    }

    super.visit(ele);
}