List of usage examples for com.itextpdf.text.pdf PdfPTable setWidths
public void setWidths(final int relativeWidths[]) throws DocumentException
From source file:bd.gov.forms.web.FormBuilder.java
License:Open Source License
@RequestMapping(value = "/individualpdf", method = RequestMethod.GET) public String individualpdf(@RequestParam(value = "formId", required = true) String formId, @RequestParam(value = "entryId", required = true) String entryId, ModelMap model, HttpServletResponse response) throws IOException { byte[] fileContent = formDao.getTemplateContent(formId); Form form = formDao.getFormWithFields(formId); form.setEntryId(entryId);//from www . j a v a2s . c o m form = formDao.getEntry(form); String report = ""; Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (fileContent != null) { report = new String(fileContent, "UTF8"); for (Field field : form.getFields()) { if (fieldTypeIsNotOfFileOrNoteOrSection(field)) { report = report.replaceAll("#" + field.getColName() + ":label#", field.getLabel()); report = report.replaceAll("#" + field.getColName() + ":value#", field.getStrVal()); } } } else { // step 2 try { response.reset(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline; filename=test.pdf"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "No-cache"); PdfWriter writer = PdfWriter.getInstance(document, baos); // step 3 document.open(); PdfPCell space; space = new PdfPCell(); space.setBorder(Rectangle.NO_BORDER); space.setColspan(2); space.setFixedHeight(8); PdfPTable table = new PdfPTable(2); PdfPCell cell; report += "<table cellspacing='0' cellpadding='0' style='border:1px solid #aaa;width:98%;'>"; for (Field field : form.getFields()) { if (fieldTypeIsNotOfFileOrNoteOrSection(field)) { report += field.getLabel(); report += field.getStrVal(); table.setWidths(new int[] { 1, 2 }); table.addCell(field.getLabel()); //cell = new PdfPCell(); //cell.setCellEvent(new TextFields(1)); table.addCell(field.getStrVal()); } } document.add(table); document.close(); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (Exception ex) { System.out.println("Could not print reasone::" + ex.toString()); } } return null; }
From source file:bd.gov.forms.web.FormBuilder.java
License:Open Source License
@RequestMapping(value = "/pdfExport", method = RequestMethod.GET) public String pdfExport(@RequestParam(value = "formId", required = true) String formId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "colName", required = false) String colName, @RequestParam(value = "colVal", required = false) String colVal, @RequestParam(value = "sortCol", required = false) String sortCol, @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws IOException { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); // step 2//from w ww.ja v a2s . c o m try { response.reset(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline; filename=test.pdf"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "No-cache"); PdfWriter writer = PdfWriter.getInstance(document, baos); // step 3 document.open(); Form form = null; //System.out.println("The form id is 1:"+formId); if (formId != null) { form = formDao.getFormWithFields(formId); } if (form != null) { if (form.getStatus() != 2) {//2-active, 3-deactive model.put("doneMessage", "msg.access.denied"); model.put("doneMsgType", "failed"); return "redirect:done.htm"; } initForm(form); } List<Field> fieldList = form.getFields(); if (fieldList.isEmpty()) { System.out.println("The list size is zero"); } PdfPCell space; space = new PdfPCell(); space.setBorder(Rectangle.NO_BORDER); space.setColspan(2); space.setFixedHeight(8); PdfPTable table = new PdfPTable(2); PdfPCell cell; //PdfPCell cell; table.setWidths(new int[] { 1, 2 }); int i = 0; for (Field f : fieldList) { if ("text".equals(f.getType())) { table.addCell(f.getLabel()); cell = new PdfPCell(); cell.setCellEvent(new TextFields(1, i)); table.addCell(cell); } else if ("textarea".equals(f.getType())) { table.addCell(f.getLabel()); cell = new PdfPCell(); cell.setCellEvent(new TextFields(1, i)); cell.setFixedHeight(60); table.addCell(cell); } else if ("select".equals(f.getType())) { table.addCell(f.getType()); cell = new PdfPCell(); cell.setCellEvent(new ChoiceFields(3, f.getList().toArray())); table.addCell(cell); //table.addCell(space); System.out.println("ajsdhd"); } i++; } /* for(Field f : fieldList) { if( "radio".equals(f.getType()) ) { System.out.println("List "+f.getList()+" Oppt"+f.getOptions()+ " df"+f.getColName()); writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldForm.pdf")); //writer.addJavaScript(Utilities.readFileToString("")); // add the radio buttons PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(FontFamily.HELVETICA, 14); Rectangle rect; PdfFormField field; PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true); radiogroup.setFieldName("language"); RadioCheckField radio; for (int i = 0; i < 2; i++) { rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40); radio = new RadioCheckField(writer, rect, null, f.getLabel()); radio.setBorderColor(GrayColor.GRAYBLACK); radio.setBackgroundColor(GrayColor.GRAYWHITE); radio.setCheckType(RadioCheckField.TYPE_CIRCLE); field = radio.getRadioField(); radiogroup.addKid(field); writer.addAnnotation(field); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(f.getLabel(), font), 70, 790 - i * 40, 0); } //table.addCell(f.getLabel()); //cell = new PdfPCell(); //document.add(radiogroup); //writer.addAnnotation(radiogroup); } } */ // Add submit button PushbuttonField submitBtn = new PushbuttonField(writer, new Rectangle(400, 700, 370, 670), "submitPOST"); //submitBtn.setBackgroundColor(Color.GRAY); submitBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); submitBtn.setText("Submit"); submitBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); PdfFormField submitField = submitBtn.getField(); submitField.setAction( PdfAction.createSubmitForm("http://localhost:8084/GovForm-07-02/formBuilder/pdfresponse.htm", null, PdfAction.SUBMIT_HTML_FORMAT)); writer.addAnnotation(submitField); document.add(table); System.out.println("Pdf creation successful"); document.close(); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (Exception ex) { System.out.println("Could not print reasone::" + ex.toString()); } //////////////////////////////////////// email part//////////////////////////// //email functionalities // Recipient's email ID needs to be mentioned. String to = "tanviranik@gmail.com"; // Sender's email ID needs to be mentioned String from = "tanvir_cse@yahoo.com"; // Assuming you are sending email from localhost String host = "localhost"; // Get system properties Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", host); // Get the default Session object. Session session = Session.getDefaultInstance(properties); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set Subject: header field message.setSubject("This is the Subject Line!"); // Now set the actual message message.setText("This is actual message"); // Send message Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException mex) { mex.printStackTrace(); } //////////////////////////////////////// email part//////////////////////////// return null; }
From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java
License:Open Source License
@Override protected void buildTable(Document document) throws DocumentException { //large table to take care of the layout PdfPTable largeTable = new PdfPTable(3); largeTable.setWidths(new int[] { 19, 1, 20 }); final float largeTableHeight = configuration.getSquareCellSize() * (getNumberOfRows() + 1); PdfPCell cell1 = getEmptyCell();/*from w ww.j a va 2 s .c o m*/ cell1.setFixedHeight(largeTableHeight); cell1.addElement(getNameTable()); largeTable.addCell(cell1); PdfPCell cellSpacer = getEmptyCell(); cellSpacer.setFixedHeight(largeTableHeight); largeTable.addCell(cellSpacer); PdfPCell cell2 = getEmptyCell(); cell2.setFixedHeight(largeTableHeight); cell2.addElement(getScoreTable()); largeTable.addCell(cell2); document.add(largeTable); }
From source file:be.rheynaerde.poolsheets.ClubPoolSheet.java
License:Open Source License
@Override protected void buildTable(Document document) throws DocumentException { int columnCount = configuration.getNrOfPlayers() + configuration.getSummaryColumnCount() + 3; int nameCellWidth = 5; PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth(//from w w w .j a v a2s. c o m (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize()); table.setLockedWidth(true); float[] widths = new float[columnCount]; widths[0] = 1f * nameCellWidth; for (int i = 1; i < widths.length; i++) { widths[i] = 1f; } widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f; table.setWidths(widths); PdfPCell cell = new PdfPCell(new Paragraph(configuration.getTitle(), configuration.getTitleFont())); cell.setColspan(columnCount); cell.setPaddingBottom(configuration.getSquareCellSize() / 2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); { table.addCell(getHeaderCell(bundle.getString("name"))); table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } table.addCell(new PdfPCell()); //spacer column for (int i = 0; i < configuration.getSummaryColumnCount(); i++) { table.addCell(getHeaderCell(configuration.getSummaryColumnName(i))); } } for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < i; j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result)); resultCell.setHorizontalAlignment(Element.ALIGN_CENTER); resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(resultCell); } table.addCell(getSolidCell()); for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result)); resultCell.setHorizontalAlignment(Element.ALIGN_CENTER); resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(resultCell); } table.addCell(new PdfPCell()); //spacer column for (int j = 0; j < configuration.getSummaryColumnCount(); j++) { String result = configuration.getSummaryColumnValue(i + 1, j); PdfPCell summaryCell = new PdfPCell(new Phrase(result == null ? "" : result)); summaryCell.setHorizontalAlignment(Element.ALIGN_CENTER); summaryCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(summaryCell); } } document.add(table); }
From source file:be.rheynaerde.poolsheets.PufCompletePoolSheet.java
License:Open Source License
@Override protected PdfPTable getScoreTable() throws DocumentException { final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2; //one column for each player, an extra column for the numbers and a column for the team marks PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);/*from w w w.jav a 2 s . c o m*/ float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1))); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2))); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1)); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { if (i == configuration.getNrOfPlayers(1)) table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); j++) { if (i == j) { PdfPCell blackCell = getSolidCell(); table.addCell(blackCell); } else { table.addCell(configuration.getResult(i, j)); } } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:be.rheynaerde.poolsheets.PufSingleTeamPoolSheet.java
License:Open Source License
@Override protected PdfPTable getScoreTable() throws DocumentException { final int columnCount = configuration.getNrOfPlayers() + 2; PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);/*from w w w . j a va 2s. co m*/ float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers())); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(), 1)); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(); j++) { if (i == j) { PdfPCell blackCell = getSolidCell(); table.addCell(blackCell); } else { table.addCell(configuration.getResult(i, j)); } } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:be.rheynaerde.poolsheets.PufTeamPoolSheet.java
License:Open Source License
protected PdfPTable getScoreTable() throws DocumentException { //table for scores final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2; //one column for each player, an extra column for the numbers and a column for the team marks PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);//from ww w . ja va 2 s .c om float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1))); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2))); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1)); for (int i = 0; i < configuration.getNrOfPlayers(1); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); if (i == 0) { PdfPCell blackCell = getSolidCell(); blackCell.setColspan(configuration.getNrOfPlayers(1)); blackCell.setRowspan(configuration.getNrOfPlayers(1)); table.addCell(blackCell); } for (int j = 0; j < configuration.getNrOfPlayers(2); j++) { table.addCell(configuration.getResult(0, i, 1, j)); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1)); for (int i = 0; i < configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(configuration.getNrOfPlayers(1) + i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(1); j++) { table.addCell(configuration.getResult(1, i, 0, j)); } if (i == 0) { PdfPCell blackCell = getSolidCell(); blackCell.setColspan(configuration.getNrOfPlayers(2)); blackCell.setRowspan(configuration.getNrOfPlayers(2)); table.addCell(blackCell); } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:be.rheynaerde.poolsheets.StandardPoolSheet.java
License:Open Source License
protected void buildTable(Document document) throws DocumentException { int columnCount = 1 + 1 + configuration.getNrOfPlayers() + 1 + configuration.getSummaryColumnCount(); // name + number + scores + spacer // + summary PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((configuration.getNrOfPlayers() + 7 //the name column + extra space between grid and summary //currently the name column just gets a width that is //a multiple of the width of the other cells. Better //would be to let this cell take up the remaining space. + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize()); table.setLockedWidth(true);//from w w w . jav a2s. c o m float[] widths = new float[columnCount]; widths[0] = 5f; for (int i = 1; i < widths.length; i++) { widths[i] = 1f; } widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f; table.setWidths(widths); { table.addCell(getHeaderCell(bundle.getString("name"))); table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } table.addCell(new PdfPCell()); //spacer column for (int i = 0; i < configuration.getSummaryColumnCount(); i++) { table.addCell(getHeaderCell(configuration.getSummaryColumnName(i))); } } for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < i; j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.addCell(getSolidCell()); for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.addCell(new PdfPCell()); //spacer column for (int j = 0; j < configuration.getSummaryColumnCount(); j++) { String result = configuration.getSummaryColumnValue(i + 1, j); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } } document.add(table); }
From source file:beans.ManagedBeanReportes.java
public void inventario() throws DocumentException, IOException { FacesContext facexcontext = FacesContext.getCurrentInstance(); ValueExpression vex = facexcontext.getApplication().getExpressionFactory() .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class); ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext()); FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft, int marginRight, int marginTop, int marginBottom ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new ManagedBeanReportes.Watermark("")); if (!document.isOpen()) { document.open();//from w w w .j a v a 2 s . c o m } try { ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext(); //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png"); //Image welladigital = Image.getInstance(imageUrl1); //welladigital.setAbsolutePosition(377f, 760f); //welladigital.scalePercent(40); //document.add(welladigital); //crear tabla PARA NOMBRE DEL AO PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.setTotalWidth(450f); // table.setTotalWidth(540f); table.setLockedWidth(true); float[] headerWidths = { 120, 20, 310 }; table.setWidths(headerWidths); table.getDefaultCell(); SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY"); StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio)); Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12); underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location PdfPCell table5 = new PdfPCell(new Paragraph(underline)); table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER); table5.setColspan(3); table5.setBorder(Rectangle.NO_BORDER); table.addCell(table5); document.add(table); document.add(new Paragraph("\n", pequeFont)); PdfPCell table2 = new PdfPCell(); table2 = new PdfPCell( new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont)); table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER); table2.setColspan(3); table2.setBorder(Rectangle.NO_BORDER); table = new PdfPTable(3); table.setWidthPercentage(100); table.setTotalWidth(450f); table.setLockedWidth(true); table.setWidths(headerWidths); table.getDefaultCell(); table.addCell(table2); document.add(table); document.add(new Paragraph("\n", pequeFont)); document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda())); formato = new SimpleDateFormat("yyyy-MM-dd"); cadena = new StringBuilder(formato.format(fecha_inicio)); //document.add(traerSubtabla02(cadena.toString())); document.add(new Paragraph("\n", pequeFont)); ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext(); String ctxPath = ((ServletContext) ctx.getContext()).getContextPath(); document.close(); formato = new SimpleDateFormat("dd_MM_yyyy"); cadena = new StringBuilder(formato.format(fecha_inicio)); String fileName = cadena.toString(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception de) { de.printStackTrace(); } }
From source file:beans.ManagedBeanReportes.java
public PdfPTable traerSubtabla(Tienda t) throws DocumentException { PdfPTable tabla_PesajeDetalle = new PdfPTable(4); tabla_PesajeDetalle.setWidthPercentage(100); tabla_PesajeDetalle.setTotalWidth(450f); tabla_PesajeDetalle.setLockedWidth(true); tabla_PesajeDetalle.setWidths(anchocol03); tabla_PesajeDetalle.getDefaultCell(); PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont)); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont)); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont)); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont)); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); tabla_PesajeDetalle.addCell(Cell_Headers); for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) { tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto())); String ubicaciones_ = ""; for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t, det.getProducto())) {//from w w w .j a v a 2 s. c om if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) { ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_; } } tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_)); tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock()))); tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad()))); } return tabla_PesajeDetalle; }