List of usage examples for com.lowagie.text.pdf PdfPCell setGrayFill
public void setGrayFill(float value)
From source file:com.senacor.wbs.web.project.ProjectListPanel.java
License:Apache License
public ProjectListPanel(final String id, final List<Project> projects) { super(id);/*from www . ja v a2 s.co m*/ 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:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPCell buildBodyNumberCell(int value, boolean even, boolean first, boolean last) { PdfPCell cell = new PdfPCell(new Phrase(String.valueOf(value))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); if (even) {// w w w . j a va 2s.co m cell.setGrayFill(0.8f); } setBorder(cell, first, last); // cell.setRotation(rotation); return cell; }
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPCell buildBodyTextCell(String value, boolean even, boolean first, boolean last) { PdfPCell cell = new PdfPCell(new Phrase(value)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); if (even) {/*from w w w . j a v a2s . c om*/ cell.setGrayFill(0.8f); } setBorder(cell, first, last); // cell.setRotation(rotation); return cell; }
From source file:domain.reports.menu.PDFReportMenu.java
License:LGPL
/** * Return a report section formatted as a table * @param data// w w w. j ava2s. c om * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(2); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 50, 50 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(70); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("ITEMS DEL MEN", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(2); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Item del men", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Servicio", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("description"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); v = detail.getString("path"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:domain.reports.role.PDFReportRole.java
License:LGPL
/** * Return a report section formatted as a table * @param data//from w w w. j a va 2s .com * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(4); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 20, 20, 20, 20 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(100); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("USUARIOS DEL ROL", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(4); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Login de Usuario", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Apellido", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Nombre", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Email", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("userlogin"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("lname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("fname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("email"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:jm.web.Addons.java
License:GNU General Public License
public static PdfPCell setBarra(int colSpan, float color) { PdfPCell celda = new PdfPCell(new Paragraph(" ", new Font(Font.HELVETICA, 1, Font.NORMAL))); celda.setGrayFill(color); celda.setBorderWidth(0);/*from www . j a va2 s .c om*/ celda.setPadding(0); celda.setColspan(colSpan); return celda; }
From source file:mitm.common.pdf.MessagePDFBuilder.java
License:Open Source License
private void addBodyAndAttachments(PdfWriter pdfWriter, Document document, PdfPTable bodyTable, String body, Collection<Part> attachments) throws DocumentException, MessagingException, IOException { /*//from w w w . ja v a 2 s . c o m * Font for anchors (links) */ Font linkFont = createLinkFont(); FontSelector bodyFontSelector = createBodyFontSelector(); PdfPCell bodyCell = new PdfPCell(); /* * Body table will be white */ bodyCell.setGrayFill(1f); bodyCell.setPadding(10); Phrase bodyPhrase = new Phrase(); bodyCell.setPhrase(bodyPhrase); /* * Matcher we need to convert links to clickable links */ Matcher urlMatcher = urlPattern.matcher(body); String textPart; int currentIndex = 0; /* * Add body and links */ while (urlMatcher.find()) { textPart = body.substring(currentIndex, urlMatcher.start()); addTextPart(textPart, bodyPhrase, bodyFontSelector); String linkPart = urlMatcher.group(); if (linkPart != null) { addLinkPart(linkPart, bodyPhrase, linkFont); currentIndex = urlMatcher.start() + linkPart.length(); } } textPart = body.substring(currentIndex); addTextPart(textPart, bodyPhrase, bodyFontSelector); bodyTable.addCell(bodyCell); document.add(bodyTable); addAttachments(pdfWriter, attachments); }
From source file:net.bull.javamelody.internal.web.pdf.PdfAbstractTableReport.java
License:Apache License
void initTable(List<String> headers, int[] relativeWidths) throws DocumentException { assert headers.size() == relativeWidths.length; final PdfPTable mytable = new PdfPTable(headers.size()); mytable.setWidthPercentage(100);/*from www. j a v a 2 s . c om*/ mytable.setWidths(relativeWidths); mytable.setHeaderRows(1); final PdfPCell defaultCell = mytable.getDefaultCell(); defaultCell.setGrayFill(0.9f); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); defaultCell.setPaddingLeft(0); defaultCell.setPaddingRight(0); final Font tableHeaderFont = PdfFonts.TABLE_HEADER.getFont(); for (final String header : headers) { mytable.addCell(new Phrase(header, tableHeaderFont)); } defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); this.table = mytable; }
From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java
License:Apache License
private void writeRequests(List<CounterRequestContext> contexts) throws DocumentException, IOException { final PdfPCell defaultCell = getDefaultCell(); final PdfPCell requestCell = new PdfPCell(); final Paragraph phrase = new Paragraph("", cellFont); int margin = 0; for (final CounterRequestContext context : contexts) { writeRequest(context, requestCell, margin); margin += 5;//from ww w . j av a 2 s . c o m } // on utilise ici PdfPCell et addElement pour que les proprits // leading et indentationLeft des paragraphes soient prises en compte requestCell.addElement(phrase); requestCell.setGrayFill(defaultCell.getGrayFill()); requestCell.setPaddingTop(defaultCell.getPaddingTop()); addCell(requestCell); }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeRequest(CounterRequest childRequest, float executionsByRequest, boolean allChildHitsDisplayed) throws IOException, DocumentException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize()); if (executionsByRequest != -1) { paragraph.setIndentationLeft(5); }//from w w w . j ava 2 s .c om final Counter parentCounter = getCounterByRequestId(childRequest); if (parentCounter != null && parentCounter.getIconName() != null) { paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1)); } paragraph.add(new Phrase(childRequest.getName(), cellFont)); final PdfPCell requestCell = new PdfPCell(); requestCell.addElement(paragraph); requestCell.setGrayFill(defaultCell.getGrayFill()); requestCell.setPaddingTop(defaultCell.getPaddingTop()); addCell(requestCell); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); if (executionsByRequest != -1) { addCell(nbExecutionsFormat.format(executionsByRequest)); } else { addCell(""); } writeRequestValues(childRequest, allChildHitsDisplayed); }