List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell
public PdfPCell getDefaultCell()
PdfPCell
that will be used as reference for all the addCell
methods except addCell(PdfPCell)
. From source file:nwk.com.br.documents.ProdutoMaisVendidoPdf.java
private PdfPTable getProduto() throws Exception { PdfPTable produtoMaisVendido = new PdfPTable(new float[] { 0.1f/*id*/, 0.65f/*nome*/, 0.25f/*soma*/ }); produtoMaisVendido.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento produtoMaisVendido.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); produtoMaisVendido.getDefaultCell().setBorder(0); //Adiciona os nomes das colunas PdfPCell codProduto = new PdfPCell(new Paragraph("Cod")); PdfPCell descProduto = new PdfPCell(new Paragraph("Descrio")); PdfPCell qtdProduto = new PdfPCell(new Paragraph("Quantidade")); produtoMaisVendido.addCell(codProduto); produtoMaisVendido.addCell(descProduto); produtoMaisVendido.addCell(qtdProduto); //Adiciona as informaes do cliente na tabela int qtdCli = 0; for (Produto produto : produtodao.getProdutoeMaisVendido()) { produtoMaisVendido.addCell(produto.getId()); produtoMaisVendido.addCell(produto.getDescricao()); produtoMaisVendido.addCell(produto.getQuantidade()); if (qtdCli == 19) { break; } else {//w w w. j av a 2 s . c o m qtdCli++; } } return produtoMaisVendido; }
From source file:org.cejug.yougi.web.report.EventAttendeeReport.java
License:Open Source License
public void printReport(List<Attendee> attendees) throws DocumentException { float[] columnSizes = { 20, 220, 220, 60 }; PdfPTable table = new PdfPTable(columnSizes.length); table.setLockedWidth(true);// w ww .ja v a 2 s. c o m table.setTotalWidth(columnSizes); PdfPCell headerCell = new PdfPCell(new Phrase("Yougi")); headerCell.setColspan(4); headerCell.setBackgroundColor(BaseColor.ORANGE); headerCell.setPadding(3); table.addCell(headerCell); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); PdfPCell checkCell = new PdfPCell(new Phrase(" ")); checkCell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(checkCell); PdfPCell productCell = new PdfPCell(new Phrase("Nome")); productCell.setBackgroundColor(BaseColor.LIGHT_GRAY); productCell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(productCell); PdfPCell currentPurchaseCell = new PdfPCell(new Phrase("Email")); currentPurchaseCell.setPadding(3); currentPurchaseCell.setHorizontalAlignment(Element.ALIGN_CENTER); currentPurchaseCell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(currentPurchaseCell); PdfPCell previousPurchaseCell = new PdfPCell(new Phrase("Presente")); previousPurchaseCell.setPadding(3); previousPurchaseCell.setHorizontalAlignment(Element.ALIGN_CENTER); previousPurchaseCell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(previousPurchaseCell); table.getDefaultCell().setBackgroundColor(null); table.setHeaderRows(2); Font font = new Font(Font.FontFamily.HELVETICA, 9); int seq = 1; for (Attendee attendee : attendees) { table.addCell(new Phrase(String.valueOf(seq++), font)); table.addCell(new Phrase(attendee.getUserAccount().getFullName(), font)); table.addCell(new Phrase(attendee.getUserAccount().getEmail(), font)); table.addCell(" "); } document.add(table); }
From source file:org.com.controller.ProductController.java
@RequestMapping(value = "/repProduct", method = RequestMethod.GET) public void productReport(Model m, HttpServletResponse response, HttpServletRequest request, OutputStream outputStream) throws Exception { String name = "ProductReport-"; Date d = new Date(); name = name + d.toString() + ".pdf"; response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=" + name); Rectangle pagesize = new Rectangle(216f, 720f); Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, outputStream); document.open();//from w w w. j a va 2 s . c om document.addTitle("PRODUCT DETAILSA REPORT"); document.add(new Paragraph("PRODUCT DETAILSA REPORT ", FontFactory.getFont(FontFactory.HELVETICA, 28, BaseColor.CYAN))); document.add(new Paragraph("DATE: " + new Date())); document.add(new Paragraph("-------------------------------------------------------- ")); document.add(new Paragraph(" ")); ProductDaoImpl pdi = new ProductDaoImpl(); PdfPTable table = new PdfPTable(4); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell("ID"); table.addCell("TITLE"); table.addCell("PUBLISHER"); table.addCell("PRICE"); ArrayList<ProductTable> list = pdi.getAllProduct(); for (ProductTable u : list) { table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(u.getPid().toString()); table.getDefaultCell().setBackgroundColor(BaseColor.GRAY); table.addCell(u.getPname()); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(u.getPublisher()); table.getDefaultCell().setBackgroundColor(BaseColor.GRAY); table.addCell(u.getSprice().toString()); } document.add(table); document.close(); }
From source file:org.fossa.rolp.util.LebPageHelper.java
License:Open Source License
@Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(527);//from w ww . j a v a 2 s.c o m table.setWidthPercentage(100); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(105f); table.getDefaultCell().setBorderWidth(0); table.addCell(""); table.addCell(csmLogoImage); table.writeSelectedRows(0, -1, 100, 840, writer.getDirectContent()); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase( lebData.getSchuelername() + " " + lebData.getSchuljahr() + " " + lebData.getSchulhalbjahr().getId() + " Seite " + document.getPageNumber(), fusszeilenFont), 100, 75, 0); }
From source file:org.me.modelos.PDFHelper.java
public void tablaToPdf(JTable jTable, File pdfNewFile, String title) { try {// w w w. jav a2 s . co m Font subCategoryFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); Document document = new Document(PageSize.LETTER.rotate()); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile)); } catch (FileNotFoundException fileNotFoundException) { Message.showErrorMessage(fileNotFoundException.getMessage()); } writer.setBoxSize("art", new Rectangle(150, 10, 700, 580)); writer.setPageEvent(new HeaderFooterPageEvent()); document.open(); document.addTitle(title); document.addSubject("Reporte"); document.addKeywords("reportes, gestion, pdf"); document.addAuthor("Gestion de Proyectos de software"); document.addCreator("gestion de proyectos"); Paragraph parrafo = new Paragraph(title, subCategoryFont); PdfPTable table = new PdfPTable(jTable.getColumnCount()); table.setWidthPercentage(100); PdfPCell columnHeader; for (int column = 0; column < jTable.getColumnCount(); column++) { Font font = new Font(Font.FontFamily.HELVETICA); font.setColor(255, 255, 255); columnHeader = new PdfPCell(new Phrase(jTable.getColumnName(column), font)); columnHeader.setHorizontalAlignment(Element.ALIGN_LEFT); columnHeader.setBackgroundColor(new BaseColor(96, 125, 139)); table.addCell(columnHeader); } table.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); table.setHeaderRows(1); BaseColor verdad = new BaseColor(255, 255, 255); BaseColor falso = new BaseColor(214, 230, 244); boolean bandera = false; for (int row = 0; row < jTable.getRowCount(); row++) { for (int column = 0; column < jTable.getColumnCount(); column++) { if (bandera) { table.getDefaultCell().setBackgroundColor(verdad); } else { table.getDefaultCell().setBackgroundColor(falso); } table.addCell(jTable.getValueAt(row, column).toString()); bandera = !bandera; } } parrafo.add(table); document.add(parrafo); document.close(); //JOptionPane.showMessageDialog(null, "Se ha creado el pdf en " + pdfNewFile.getPath(), // "RESULTADO", JOptionPane.INFORMATION_MESSAGE); } catch (DocumentException documentException) { System.out.println("Se ha producido un error " + documentException); JOptionPane.showMessageDialog(null, "Se ha producido un error" + documentException, "ERROR", JOptionPane.ERROR_MESSAGE); } }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareTable(List<? extends Column> visibleColumns) throws DocumentException { java.util.List<Integer> widths = new ArrayList<>(); for (Column column : visibleColumns) { widths.add(column.getColumnWidth()); }/* w ww .ja v a 2 s. co m*/ PdfPTable table = new PdfPTable(widths.size()); table.setWidths(ArrayUtils.toPrimitive(widths.toArray(new Integer[widths.size()]))); table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(CELL_PADDING); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(2); table.setFooterRows(1); setTableHeader(table, visibleColumns); setBlankFooter(table, visibleColumns.size()); return table; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private void insertCell(PdfPTable table, String text, int colSpan) { Chunk chunk;/*from w w w.j a v a 2 s . c o m*/ chunk = new Chunk(text); PdfPCell cell = table.getDefaultCell(); cell.setPhrase(new Phrase(chunk)); cell.setColspan(colSpan); table.addCell(cell); }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareRequisitionHeaderTable() throws DocumentException { int[] columnWidths = { 160, 160, 160, 160, 160 }; PdfPTable table = new PdfPTable(columnWidths.length); table.setWidths(columnWidths);//from www .j a va 2 s . c o m table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(10); table.getDefaultCell().setBorder(0); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(1); return table; }
From source file:org.smap.sdal.managers.MiscPDFManager.java
License:Open Source License
public void createUsagePdf(Connection sd, OutputStream outputStream, String basePath, HttpServletResponse response, int o_id, int month, int year, String period, String org_name) { PreparedStatement pstmt = null; if (org_name == null) { org_name = "None"; }/* w w w. ja v a2 s.c o m*/ try { String filename; // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/Library/Fonts/NotoSans-Regular.ttf", "notosans"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "default"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("default", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); filename = org_name + "_" + year + "_" + month + ".pdf"; /* * Get the usage results */ String sql = "SELECT users.id as id," + "users.ident as ident, " + "users.name as name, " + "(select count (*) from upload_event ue, subscriber_event se " + "where ue.ue_id = se.ue_id " + "and se.status = 'success' " + "and se.subscriber = 'results_db' " + "and extract(month from upload_time) = ? " // current month + "and extract(year from upload_time) = ? " // current year + "and ue.user_name = users.ident) as month, " + "(select count (*) from upload_event ue, subscriber_event se " + "where ue.ue_id = se.ue_id " + "and se.status = 'success' " + "and se.subscriber = 'results_db' " + "and ue.user_name = users.ident) as all_time " + "from users " + "where users.o_id = ? " + "and not users.temporary " + "order by users.ident;"; pstmt = sd.prepareStatement(sql); pstmt.setInt(1, month); pstmt.setInt(2, year); pstmt.setInt(3, o_id); log.info("Get Usage Data: " + pstmt.toString()); // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); setFilenameInResponse(filename, response); } /* * Get a template for the PDF report if it exists * The template name will be the same as the XLS form name but with an extension of pdf */ String stationaryName = basePath + File.separator + "misc" + File.separator + "UsageReportTemplate.pdf"; File stationaryFile = new File(stationaryName); ByteArrayOutputStream baos = null; ByteArrayOutputStream baos_s = null; PdfWriter writer = null; /* * Create document in two passes, the second pass adds the letter head */ // Create the underlying document as a byte array Document document = new Document(PageSize.A4); document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); if (stationaryFile.exists()) { baos = new ByteArrayOutputStream(); baos_s = new ByteArrayOutputStream(); writer = PdfWriter.getInstance(document, baos); } else { writer = PdfWriter.getInstance(document, outputStream); } writer.setInitialLeading(12); writer.setPageEvent(new PageSizer()); document.open(); // Write the usage data ResultSet resultSet = pstmt.executeQuery(); PdfPTable table = new PdfPTable(4); // Add the header row table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setBackgroundColor(VLG); table.addCell("User Id"); table.addCell("User Name"); table.addCell("Usage in Period"); table.addCell("All Time Usage"); table.setHeaderRows(1); // Add the user data int total = 0; int totalAllTime = 0; table.getDefaultCell().setBackgroundColor(null); while (resultSet.next()) { String ident = resultSet.getString("ident"); String name = resultSet.getString("name"); String monthUsage = resultSet.getString("month"); int monthUsageInt = resultSet.getInt("month"); String allTime = resultSet.getString("all_time"); int allTimeInt = resultSet.getInt("all_time"); table.addCell(ident); table.addCell(name); table.addCell(monthUsage); table.addCell(allTime); total += monthUsageInt; totalAllTime += allTimeInt; } // Add the totals table.getDefaultCell().setBackgroundColor(VLG); table.addCell("Totals: "); table.addCell(" "); table.addCell(String.valueOf(total)); table.addCell(String.valueOf(totalAllTime)); document.add(table); document.close(); if (stationaryFile.exists()) { // Step 2 - Populate the fields in the stationary PdfReader s_reader = new PdfReader(stationaryName); PdfStamper s_stamper = new PdfStamper(s_reader, baos_s); AcroFields pdfForm = s_stamper.getAcroFields(); Set<String> fields = pdfForm.getFields().keySet(); for (String key : fields) { log.info("Field: " + key); } pdfForm.setField("billing_period", period); pdfForm.setField("organisation", org_name); s_stamper.setFormFlattening(true); s_stamper.close(); // Step 3 - Apply the stationary to the underlying document PdfReader reader = new PdfReader(baos.toByteArray()); // Underlying document PdfReader f_reader = new PdfReader(baos_s.toByteArray()); // Filled in stationary PdfStamper stamper = new PdfStamper(reader, outputStream); PdfImportedPage letter1 = stamper.getImportedPage(f_reader, 1); int n = reader.getNumberOfPages(); PdfContentByte background; for (int i = 0; i < n; i++) { background = stamper.getUnderContent(i + 1); if (i == 0) { background.addTemplate(letter1, 0, 0); } } stamper.close(); reader.close(); } } catch (SQLException e) { log.log(Level.SEVERE, "SQL Error", e); } catch (Exception e) { log.log(Level.SEVERE, "Exception", e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (SQLException e) { } } }
From source file:org.smap.sdal.managers.MiscPDFManager.java
License:Open Source License
public void createTasksPdf(Connection sd, OutputStream outputStream, String basePath, HttpServletRequest request, HttpServletResponse response, int tgId) { try {// w w w. ja v a 2 s . c o m // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "default"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("default", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); /* * Get the tasks for this task group */ String urlprefix = request.getScheme() + "://" + request.getServerName(); TaskManager tm = new TaskManager(localisation, tz); TaskListGeoJson t = tm.getTasks(sd, urlprefix, 0, tgId, 0, false, 0, null, "all", 0, 0, "scheduled", "desc"); PdfWriter writer = null; String filename = "tasks.pdf"; // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); setFilenameInResponse(filename, response); } Document document = new Document(PageSize.A4); document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); writer = PdfWriter.getInstance(document, outputStream); writer.setInitialLeading(12); writer.setPageEvent(new PageSizer()); document.open(); PdfPTable table = new PdfPTable(4); // Add the header row table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setBackgroundColor(VLG); table.addCell("Form Name"); table.addCell("Task Name"); table.addCell("Status"); table.addCell("Assigned To"); table.setHeaderRows(1); // Add the task data table.getDefaultCell().setBackgroundColor(null); for (TaskFeature tf : t.features) { TaskProperties p = tf.properties; table.addCell(p.survey_name); table.addCell(p.name); table.addCell(p.status); table.addCell(p.assignee_name); } document.add(table); document.close(); } catch (SQLException e) { log.log(Level.SEVERE, "SQL Error", e); } catch (Exception e) { log.log(Level.SEVERE, "Exception", e); } }