PdfPTable my_report_table = new PdfPTable(5); my_report_table.setSpacingAfter(10);
document.add(new Paragraph("By design tables are filled row by row:")); PdfPTable table = new PdfPTable(5); table.setSpacingBefore(10); table.setSpacingAfter(10); for (int i = 1; i <= 15; i++) { table.addCell("cell " + i); } document.add(table);
PdfPTable outerTable = new PdfPTable(1); outerTable.setSpacingAfter(0); outerTable.setSpacingBefore(0); outerTable.setTotalWidth(document.right() - document.left()); outerTable.setLockedWidth(true);
private void addTableToDocument(Document document, Entity orderEntity, Locale locale, String headerKey, Map<String, String> values) throws DocumentException { document.add(new Paragraph(translationService.translate(headerKey, locale), FontUtils.getDejavuBold10Dark())); Map<String, HeaderAlignment> headerValues = Maps.newLinkedHashMap(); for (String key : values.keySet()) { headerValues.put(translationService.translate(String.format(L_TRANSLATION_PATH, key), locale), HeaderAlignment.LEFT); } PdfPTable table = pdfHelper.createTableWithHeader(values.size(), Lists.newArrayList(headerValues.keySet()), false, headerValues); table.getDefaultCell().disableBorderSide(PdfPCell.RIGHT); table.getDefaultCell().disableBorderSide(PdfPCell.LEFT); table.setHeaderRows(1); for (String value : values.values()) { table.addCell(createCell(value, Element.ALIGN_LEFT)); } table.setSpacingAfter(20); document.add(table); }
public static PdfPTable createTwoColumnsTitledTable( final List<String> titles, final List<String> content) { PdfPTable table = new PdfPTable(10); Iterator<String> itLeft = titles.iterator(); Iterator<String> itRight = content.iterator(); while (itLeft.hasNext()) { String textLeft = itLeft.next(); String textRight = itRight.next(); table.getDefaultCell().setColspan(1); table.addCell(textLeft); table.getDefaultCell().setColspan(9); table.addCell(textRight); } table.setSpacingBefore(20); table.setSpacingAfter(20); table.setLockedWidth(false); table.setWidthPercentage(90); return table; } }
private PdfPTable createTable() { int[] headerWidths = Ints.toArray(getHeaderWidths()); Map<String, HeaderAlignment> headerValues = getHeaderValues(locale); PdfPTable warehouseTable = pdfHelper.createTableWithHeader(headerWidths.length, Lists.newArrayList(headerValues.keySet()), false, headerWidths, headerValues); warehouseTable.getDefaultCell().disableBorderSide(PdfPCell.RIGHT); warehouseTable.getDefaultCell().disableBorderSide(PdfPCell.LEFT); warehouseTable.setHeaderRows(1); warehouseTable.setSpacingAfter(12.0f); return warehouseTable; }
private void addHeaderTable(Document document, Entity orderEntity, Locale locale) throws DocumentException { PdfPTable table = pdfHelper.createPanelTable(3); List<HeaderPair> headerValues = getDocumentHeaderTableContent(orderEntity, locale); for (HeaderPair pair : headerValues) { if (pair.getValue() != null && !pair.getValue().isEmpty()) { pdfHelper.addTableCellAsOneColumnTable(table, pair.getLabel(), pair.getValue()); } else { pdfHelper.addTableCellAsOneColumnTable(table, StringUtils.EMPTY, StringUtils.EMPTY); } } table.setSpacingAfter(20); document.add(table); }
public void print(Entity order, Entity operationComponent, Document document, Locale locale) throws DocumentException { PdfPTable operationTable = pdfHelper.createPanelTable(3); operationOrderInfoOperation.print(operationComponent, operationTable, locale); if (isOrderInfoEnabled()) { operationOrderInfoHeader.print(order, operationTable, locale); } operationOrderInfoWorkstation.print(operationComponent, operationTable, locale); operationTable.setSpacingAfter(18); operationTable.setSpacingBefore(9); document.add(operationTable); }
private void createInfoTable(final Document document, final Locale locale, final Entity trackingRecord) throws DocumentException { Entity producedBatch = trackingRecord.getBelongsToField(L_PRODUCED_BATCH); String producedBatchNumber = producedBatch.getStringField(L_NUMBER); String producedBatchProductNumber = producedBatch.getBelongsToField(L_PRODUCT).getStringField(L_NUMBER); String producedBatchProductName = producedBatch.getBelongsToField(L_PRODUCT).getStringField(L_NAME); String producedBatchProductNameNumber = producedBatchProductName + "(" + producedBatchProductNumber + ")"; String producedBatchProductUnit = producedBatch.getBelongsToField(L_PRODUCT).getStringField(L_UNIT); String producedBatchSupplierName = (producedBatch.getBelongsToField(L_SUPPLIER) == null) ? " " : producedBatch .getBelongsToField(L_SUPPLIER).getStringField("L_NAME"); String producedBatchQuantity = (trackingRecord.getField(L_QUANTITY) == null) ? " " : numberService.format(trackingRecord .getField(L_QUANTITY)) + " " + producedBatchProductUnit; Map<String, String> panelTableValues = newLinkedHashMap(); panelTableValues.put(L_BATCH, producedBatchNumber); panelTableValues.put(L_PRODUCT, producedBatchProductNameNumber); panelTableValues.put(L_SUPPLIER, producedBatchSupplierName); panelTableValues.put(L_QUANTITY, producedBatchQuantity); PdfPTable panelTable = pdfHelper.createPanelTable(2); for (Map.Entry<String, String> panelEntry : panelTableValues.entrySet()) { pdfHelper.addTableCellAsOneColumnTable( panelTable, translationService.translate( "advancedGenealogy.trackingRecordSimpleDetails.report.panel." + panelEntry.getKey(), locale), panelEntry.getValue()); } panelTable.setSpacingAfter(20); panelTable.setSpacingBefore(20); document.add(panelTable); }
private void addHeaderTable(Document document, Entity documentEntity, Locale locale) throws DocumentException { PdfPTable table = pdfHelper.createPanelTable(2); table.setSpacingAfter(20); List<HeaderPair> headerValues = getDocumentHeaderTableContent(documentEntity, locale); for (HeaderPair pair : headerValues) { if (pair.getValue() != null && !pair.getValue().isEmpty()) { pdfHelper.addTableCellAsOneColumnTable(table, pair.getLabel(), pair.getValue(), pair.isBoldAndBigger()); } else { pdfHelper.addTableCellAsOneColumnTable(table, StringUtils.EMPTY, StringUtils.EMPTY); } } document.add(table); }
table.setSpacingAfter(18); table.setSpacingBefore(9);
table.setSpacingAfter(18); table.setSpacingBefore(9);
public void print(Entity operationComponent, Document document, Locale locale) throws DocumentException { String commentContent = operationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); if (commentContent == null) { return; } PdfPTable table = pdfHelper.createPanelTable(1); table.getDefaultCell().setBackgroundColor(null); String commentLabel = translationService.translate("workPlans.workPlan.report.operation.comment", locale); pdfHelper.addTableCellAsOneColumnTable(table, commentLabel, commentContent); table.setSpacingAfter(18); table.setSpacingBefore(9); document.add(table); }
private void addPanel(final Document document, final Entity simpleMaterialBalance, final Locale locale) throws DocumentException { PdfPTable panelTable = pdfHelper.createPanelTable(2); pdfHelper.addTableCellAsOneColumnTable( panelTable, translationService.translate( "simpleMaterialBalance.simpleMaterialBalance.report.panel.simpleMaterialBalance.date", locale), DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT, locale).format( (Date) simpleMaterialBalance.getField(L_DATE))); pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate( "simpleMaterialBalance.simpleMaterialBalance.report.panel.simpleMaterialBalance.name", locale), simpleMaterialBalance.getStringField(L_NAME)); pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate( "simpleMaterialBalance.simpleMaterialBalance.report.panel.simpleMaterialBalance.worker", locale), simpleMaterialBalance.getStringField(L_WORKER)); pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate( "simpleMaterialBalance.simpleMaterialBalance.report.panel.simpleMaterialBalance.mrpAlgorithm", locale), translationService.translate("simpleMaterialBalance.simpleMaterialBalance.mrpAlgorithm.value." + simpleMaterialBalance.getStringField("mrpAlgorithm"), locale)); panelTable.setSpacingAfter(20); panelTable.setSpacingBefore(20); document.add(panelTable); }
@Override protected void buildPdfContent(final Document document, final Entity productionTrackingReport, final Locale locale) throws DocumentException { final String documentTitle = translationService.translate("productionCounting.productionTrackingReport.report.title", locale) + " " + productionTrackingReport.getId().toString(); final String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionTrackingReport.getDateField(ProductionTrackingReportFields.DATE)); final PdfPTable leftPanel = createLeftPanel(productionTrackingReport, locale); final PdfPTable rightPanel = createRightPanel(productionTrackingReport, locale); final PdfPTable panelTable = pdfHelper.createPanelTable(2); panelTable.addCell(leftPanel); panelTable.addCell(rightPanel); panelTable.setSpacingAfter(20); panelTable.setSpacingBefore(20); document.add(panelTable); Entity order = productionTrackingReport.getBelongsToField(ProductionTrackingReportFields.ORDER); final List<Entity> productionTrackings = productionCountingService.getProductionTrackingsForOrder(order); Collections.sort(productionTrackings, new EntityProductionTrackingComparator()); for (Entity productionTracking : productionTrackings) { addProductionTracking(document, productionTracking, locale); } }
private PdfPTable createTable( PdfPCell cell ) { PdfPTable table = new PdfPTable( 1 ); table.setSpacingBefore( this.spacingBefore() ); table.setSpacingAfter( this.spacingAfter() ); table.setHorizontalAlignment( this.getHorizontalAlignment() ); table.setTotalWidth( cell.getPaddingLeft() + this.getTotalWidth() + cell.getPaddingRight() ); table.setLockedWidth( true ); table.setSplitLate( false ); table.addCell( cell ); return table; }
private PdfPTable createTable( PdfPCell cell ) { PdfPTable table = new PdfPTable( 1 ); table.setSpacingBefore( this.spacingBefore() ); table.setSpacingAfter( this.spacingAfter() ); table.setHorizontalAlignment( this.getHorizontalAlignment() ); table.setTotalWidth( cell.getPaddingLeft() + this.getTotalWidth() + cell.getPaddingRight() ); table.setLockedWidth( true ); table.setSplitLate( false ); table.addCell( cell ); return table; }
private void addPanel(final Document document, final Entity materialRequirement, final Locale locale) throws DocumentException { PdfPTable panelTable = pdfHelper.createPanelTable(2); pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate("materialRequirements.materialRequirement.report.panel.number", locale), materialRequirement.getStringField(MaterialRequirementFields.NUMBER)); pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate( "materialRequirements.materialRequirement.report.panel.name", locale), StringUtils.isEmpty(materialRequirement.getStringField(MaterialRequirementFields.NAME)) ? "" : materialRequirement.getStringField(MaterialRequirementFields.NAME)); pdfHelper.addTableCellAsOneColumnTable( panelTable, translationService.translate("materialRequirements.materialRequirement.report.panel.mrpAlgorithm", locale), translationService.translate( "materialRequirements.materialRequirement.mrpAlgorithm.value." + materialRequirement.getStringField(MaterialRequirementFields.MRP_ALGORITHM), locale)); pdfHelper.addTableCellAsOneColumnTable(panelTable, "", ""); panelTable.setSpacingAfter(20); panelTable.setSpacingBefore(20); document.add(panelTable); }
@Override public void onEndPage(final PdfWriter writer, final Document document) { try { Image logoImage = Image.getInstance(logo); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(4); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.addCell(logoImage); Phrase projectName = new Phrase(project.getName(), FontFactory.getFont( FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); Phrase phrase = new Phrase("Sonar PDF Report", FontFactory.getFont( FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); head.getDefaultCell().setColspan(2); head.addCell(phrase); head.getDefaultCell().setColspan(1); head.addCell(projectName); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - 20, writer.getDirectContent()); head.setSpacingAfter(10); } catch (BadElementException e) { LOG.error("Can not generate PDF header", e); } catch (MalformedURLException e) { LOG.error("Can not generate PDF header", e); } catch (IOException e) { LOG.error("Can not generate PDF header", e); } }
private void addWorkPlanTitle(Document document, Entity workPlan, String title, Locale locale) throws DocumentException { PdfPTable headerTable = pdfHelper.createPanelTable(2); PdfPCell titleCell = new PdfPCell(); titleCell.setBorder(Rectangle.NO_BORDER); Paragraph workPlanTitle = new Paragraph(new Phrase(getWorkPlanTitle(locale), FontUtils.getDejavuBold11Light())); workPlanTitle.add(new Phrase(" " + getWorkPlanName(workPlan), FontUtils.getDejavuBold11Dark())); titleCell.addElement(workPlanTitle); PdfPCell divisionCell = new PdfPCell(); divisionCell.setBorder(Rectangle.NO_BORDER); Paragraph divisionTitle = new Paragraph(new Phrase(getDivisionTitle(locale), FontUtils.getDejavuBold11Light())); divisionTitle.add(new Phrase(" " + getDivisionFromTitle(title, locale), FontUtils.getDejavuBold11Dark())); divisionTitle.setAlignment(Element.ALIGN_RIGHT); divisionCell.addElement(divisionTitle); headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headerTable.setTableEvent(null); headerTable.setSpacingAfter(4.0f); headerTable.addCell(titleCell); headerTable.addCell(divisionCell); document.add(headerTable); }