Example usage for com.lowagie.text Document add

List of usage examples for com.lowagie.text Document add

Introduction

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

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

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

License:Open Source License

private void createProductsTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    List<Entity> columnsForDeliveries = deliveriesService.getColumnsForDeliveries();

    if (!columnsForDeliveries.isEmpty()) {
        List<DeliveryProduct> deliveryProducts = deliveryColumnFetcher.getDeliveryProducts(delivery);

        Map<DeliveryProduct, Map<String, String>> deliveryProductsColumnValues = deliveryColumnFetcher
                .getDeliveryProductsColumnValues(deliveryProducts);

        List<Entity> filteredColumnsForDeliveries = getDeliveryReportColumns(columnsForDeliveries,
                deliveryProducts, deliveryProductsColumnValues);

        if (!filteredColumnsForDeliveries.isEmpty()) {
            List<String> columnsName = Lists.newArrayList();

            for (Entity entity : filteredColumnsForDeliveries) {
                columnsName.add(entity.getStringField(ColumnForDeliveriesFields.IDENTIFIER));
            }/*from  www .j  a  v a 2 s .c o  m*/

            Map<String, HeaderAlignment> alignments = prepareHeaderAlignment(filteredColumnsForDeliveries,
                    locale);
            PdfPTable productsTable = pdfHelper.createTableWithHeader(filteredColumnsForDeliveries.size(),
                    prepareProductsTableHeader(document, filteredColumnsForDeliveries, locale), false,
                    pdfHelper.getReportColumnWidths(REPORT_WIDTH, parameterService.getReportColumnWidths(),
                            columnsName),
                    alignments);

            for (DeliveryProduct deliveryProduct : deliveryProducts) {
                for (Entity columnForDeliveries : filteredColumnsForDeliveries) {
                    String identifier = columnForDeliveries
                            .getStringField(ColumnForDeliveriesFields.IDENTIFIER);
                    String alignment = columnForDeliveries.getStringField(ColumnForDeliveriesFields.ALIGNMENT);

                    String value = deliveryProductsColumnValues.get(deliveryProduct).get(identifier);

                    prepareProductColumnAlignment(productsTable.getDefaultCell(),
                            ColumnAlignment.parseString(alignment));

                    productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark()));
                }
            }

            addTotalRow(productsTable, locale, columnsName, delivery);

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

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   w ww.j av  a 2s  .c om*/

    return productsHeader;
}

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);//from  ww  w .  ja  v a  2  s .  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.deliveries.print.OrderReportPdf.java

License:Open Source License

private void createProductsTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    List<Entity> columnsForOrders = deliveriesService.getColumnsForOrders();

    if (!columnsForOrders.isEmpty()) {
        List<Entity> orderedProducts = delivery.getHasManyField(DeliveryFields.ORDERED_PRODUCTS);

        Map<Entity, Map<String, String>> orderedProductsColumnValues = orderColumnFetcher
                .getOrderedProductsColumnValues(orderedProducts);

        List<Entity> filteredColumnsForOrders = getOrderReportColumns(columnsForOrders, orderedProducts,
                orderedProductsColumnValues);

        if (!filteredColumnsForOrders.isEmpty()) {
            List<String> columnsName = Lists.newArrayList();

            for (Entity entity : filteredColumnsForOrders) {
                columnsName.add(entity.getStringField(ColumnForOrdersFields.IDENTIFIER));
            }//from w w  w.j ava  2 s.  c  o m

            Map<String, HeaderAlignment> alignments = prepareHeaderAlignment(filteredColumnsForOrders, locale);
            PdfPTable productsTable = pdfHelper.createTableWithHeader(filteredColumnsForOrders.size(),
                    prepareProductsTableHeader(document, filteredColumnsForOrders, locale), false,
                    pdfHelper.getReportColumnWidths(REPORT_WIDTH, parameterService.getReportColumnWidths(),
                            columnsName),
                    alignments);

            for (Entity orderedProduct : orderedProducts) {
                for (Entity columnForOrders : filteredColumnsForOrders) {
                    String identifier = columnForOrders.getStringField(ColumnForOrdersFields.IDENTIFIER);
                    String alignment = columnForOrders.getStringField(ColumnForOrdersFields.ALIGNMENT);

                    String value = orderedProductsColumnValues.get(orderedProduct).get(identifier);

                    prepareProductColumnAlignment(productsTable.getDefaultCell(),
                            ColumnAlignment.parseString(alignment));

                    productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark()));
                }
            }

            addTotalRow(productsTable, locale, columnsName, delivery);

            document.add(productsTable);
            // document.add(Chunk.NEWLINE);
        }
    }
}

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(
            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));
    }/*from   ww w  .  jav  a 2  s  . c  o m*/

    return productsHeader;
}

