List of usage examples for com.itextpdf.text.pdf PdfPCell setBackgroundColor
public void setBackgroundColor(final BaseColor backgroundColor)
From source file:Integral.PDF.java
/** * crea una celda con texto adentro para una tabla * @param texto Texto que se va a incluir en la celda * @param font Fuente para el texto/* w w w . ja v a 2s .co m*/ * @param color color del texto * @param alineacion alineacion del texto respecto a la celda * @param expandirCol expandir la celda x columnas ej:3 junta la celda y 2 mas a la derecha * @param expandirRow Expandir la celda x renglones ej: 3 junta la celda y 2 mas hacia abajo * @param borde tipo de borde de la celda * @return */ public PdfPCell celda(String texto, Font font, BaseColor color, int alineacion, int expandirCol, int expandirRow, int borde) { try { PdfPCell c1 = new PdfPCell(new Paragraph(new Chunk(texto, font))); c1.setColspan(expandirCol); c1.setRowspan(expandirRow); c1.setBackgroundColor(color); c1.setHorizontalAlignment(alineacion); c1.setBorder(borde); return c1; } catch (Exception e) { System.out.println(e); return null; } }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = (float) Units.PT.setYPixels((int) rect.getHeight()); float w = (float) Units.PT.setXPixels((int) rect.getWidth()); PdfPCell pdfCell; if (srcCell.getPicture() != null) { Icon icon = srcCell.getPicture().getIcon(); java.awt.Image awtImage = ((ImageIcon) icon).getImage(); com.itextpdf.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else {//from w ww .j a v a2 s .co m pdfCell = new PdfPCell(); String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.itextpdf.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell.setImage(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (text != null && text.length() > 0) { com.itextpdf.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); } } pdfCell.setFixedHeight(h); pdfCell.setPadding(1); pdfCell.setBackgroundColor(new BaseColor(style.getBackground().getRGB())); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:ManagementPackage.ServiceEnd.java
private void txtDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoneActionPerformed // TODO add your handling code here: Document doc = new Document(); try {// w ww. jav a2s . c o m long time = new Date().getTime(); TransNo = "" + time; PdfWriter.getInstance(doc, new FileOutputStream("Invoices\\Invoices" + time + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(4); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Invoice/Money Receipt\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("Transaction No: " + time, FontFactory.getFont(null, 10))); cell3.setColspan(2); cell3.setPaddingBottom(10); cell3.setPaddingTop(10); cell3.setBorder(2); cell3.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell3); PdfPCell cell4 = new PdfPCell( new Paragraph("Date: " + formatedDateTime, FontFactory.getFont(null, 10))); cell4.setColspan(3); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); //table.addCell("Sl No"); table.addCell("Product Name"); table.addCell("Rate"); table.addCell("Qty"); table.addCell("Amount (TK)"); String query = "select product_name, rate, qty, amount from temp_trans WHERE trans_by = '" + user + "'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { //String sl_no = rs.getString("sl_no"); String product_name = rs.getString("product_name"); String rate = rs.getString("rate"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); //table.addCell(sl_no); table.addCell(product_name); table.addCell(rate); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph(txtTotal.getText())); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph(txtAdjust.getText())); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Billed By: " + user)); celltxtTotalPaid.setColspan(2); //celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid0 = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid0.setColspan(1); celltxtTotalPaid0.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid0); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph(txtTotalPaid.getText())); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); savePermanently(); clearTempTable(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Invoices\\Invoices" + time + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed // TODO add your handling code here: totalAdjustment = 0;/*ww w .ja va 2 s . c o m*/ totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Daily" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Daily Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date = '" + formatedDate + "'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Daily" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed // TODO add your handling code here: totalAdjustment = 0;//from w ww . j a v a 2s. co m totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Monthly" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Monthly Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%" + month + "%'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Monthly" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed // TODO add your handling code here: totalAdjustment = 0;/*ww w . j a v a 2s. c o m*/ totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Yearly" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Yearly Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%" + year + "%'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Yearly" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Measurment_Result_Record.MeasurmentSetup.java
/** * write the given table datas to the given document * @param doc document to write the result tables on * @param table the result table //from w w w . jav a2s. c om * @param m_title the measurment title */ public static void addResultTablesTotheDocument(Document doc, JTable table, String m_title) throws DocumentException { //add the measurment title and table Paragraph measurmenttitle = new Paragraph(m_title + "\n "); measurmenttitle.getFont().setStyle(com.itextpdf.text.Font.BOLD); doc.add(measurmenttitle); int colmWidth = table.getColumnCount(); int rowCount = table.getModel().getRowCount(); PdfPTable resultTable = new PdfPTable(colmWidth); resultTable.setHorizontalAlignment(Element.ALIGN_LEFT); //add the table headers for (int i = 0; i < colmWidth; i++) { String headertext = table.getModel().getColumnName(i); PdfPCell cell = new PdfPCell(new Paragraph(headertext)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); resultTable.addCell(cell); } //add the table body for (int r = 0; r < rowCount; r++) { for (int c = 0; c < colmWidth; c++) { String data = table.getValueAt(r, c).toString(); resultTable.addCell(data); } } resultTable.setSpacingAfter(10); //add the table to the document doc.add(resultTable); }
From source file:model.PDFModel.java
License:Open Source License
public PdfPTable createTablePDFTable(int counter, String raportDate) { JTable resultTable = query.getProductsInTablePDFTable(raportDate, counter); PdfPTable[] tableTable = new PdfPTable[11]; PdfPCell cell, productNameCell, paymentCell, countCell, priceCell; tableTable[counter] = new PdfPTable(4); tableTable[counter].setSpacingBefore(5f); tableTable[counter].setSpacingAfter(5f); totalTablePayment[counter] = 0.00;/*from www .j a v a 2 s . c om*/ if (resultTable != null) { DefaultTableModel resultTableModel = (DefaultTableModel) resultTable.getModel(); if (resultTableModel.getRowCount() > 0) { cell = new PdfPCell(new Phrase("Stolik " + (counter))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 255, 50)); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Produkt")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Ilosc")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Cena jednostkowa")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Zaplata")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); for (int i = 0; i < resultTableModel.getRowCount(); i++) { productNameCell = new PdfPCell(new Phrase(resultTableModel.getValueAt(i, 0).toString(), FontFactory.getFont(FontFactory.defaultEncoding, 10, Font.NORMAL, BaseColor.BLACK))); productNameCell.setHorizontalAlignment(Element.ALIGN_CENTER); productNameCell.setBackgroundColor(new BaseColor(80, 135, 8)); tableTable[counter].addCell(productNameCell); countCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 2)))); countCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTable[counter].addCell(countCell); double payment = Double.parseDouble(resultTableModel.getValueAt(i, 1).toString()) * Double.parseDouble(resultTableModel.getValueAt(i, 2).toString()); totalTablePayment[counter] += payment; paymentCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 1)))); paymentCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTable[counter].addCell(paymentCell); priceCell = new PdfPCell(new Phrase(String.valueOf(payment))); priceCell.setHorizontalAlignment(Element.ALIGN_CENTER); priceCell.setBackgroundColor(new BaseColor(255, 160, 160)); tableTable[counter].addCell(priceCell); } } } if (totalTablePayment[counter] > 0.00) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("SUMA:", FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.NORMAL, BaseColor.BLACK))); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(totalTablePayment[counter]), FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.BOLD, BaseColor.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(255, 50, 50)); tableTable[counter].addCell(cell); } return tableTable[counter]; }
From source file:model.PDFModel.java
License:Open Source License
public PdfPTable createDailyTable(String date) throws DocumentException { PdfPTable dailyTable = new PdfPTable(3); PdfPCell cell; dailyTable.setSpacingBefore(5f);//from ww w.j a va 2s . c o m cell = new PdfPCell(new Phrase("Stolik dnia")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); dailyTable.addCell(cell); cell = new PdfPCell(new Phrase("Potrawa dnia")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); dailyTable.addCell(cell); cell = new PdfPCell(new Phrase("Suma rachunkw")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); dailyTable.addCell(cell); double theBestTableEarnings = 0.00; int theBestTableNumber = 0; for (int i = 1; i < totalTablePayment.length; i++) { if (theBestTableEarnings < totalTablePayment[i]) { theBestTableEarnings = totalTablePayment[i]; theBestTableNumber = i; } } cell = new PdfPCell(new Phrase("Stolik " + String.valueOf(theBestTableNumber))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); dailyTable.addCell(cell); cell = new PdfPCell(new Phrase(query.getDailyBestSellingProduct(date))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); dailyTable.addCell(cell); cell = new PdfPCell(new Phrase(query.getDailyTakings(date))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); dailyTable.addCell(cell); return dailyTable; }
From source file:net.digitstar.vanadio.helpers.PdfHelper.java
License:Apache License
public static PdfPCell newCell(CellStyle style) { PdfPCell cell = new PdfPCell(); if (style != null) { if (style.getNestedTable() != null) { cell = new PdfPCell(style.getNestedTable()); style.setNestedTable(null);/*from w w w.j a v a2s. co m*/ } else if (style.getImage() != null) { cell = new PdfPCell(style.getImage(), style.isFitImage()); style.setImage(null); } else if (style.getText() != null) { cell = new PdfPCell(style.getText()); style.setText((String) null); } cell.setColspan(style.getColspan()); cell.setRowspan(style.getRowspan()); cell.setMinimumHeight(style.getMinimumHeight()); cell.setFixedHeight(style.getFixedHeight()); cell.setNoWrap(style.isNoWrap()); cell.setRotation(style.getRotation().getValue()); style = Alignment.assign(style); cell.setHorizontalAlignment(style.getHorizAlign().getValue()); cell.setVerticalAlignment(style.getVertAlign().getValue()); cell.setUseVariableBorders(style.isUseVariableBorders()); cell.setUseBorderPadding(style.isUseBorderPadding()); if (!style.getBorderWidth().isAllSideEqual()) { cell.setBorderWidthBottom(style.getBorderWidth().getBottom()); cell.setBorderWidthLeft(style.getBorderWidth().getLeft()); cell.setBorderWidthRight(style.getBorderWidth().getRight()); cell.setBorderWidthTop(style.getBorderWidth().getTop()); } else { cell.setBorderWidth(style.getBorderWidth().getValue()); } cell.setPaddingBottom(style.getPadding().getBottom()); cell.setPaddingLeft(style.getPadding().getLeft()); cell.setPaddingRight(style.getPadding().getRight()); cell.setPaddingTop(style.getPadding().getTop()); cell.setBorderColorBottom(style.getBorderColor().getBottom()); cell.setBorderColorLeft(style.getBorderColor().getLeft()); cell.setBorderColorRight(style.getBorderColor().getRight()); cell.setBorderColorTop(style.getBorderColor().getTop()); cell.setBorder(style.getBorder().getValue()); cell.setBackgroundColor(style.getBackgroundColor()); if (style.getGreyFill() >= 0) { cell.setGrayFill(style.getGreyFill()); } } return cell; }