List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell
public PdfPCell(PdfPCell cell)
PdfPCell
. From source file:com.parakhcomputer.util.pdf.FirstPdf.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from ww w .jav a 2 s . c o m*/ c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }
From source file:com.prime.location.billing.InvoicedBillingManager.java
/** * Print invoice//from w w w . j a va2 s . c o m */ public void printInvoice() { try { //catch better your exceptions, this is just an example FacesContext context = FacesContext.getCurrentInstance(); Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f); String fileName = "PDFFile"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(pdf, baos); TableHeader event = new TableHeader(); event.setHeader("Header Here"); writer.setPageEvent(event); if (!pdf.isOpen()) { pdf.open(); } PdfPCell cell; PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 }); cell = new PdfPCell(new Paragraph("INVOICE", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); header.setTotalWidth(527); header.setLockedWidth(true); cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription())); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId())); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); cell = new PdfPCell( new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate()))); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); pdf.add(header); PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 }); table.setSpacingBefore(15f); table.setTotalWidth(527); table.setLockedWidth(true); //table.setWidths(new int[]{3, 1, 1}); table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY); table.addCell("Date"); table.addCell("Name"); table.addCell("Service"); table.addCell("Rate"); table.getDefaultCell().setBackgroundColor(null); cell = new PdfPCell(new Phrase("Total(US$): ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); // There are three special rows table.setHeaderRows(2); // One of them is a footer table.setFooterRows(1); Font f = FontFactory.getFont(FontFactory.HELVETICA, 10); //add remaining for (AgencyBilling billing : selectedInvoice.getBillings()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setIndent(2); table.getDefaultCell().setFixedHeight(20); table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f)); table.addCell(new Phrase(billing.getPerson().getName(), f)); table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f)); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } pdf.add(table); writer.getAcroForm().setNeedAppearances(true); //document.add(new Phrase(TEXT)); //Keep modifying your pdf file (add pages and more) pdf.close(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception e) { //e.printStackTrace(); } }
From source file:com.prime.report.template.TableHeader.java
/** * Adds a header to every page/*from w w w .j a va 2s. c o m*/ * * @param writer * @param document * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(4); try { table.setWidths(new int[] { 10, 11, 9, 1 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); Image img = Image.getInstance(logo); table.addCell(Image.getInstance(img)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase("New South West Facility Center", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, Color.BLACK))); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Page %d of", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } catch (IOException ex) { Logger.getLogger(TableHeader.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java
License:Open Source License
private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName, Entity delivery) {// w w w . j a va2 s .c o m DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery, numberService); PdfPCell total = new PdfPCell( new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale), FontUtils.getDejavuRegular7Dark())); total.setColspan(2); total.setHorizontalAlignment(Element.ALIGN_LEFT); total.setVerticalAlignment(Element.ALIGN_MIDDLE); total.setBackgroundColor(null); total.disableBorderSide(Rectangle.RIGHT); total.disableBorderSide(Rectangle.LEFT); total.setBorderColor(ColorUtils.getLineLightColor()); productsTable.addCell(total); for (int i = 2; i < columnsName.size(); i++) { if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY) && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(DeliveredProductFields.DELIVERED_QUANTITY) && columnsName.indexOf(DeliveredProductFields.DELIVERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell(new Phrase( numberService.format(deliveryPricesAndQuantities.getDeliveredCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(DeliveredProductFields.TOTAL_PRICE) && columnsName.indexOf(DeliveredProductFields.TOTAL_PRICE) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getDeliveredTotalPrice()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); productsTable.addCell( new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark())); } else { productsTable.addCell(""); } } }
From source file:com.qcadoo.mes.deliveries.print.OrderReportPdf.java
License:Open Source License
private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName, Entity delivery) {//from w w w . j ava 2 s . co m DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery, numberService); PdfPCell total = new PdfPCell( new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale), FontUtils.getDejavuRegular7Dark())); total.setColspan(2); total.setHorizontalAlignment(Element.ALIGN_LEFT); total.setVerticalAlignment(Element.ALIGN_MIDDLE); total.setBackgroundColor(null); total.disableBorderSide(Rectangle.RIGHT); total.disableBorderSide(Rectangle.LEFT); total.setBorderColor(ColorUtils.getLineLightColor()); productsTable.addCell(total); for (int i = 2; i < columnsName.size(); i++) { if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY) && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(OrderedProductFields.TOTAL_PRICE) && columnsName.indexOf(OrderedProductFields.TOTAL_PRICE) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedTotalPrice()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); productsTable.addCell( new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark())); } else { productsTable.addCell(""); } } }
From source file:com.qcadoo.mes.warehouseMinimalState.print.DocumentPdf.java
License:Open Source License
public void addSmallCell(PdfPTable table, BigDecimal content) { PdfPCell cell = new PdfPCell(table.getDefaultCell()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); String value = numberService.formatWithMinimumFractionDigits(content, 0); cell.setPhrase(new Phrase(value, FontUtils.getDejavuRegular7Dark())); table.addCell(cell);/* w w w . j a va2 s . c om*/ }
From source file:com.safetys.framework.jmesa.view.pdfp.PdfPView.java
License:Apache License
@SuppressWarnings("deprecation") public PdfPTable render() { PdfPTable pdfpTable = new PdfPTable(getTable().getRow().getColumns().size()); pdfpTable.setSpacingBefore(3);// ww w . j a va 2 s . c o m Row row = getTable().getRow(); List<Column> columns = row.getColumns(); // build table headers for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { Column column = iter.next(); PdfPCell cell = new PdfPCell(new Paragraph(column.getTitle(), getHeaderCellFont())); cell.setPadding(3.0f); cell.setBackgroundColor(getHeaderBackgroundColor()); pdfpTable.addCell(cell); } // build table body Collection<?> items = getCoreContext().getPageItems(); int rowcount = 0; for (Object item : items) { rowcount++; columns = row.getColumns(); for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { Column column = iter.next(); String property = column.getProperty(); Object value = column.getCellRenderer().getCellEditor().getValue(item, property, rowcount); PdfPCell cell = new PdfPCell( new Paragraph(value == null ? "" : String.valueOf(value), getCellFont())); cell.setPadding(3.0f); if (isRowEven(rowcount)) { cell.setBackgroundColor(getEvenCellBackgroundColor()); } else { cell.setBackgroundColor(getOddCellBackgroundColor()); } pdfpTable.addCell(cell); } } return pdfpTable; }
From source file:com.senacor.wbs.web.project.ProjectListPanel.java
License:Apache License
public ProjectListPanel(final String id, final List<Project> projects) { super(id);/*w w w . j a va2 s . c om*/ this.locale = getLocale(); SortableListDataProvider<Project> projectProvider = new SortableListDataProvider<Project>(projects) { @Override protected Locale getLocale() { return ProjectListPanel.this.getLocale(); } public IModel model(final Object object) { return new CompoundPropertyModel(object); } }; projectProvider.setSort("name", true); dataView = new DataView("projects", projectProvider, 4) { @Override protected void populateItem(final Item item) { Project project = (Project) item.getModelObject(); PageParameters pageParameters = new PageParameters(); pageParameters.put("projectId", project.getId()); item.add(new BookmarkablePageLink("tasks", ProjectDetailsPage.class, pageParameters) .add(new Label("id"))); item.add(new Label("kuerzel")); item.add(new Label("titel", project.getName())); item.add(new Label("budget")); item.add(new Label("costPerHour")); item.add(new Label("start")); item.add(new Label("ende")); item.add(new Label("state")); // Alternieren der Farbe zwischen geraden und // ungeraden Zeilen item.add(new AttributeModifier("class", true, new AbstractReadOnlyModel() { @Override public Object getObject() { return (item.getIndex() % 2 == 1) ? "even" : "odd"; } })); } }; add(dataView); Form localeForm = new Form("localeForm"); ImageButton deButton = new ImageButton("langde", new ResourceReference(BaseWBSPage.class, "de.png")) { @Override public void onSubmit() { ProjectListPanel.this.locale = Locale.GERMANY; } }; localeForm.add(deButton); ImageButton usButton = new ImageButton("langus", new ResourceReference(BaseWBSPage.class, "us.png")) { @Override public void onSubmit() { ProjectListPanel.this.locale = Locale.US; } }; localeForm.add(usButton); add(localeForm); final IResourceStream pdfResourceStream = new AbstractResourceStreamWriter() { public void write(final OutputStream output) { Document document = new Document(); try { PdfWriter.getInstance(document, output); document.open(); // document.add(new // Paragraph("WBS-Projektliste")); // document.add(new Paragraph("")); PdfPTable table = new PdfPTable(new float[] { 1f, 1f, 2f, 1f }); PdfPCell cell = new PdfPCell(new Paragraph("WBS-Projektliste")); cell.setColspan(4); cell.setGrayFill(0.8f); table.addCell(cell); table.addCell("ID"); table.addCell("Krzel"); table.addCell("Titel"); table.addCell("Budget in PT"); for (Project project : projects) { table.addCell("" + project.getId()); table.addCell(project.getKuerzel()); table.addCell(project.getName()); table.addCell("" + project.getBudget()); } document.add(table); document.close(); } catch (DocumentException e) { throw new RuntimeException(e); } } public String getContentType() { return "application/pdf"; } }; WebResource projectsResource = new WebResource() { { setCacheable(false); } @Override public IResourceStream getResourceStream() { return pdfResourceStream; } @Override protected void setHeaders(final WebResponse response) { super.setHeaders(response); // response.setAttachmentHeader("projekte.pdf"); } }; WebResource projectsResourceDL = new WebResource() { { setCacheable(false); } @Override public IResourceStream getResourceStream() { return pdfResourceStream; } @Override protected void setHeaders(final WebResponse response) { super.setHeaders(response); response.setAttachmentHeader("projekte.pdf"); } }; ResourceLink pdfDownload = new ResourceLink("pdfDownload", projectsResourceDL); ResourceLink pdfPopup = new ResourceLink("pdfPopup", projectsResource); PopupSettings popupSettings = new PopupSettings(PopupSettings.STATUS_BAR); popupSettings.setWidth(500); popupSettings.setHeight(700); pdfPopup.setPopupSettings(popupSettings); Link pdfReqTarget = new Link("pdfReqTarget") { @Override public void onClick() { RequestCycle.get() .setRequestTarget(new ResourceStreamRequestTarget(pdfResourceStream, "projekte.pdf")); } }; add(pdfReqTarget); add(pdfDownload); add(pdfPopup); add(new OrderByBorder("orderByKuerzel", "kuerzel", projectProvider)); add(new OrderByBorder("orderByName", "name", projectProvider)); add(new OrderByBorder("orderByBudget", "budget", projectProvider)); add(new OrderByBorder("orderByCostPerHour", "costPerHour", projectProvider)); add(new OrderByBorder("orderByStart", "start", projectProvider)); add(new OrderByBorder("orderByEnde", "ende", projectProvider)); add(new OrderByBorder("orderByState", "state", projectProvider)); add(new PagingNavigator("projectsNavigator", dataView)); }
From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) { try {//from w w w . j a v a 2s . c o m String activity = ""; if (step.getResolvedState() != null) { State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState()); activity = resolvedState.getLabel(getRole(), getLanguage()); } String sAction = null; try { if ("#question#".equals(step.getAction())) { sAction = getString("processManager.question"); } else if ("#response#".equals(step.getAction())) { sAction = getString("processManager.response"); } else if ("#reAssign#".equals(step.getAction())) { sAction = getString("processManager.reAffectation"); } else { Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction()); sAction = action.getLabel(getRole(), getLanguage()); } } catch (WorkflowException we) { sAction = "##"; } String actor = getBestUserDetail().getDisplayedName(); String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage()); String header = ""; if (StringUtil.isDefined(activity)) { header += activity + " - "; } header += sAction + " (" + actor + " - " + date + ")"; Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL); PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader)); pCell.setFixedHeight(28); pCell.setBackgroundColor(new Color(239, 239, 239)); pCell.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPTable pTable = new PdfPTable(1); pTable.setWidthPercentage(100); pTable.addCell(pCell); document.add(pTable); } catch (Exception e) { SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e); } }
From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepContent(HistoryStep step, com.lowagie.text.Document document) { try {// w ww . j a v a 2 s. c o m Form form; if ("#question#".equals(step.getAction()) || "#response#".equals(step.getAction())) { // TODO form = null; } else { form = getProcessInstance().getProcessModel().getPresentationForm(step.getAction(), getRole(), getLanguage()); } XmlForm xmlForm = (XmlForm) form; if (xmlForm != null && step.getActionRecord() != null) { DataRecord data = step.getActionRecord(); VersioningUtil versioningUtil = new VersioningUtil(); // Force simpletext displayers because itext cannot display HTML Form fields (select, // radio...) float[] colsWidth = { 25, 75 }; PdfPTable tableContent = new PdfPTable(colsWidth); tableContent.setWidthPercentage(100); PdfPCell cell = null; Field field; String fieldLabel; String fieldValue = ""; Font fontLabel = new Font(Font.HELVETICA, 10, Font.BOLD); Font fontValue = new Font(Font.HELVETICA, 10, Font.NORMAL); List<FieldTemplate> fieldTemplates = xmlForm.getFieldTemplates(); for (FieldTemplate fieldTemplate1 : fieldTemplates) { GenericFieldTemplate fieldTemplate = (GenericFieldTemplate) fieldTemplate1; fieldLabel = fieldTemplate.getLabel("fr"); field = data.getField(fieldTemplate.getFieldName()); String componentId = step.getProcessInstance().getProcessModel().getModelId(); // fieldValue = data.getField(fieldTemplate.getFieldName()).getValue(); //wysiwyg field if ("wysiwyg".equals(fieldTemplate.getDisplayerName())) { String file = WysiwygFCKFieldDisplayer.getFile(componentId, getProcessInstance().getInstanceId(), fieldTemplate.getFieldName(), getLanguage()); //Extract the text content of the html code Source source = new Source(file); if (source != null) { fieldValue = source.getTextExtractor().toString(); } } //Field file type else if (FileField.TYPE.equals(fieldTemplate.getDisplayerName()) && StringUtil.isDefined(field.getValue())) { boolean fromCompoVersion = "yes".equals(getOrganizationController() .getComponentParameterValue(componentId, "versionControl")); //Versioning Used if (fromCompoVersion) { DocumentVersion documentVersion = versioningUtil .getDocumentVersion(new DocumentVersionPK(Integer.parseInt(field.getValue()))); if (documentVersion != null) { fieldValue = documentVersion.getLogicalName(); } } else { AttachmentDetail attDetail = AttachmentController .searchAttachmentByPK(new AttachmentPK(field.getValue(), componentId)); if (attDetail != null) { fieldValue = attDetail.getLogicalName(getLanguage()); } } } //Field date type else if (fieldTemplate.getTypeName().equals("date")) { fieldValue = DateUtil.getOutputDate(fieldValue, "fr"); } //Others fields type else { fieldTemplate.setDisplayerName("simpletext"); fieldValue = field.getValue(getLanguage()); } cell = new PdfPCell(new Phrase(fieldLabel, fontLabel)); cell.setBorderWidth(0); cell.setPaddingBottom(5); tableContent.addCell(cell); cell = new PdfPCell(new Phrase(fieldValue, fontValue)); cell.setBorderWidth(0); cell.setPaddingBottom(5); tableContent.addCell(cell); } document.add(tableContent); } } catch (Exception e) { SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e); } }