From source file:com.qcadoo.mes.genealogies.print.GenealogyForProductView.java

License:Open Source License

private void addTables(final Document document, final Entity entity, final Locale locale)
        throws DocumentException {
    List<String> orderHeader = new ArrayList<String>();
    orderHeader.add(translationService.translate("orders.order.number.label", locale));
    orderHeader.add(translationService.translate("orders.order.name.label", locale));
    orderHeader.add(translationService.translate("orders.order.dateFrom.label", locale));
    Paragraph productTitle = new Paragraph(new Phrase(
            translationService.translate("genealogies.genealogyForProduct.report.paragrah.product", locale),
            FontUtils.getDejavuBold11Light()));
    productTitle.setSpacingBefore(20);/*from   w w  w  .  j a v  a2  s. c  o  m*/
    document.add(productTitle);
    PdfPTable headerData = pdfHelper.createPanelTable(3);
    headerData.setSpacingBefore(7);
    Entity product = entity.getBelongsToField(ORDER_FIELD).getBelongsToField(PRODUCT_FIELD);
    pdfHelper.addTableCellAsOneColumnTable(headerData,
            translationService.translate("basic.product.number.label", locale), product.getField(NUMBER_FIELD));
    pdfHelper.addTableCellAsOneColumnTable(headerData,
            translationService.translate("basic.product.name.label", locale), product.getField(NAME_FIELD));
    pdfHelper.addTableCellAsOneColumnTable(headerData,
            translationService.translate("genealogies.genealogy.batch.label", locale),
            entity.getField(BATCH_FIELD));
    document.add(headerData);
    Paragraph orderTitle = new Paragraph(new Phrase(
            translationService.translate("genealogies.genealogyForProduct.report.paragrah.order", locale),
            FontUtils.getDejavuBold11Light()));
    orderTitle.setSpacingBefore(20);
    document.add(orderTitle);
    List<Entity> orders = getOrders(entity);
    Collections.sort(orders, new EntityNumberComparator());
    addOrderSeries(document, orders, orderHeader);
    if (pluginManager.isPluginEnabled(GENEALOGIES_FOR_COMPONENTS_PLUGIN)) {
        addComponentSeries(document, orders, locale);
    }
}

From source file:com.qcadoo.mes.genealogies.print.GenealogyForProductView.java

License:Open Source License

private void addComponentSeries(final Document document, final List<Entity> orders, final Locale locale)
        throws DocumentException {
    for (Entity order : orders) {
        document.add(Chunk.NEWLINE);
        Paragraph title = new Paragraph(new Phrase(
                translationService.translate("genealogies.genealogyForProduct.report.paragrah", locale),
                FontUtils.getDejavuBold11Light()));
        title.add(new Phrase(" " + order.getField(NUMBER_FIELD).toString(), FontUtils.getDejavuBold19Dark()));
        document.add(title);/*from  w  w w.j a va  2 s.  co  m*/
        List<String> componentHeader = new ArrayList<String>();
        componentHeader.add(translationService.translate("basic.product.number.label", locale));
        componentHeader.add(translationService.translate("basic.product.name.label", locale));
        componentHeader.add(
                translationService.translate("genealogiesForComponents.productInBatch.batch.label", locale));
        PdfPTable table = pdfHelper.createTableWithHeader(3, componentHeader, false);

        List<Pair<String, Entity>> batchList = getBatchList(order);

        Collections.sort(batchList, new BatchOrderNrComparator());

        for (Pair<String, Entity> pair : batchList) {
            String batch = pair.getKey();
            Entity product = pair.getValue();
            table.addCell(
                    new Phrase(product.getField(NUMBER_FIELD).toString(), FontUtils.getDejavuRegular9Dark()));
            table.addCell(
                    new Phrase(product.getField(NAME_FIELD).toString(), FontUtils.getDejavuRegular9Dark()));
            table.addCell(new Phrase(batch, FontUtils.getDejavuRegular9Dark()));
        }
        document.add(table);

    }
}

From source file:com.qcadoo.mes.genealogies.print.GenealogyForProductView.java

License:Open Source License

private void addOrderSeries(final Document document, final List<Entity> orders, final List<String> orderHeader)
        throws DocumentException {
    PdfPTable table = pdfHelper.createTableWithHeader(3, orderHeader, false);
    for (Entity order : orders) {
        table.addCell(new Phrase(order.getField(NUMBER_FIELD).toString(), FontUtils.getDejavuRegular9Dark()));
        table.addCell(new Phrase(order.getField(NAME_FIELD).toString(), FontUtils.getDejavuRegular9Dark()));
        table.addCell(//from  ww w.j a  v  a2 s .  c  o m
                new Phrase(order.getField(DATE_FROM_FIELD).toString(), FontUtils.getDejavuRegular9Dark()));
    }
    document.add(table);
}

From source file:com.qcadoo.mes.genealogiesForComponents.GenealogyForComponentView.java

License:Open Source License

private void addTables(final Document document, final Entity entity, final Locale locale)
        throws DocumentException {
    List<String> orderHeader = new ArrayList<String>();
    orderHeader.add(translationService.translate("orders.order.number.label", locale));
    orderHeader.add(translationService.translate("orders.order.name.label", locale));
    orderHeader.add(translationService.translate("orders.order.product.label", locale));
    orderHeader.add(translationService//from w  w w .  j  a  v a2s . co  m
            .translate("genealogiesForComponents.genealogyForComponent.report.productBatch", locale));
    Paragraph productTitle = new Paragraph(new Phrase(
            translationService.translate(
                    "genealogiesForComponents.genealogyForComponent.report.paragrah.product", locale),
            FontUtils.getDejavuBold11Light()));
    productTitle.setSpacingBefore(20);
    document.add(productTitle);
    PdfPTable headerData = pdfHelper.createPanelTable(3);
    headerData.setSpacingBefore(7);
    Entity product = entity.getBelongsToField("productInComponent").getBelongsToField("productInComponent")
            .getBelongsToField("product");
    pdfHelper.addTableCellAsOneColumnTable(headerData,
            translationService.translate("basic.product.number.label", locale), product.getField("number"));
    pdfHelper.addTableCellAsOneColumnTable(headerData,
            translationService.translate("basic.product.name.label", locale), product.getField("name"));
    pdfHelper.addTableCellAsOneColumnTable(headerData,
            translationService.translate("genealogiesForComponents.productInBatch.batch.label", locale),
            entity.getField(BATCH_FIELD));
    document.add(headerData);
    Paragraph orderTitle = new Paragraph(
            new Phrase(
                    translationService.translate(
                            "genealogiesForComponents.genealogyForComponent.report.paragrah.order", locale),
                    FontUtils.getDejavuBold11Light()));
    orderTitle.setSpacingBefore(20);
    document.add(orderTitle);
    addOrderSeries(document, entity, orderHeader);
}

From source file:com.qcadoo.mes.genealogiesForComponents.GenealogyForComponentView.java

License:Open Source License

private void addOrderSeries(final Document document, final Entity entity, final List<String> orderHeader)
        throws DocumentException {
    PdfPTable table = pdfHelper.createTableWithHeader(4, orderHeader, false);
    List<Entity> genealogies = getGenealogies(entity);
    Collections.sort(genealogies, new EntityOrderNumberComparator());
    for (Entity genealogy : genealogies) {
        Entity order = (Entity) genealogy.getField("order");
        table.addCell(new Phrase(order.getField("number").toString(), FontUtils.getDejavuRegular9Dark()));
        table.addCell(new Phrase(order.getField("name").toString(), FontUtils.getDejavuRegular9Dark()));
        Entity product = (Entity) order.getField("product");
        if (product == null) {
            table.addCell(new Phrase("", FontUtils.getDejavuRegular9Dark()));
        } else {//from ww w  . java  2s .c  o  m
            table.addCell(new Phrase(product.getField("name").toString(), FontUtils.getDejavuRegular9Dark()));
        }
        table.addCell(
                new Phrase(genealogy.getField(BATCH_FIELD).toString(), FontUtils.getDejavuRegular9Dark()));
    }
    document.add(table);
}