List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:PrefichaPDF.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w . j a v a 2s.c o m response.setContentType("application/pdf"); String curp = new String(request.getParameter("curp").getBytes("ISO-8859-1"), "UTF-8"); ConexionOracle conexionOracle = new ConexionOracle(); String sql = "select * from PERSONALDATA_ASP_TAB where curp=" + "'" + curp + "'"; System.out.println(sql); System.out.println("Esta es la curp: " + curp); conexionOracle.conectar(); Connection conn = conexionOracle.getConnection(); // driver@machineName:port:SID , userid, password Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery(sql); while (rset.next()) { fichabd = rset.getString("id_aspirante"); periodobd = rset.getString("periodo_solicitud"); prefichabd = rset.getString("preficha"); nombrebd = rset.getString("nombre"); String appat = rset.getString("apellido_pat"); String apmat = rset.getString("apellido_mat"); apellidosbd = appat + " " + apmat; curpbd = rset.getString("curp"); carrerabd = rset.getString("carrera"); modalidadbd = rset.getString("modalidad"); } try { Document preficha = new Document(); PdfWriter writer = PdfWriter.getInstance(preficha, response.getOutputStream()); preficha.open(); //encabezado //encabezado //encabezado //encabezado // documento.add(vacio); // documento.add(vacio); // documento.add(vacio); Paragraph depto = new Paragraph("Departamento de servicios escolares", FontFactory.getFont("arial", 20, Font.BOLD)); depto.setAlignment(Element.ALIGN_CENTER); preficha.add(depto); Paragraph vacio = new Paragraph(" ", FontFactory.getFont("arial", 10, Font.BOLD)); vacio.setAlignment(Element.ALIGN_CENTER); preficha.add(vacio); preficha.add(vacio); // preficha.add(vacio); //cuerpo //cuerpo //cuerpo //cuerpo //cuerpo Paragraph periodo_text = new Paragraph("Convocatoria de nuevo ingreso periodo: " + periodobd, FontFactory.getFont("arial", 10, Font.BOLD)); periodo_text.setAlignment(Element.ALIGN_CENTER); preficha.add(periodo_text); preficha.add(vacio); preficha.add(vacio); Paragraph fotografia = new Paragraph("Fotografa", FontFactory.getFont("arial", 10, Font.BOLD)); fotografia.setAlignment(Element.ALIGN_CENTER); preficha.add(fotografia); PdfContentByte rectangulo_general = writer.getDirectContentUnder(); rectangulo_general.rectangle(50, 48, 500, 710); rectangulo_general.fill(); drawRectangleSC(rectangulo_general, 50, 48, 500, 710); PdfContentByte rectangulo_periodo = writer.getDirectContentUnder(); rectangulo_periodo.rectangle(125, 725, 350, 20); rectangulo_periodo.fill(); drawRectangleSC(rectangulo_periodo, 125, 725, 350, 20); String url_logo = "/Imagenes/itt_logo_opt.jpg"; String absolute_url_logo = getServletContext().getRealPath(url_logo); Image itt_logo = Image.getInstance(absolute_url_logo); String url_logo_bnmx = "/Imagenes/bnmx_color_opt.jpg"; String absolute_url_logo_bnmx = getServletContext().getRealPath(url_logo_bnmx); Image bnmx_logo = Image.getInstance(absolute_url_logo_bnmx); Image Logo_itt = Image.getInstance(itt_logo); Logo_itt.setAbsolutePosition(140f, 640f); preficha.add(Logo_itt); Image Logo_banco = Image.getInstance(bnmx_logo); Logo_banco.setAbsolutePosition(380f, 340f); preficha.add(Logo_banco); PdfContentByte espacio_imagen = writer.getDirectContentUnder(); espacio_imagen.rectangle(255, 635, 85, 80); espacio_imagen.fill(); drawRectangleSC(espacio_imagen, 255, 635, 85, 80); // preficha.add(vacio); preficha.add(vacio); PdfContentByte fechaimpr = writer.getDirectContentUnder(); fechaimpr.rectangle(416, 635, 100, 35); fechaimpr.fill(); drawRectangleSC(fechaimpr, 416, 635, 100, 35); // drawRectangle(fechaimpr, 85, 530, 430, 25); Paragraph fechapdf = new Paragraph("\tFecha de impresin ", FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD)); fechapdf.setAlignment(Element.ALIGN_RIGHT); preficha.add(fechapdf); Paragraph fechapdf_fec = new Paragraph("\t" + fecha_hoy() + " ", FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD)); fechapdf_fec.setAlignment(Element.ALIGN_RIGHT); preficha.add(fechapdf_fec); preficha.add(vacio); Paragraph no_preficha = new Paragraph("Preficha N: " + prefichabd, FontFactory.getFont("arial", 20, Font.BOLD)); no_preficha.setAlignment(Element.ALIGN_CENTER); preficha.add(no_preficha); preficha.add(vacio); // preficha.add(vacio); PdfContentByte rectangulo_preficha_no = writer.getDirectContentUnder(); rectangulo_preficha_no.rectangle(85, 590, 430, 25); rectangulo_preficha_no.fill(); drawRectangleSC(rectangulo_preficha_no, 85, 590, 430, 25); PdfContentByte rectangulo_datos = writer.getDirectContentUnder(); rectangulo_datos.rectangle(85, 500, 430, 80); // rectangulo_datos.rec rectangulo_datos.fill(); drawRectangleSC(rectangulo_datos, 85, 500, 430, 80); ////////////////////////////// Paragraph nombre = new Paragraph( " Nombre: " + nombrebd, FontFactory.getFont("arial", 10, Font.BOLD)); nombre.setAlignment(Element.ALIGN_LEFT); preficha.add(nombre); // preficha.add(vacio); Paragraph apellidos = new Paragraph( " " + apellidosbd, FontFactory.getFont("arial", 10, Font.BOLD)); apellidos.setAlignment(Element.ALIGN_LEFT); preficha.add(apellidos); // preficha.add(vacio); Paragraph CURP = new Paragraph( " CURP: " + curpbd, FontFactory.getFont("arial", 10, Font.BOLD)); CURP.setAlignment(Element.ALIGN_LEFT); preficha.add(CURP); // preficha.add(vacio); Paragraph carrera = new Paragraph( " Carrera Solicitada: " + carrerabd, FontFactory.getFont("arial", 10, Font.BOLD)); carrera.setAlignment(Element.ALIGN_LEFT); preficha.add(carrera); // preficha.add(vacio); Paragraph modalidad = new Paragraph( " Modalidad: " + modalidadbd, FontFactory.getFont("arial", 10, Font.BOLD)); modalidad.setAlignment(Element.ALIGN_LEFT); preficha.add(modalidad); preficha.add(vacio); // preficha.add(vacio); Paragraph formatoBanamex = new Paragraph("FORMATO UNIVERSAL PARA DEPSITOS EN SUCURSALES BANAMEX", FontFactory.getFont("arial", 10, Font.BOLD)); formatoBanamex.setAlignment(Element.ALIGN_CENTER); preficha.add(formatoBanamex); PdfContentByte rectanguloDepositoB = writer.getDirectContentUnder(); rectanguloDepositoB.rectangle(85, 470, 430, 20); rectanguloDepositoB.fill(); drawRectangle(rectanguloDepositoB, 85, 470, 430, 20); PdfContentByte rectanguloPago = writer.getDirectContentUnder(); rectanguloPago.rectangle(85, 280, 430, 190); rectanguloPago.fill(); drawRectangleSC(rectanguloPago, 85, 280, 430, 190); preficha.add(vacio); PdfContentByte rectanguloConcepto = writer.getDirectContentUnder(); rectanguloConcepto.rectangle(150, 425, 295, 35); // rectangulo_datos.rec rectanguloConcepto.fill(); drawRectangleSC(rectanguloConcepto, 150, 425, 295, 35); Paragraph formatoConceptoPre = new Paragraph("CONCEPTO: PAGO DE DERECHO A EXAMEN DE ADMISIN", FontFactory.getFont("arial", 10, Font.BOLD)); formatoConceptoPre.setAlignment(Element.ALIGN_CENTER); preficha.add(formatoConceptoPre); Paragraph fechaEmision = new Paragraph("FECHA DE EMISIN: 18/12/2014", FontFactory.getFont("arial", 10, Font.BOLD)); fechaEmision.setAlignment(Element.ALIGN_CENTER); preficha.add(fechaEmision); preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); preficha.add(vacio); Paragraph importe = new Paragraph("IMPORTE A PAGAR: $1,500.", FontFactory.getFont("arial", 15, Font.BOLD)); importe.setAlignment(Element.ALIGN_CENTER); preficha.add(importe); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); String ref = "44353452342353464765634523434"; Paragraph referencia = new Paragraph( " REFERENCIA (B): " + ref, FontFactory.getFont("arial", 10, Font.BOLD)); referencia.setAlignment(Element.ALIGN_LEFT); preficha.add(referencia); preficha.add(vacio); // Paragraph descrConcepto = new Paragraph("DESCRIPCIN DEL CONCEPTO: CUOTA POR CONCEPTO DE PREINCRIPCIN.", FontFactory.getFont("arial", 10, Font.BOLD)); // descrConcepto.setAlignment(Element.ALIGN_CENTER); // preficha.add(descrConcepto); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); Paragraph atencion = new Paragraph("Atencin", FontFactory.getFont("arial", 15, Font.BOLD)); atencion.setAlignment(Element.ALIGN_CENTER); preficha.add(atencion); PdfContentByte rectangulo_atencion = writer.getDirectContentUnder(); rectangulo_atencion.rectangle(245, 229, 100, 25); rectangulo_atencion.fill(); drawRectangle(rectangulo_atencion, 245, 229, 100, 25); PdfContentByte rectangulo_info = writer.getDirectContentUnder(); rectangulo_info.rectangle(85, 94, 430, 100); rectangulo_info.fill(); drawRectangle(rectangulo_info, 85, 94, 430, 120); preficha.add(vacio); preficha.add(vacio); Paragraph informacion = new Paragraph( " Para continuar con el proceso de preinscripcin debers:\n" + " - Realizar el pago para tu examen de admisin con la \"REFERENCIA\" que aparece\n" + " en este documento en cualquier sucursal BANAMEX.\n" + " - Recibir la notificacin en tu correo electrnico y estar al pendiente de \n" + " las notificaciones que sern enviadas al mismo de que el pago ya fue procesado \n" + " para completar tu proceso de preinscripcin.\n", FontFactory.getFont("arial", 10, Font.BOLD)); informacion.setAlignment(Element.ALIGN_LEFT); preficha.add(informacion); // pie // pie // pie // pie // pie preficha.add(vacio); preficha.add(vacio); preficha.addTitle("Preficha"); preficha.addSubject("Instituto Tecnolgico de Toluca"); preficha.addKeywords("Instituto Tecnolgico de Toluca"); preficha.addAuthor("Departamento de Servicios escolares"); preficha.addCreator("Departamento de Servicios escolares"); preficha.close(); preficha.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } } catch (SQLException ex) { Logger.getLogger(PrefichaPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:watermark.java
public static void main(String[] args) { try {/*from w w w . java2s . co m*/ PdfReader reader = new PdfReader(args[0]); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(args[1])); stamp.getWriter().setCompressionLevel(9); // without this code it'll 3 times bigger int bottom_margin = Integer.parseInt(args[2]); String lic = String.format(LIC, args[3]); BaseFont bf = BaseFont.createFont(FONTFILE, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Chunk c = new Chunk(lic, new Font(bf, 7, Font.NORMAL, TCOLOR)); c.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1 / 800f, null); Phrase phrase = new Phrase(c); int pages = reader.getNumberOfPages(); int xpos = 90; for (int i = 1; i <= pages; i++) { if (i % 2 == 0) xpos = 160; else xpos = 90; PdfContentByte under = stamp.getUnderContent(i); ColumnText.showTextAligned(under, Element.ALIGN_LEFT, phrase, xpos, bottom_margin, -0); } stamp.setFullCompression(); // without this code it'll 3 times bigger stamp.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:generatepayslipbyaccz.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w. java2 s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException { // setting the content type response.setContentType("application/pdf"); try { HttpSession session = request.getSession(); if (session.getAttribute("username") != null) { // Get the text that will be added to the PDF String month = request.getParameter("month"); String year = request.getParameter("year"); String id = request.getParameter("empid"); // System.out.println(id); // String text = request.getParameter("text"); // if (text == null || text.trim().length() == 0) { // text = "You didn't enter any text."; // } //String id="Ultimate01"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", ""); PreparedStatement ps = con.prepareStatement("SELECT * from employee where id=?"); ps.setString(1, id); // ps.setString(2, pass); PreparedStatement ps1 = con .prepareStatement("SELECT * from payslip where employeeid=? and month=? and year=?"); ps1.setString(1, id); ps1.setString(2, month); ps1.setString(3, year); PreparedStatement ps2 = con .prepareStatement("SELECT * from `leave` where employeeid=? and month=? and year=?"); ps2.setString(1, id); ps2.setString(2, month); ps2.setString(3, year); ResultSet rs2 = ps2.executeQuery(); rs2.next(); ResultSet rs = ps.executeQuery(); rs.next(); ResultSet rs1 = ps1.executeQuery(); if (rs1.next() == false) { response.sendRedirect("generatepayslipbyaccz.jsp?id=Payslip of " + month + "/" + year + " is not generated OR Record of this Payslip is not available in our Database"); } // step 1 //System.out.println("sssssssssssssssssss"); Document document = new Document(); // step 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11); Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD); Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD); Font font4 = new Font(Font.FontFamily.HELVETICA, 10); Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font font6 = new Font(Font.FontFamily.HELVETICA, 12); //font1.setColor(BaseColor.WHITE); BaseColor myColor = WebColors.getRGBColor("#F78181"); BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA"); //step 3 document.open(); // step 3.5 PdfPTable table1 = new PdfPTable(3); // 1 columns. PdfPCell cell00 = new PdfPCell(new Paragraph("Payslip\nFEB-2015", font2)); cell00.setBorder(PdfPCell.NO_BORDER); cell00.setPaddingTop(18); PdfPCell cell01 = new PdfPCell(new Paragraph("")); cell01.setBorder(PdfPCell.NO_BORDER); Image image = Image.getInstance("cc.jpg"); PdfPCell cell0 = new PdfPCell(image, true); cell0.setBorder(PdfPCell.NO_BORDER); // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT); //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA")); table1.addCell(cell00); table1.addCell(cell01); table1.addCell(cell0); // table1.addCell(cell1); // table.addCell(cell2); // table.addCell(cell3); table1.setWidthPercentage(100); table1.setSpacingAfter(2f); //table1.setSpacingBefore(20f); //table1.setSpacingAfter(10f); document.add(table1); // table1.setWidthPercentage(100); PdfPTable table2 = new PdfPTable(6); // 3 columns. table2.setWidthPercentage(100); PdfPCell cell11 = new PdfPCell(new Paragraph( rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5), font0)); cell11.setColspan(6); //cell11.setBorder(PdfPCell.NO_BORDER); cell11.setLeading(10f, 0f); cell11.setBorderWidth(1f); cell11.setPadding(4); cell11.setBackgroundColor(myColor1); PdfPCell cell12 = new PdfPCell(new Paragraph("Employee Details", font1)); cell12.setColspan(2); cell12.setBorderWidth(1f); cell12.setLeading(10f, 0f); cell12.setPadding(4); cell12.setBackgroundColor(myColor); PdfPCell cell13 = new PdfPCell(new Paragraph("Payment & Leave Details", font1)); cell13.setColspan(2); cell13.setLeading(10f, 0f); cell13.setPadding(4); cell13.setBorderWidth(1f); cell13.setBackgroundColor(myColor); // cell11.setLeading(15f, 1.5f); PdfPCell cell14 = new PdfPCell(new Paragraph("Location Details", font1)); cell14.setColspan(2); cell14.setLeading(10f, 0f); cell14.setPadding(4); cell14.setBorderWidth(1f); cell14.setBackgroundColor(myColor); // PdfPTable nestedTable1 = new PdfPTable(2); // nestedTable1.addCell(new Paragraph("Emp No.")); // nestedTable1.addCell(new Paragraph("379666")); // cell41.addElement(nestedTable1); table2.addCell(cell11); table2.addCell(cell12); table2.addCell(cell13); table2.addCell(cell14); PdfPCell cell15 = new PdfPCell(new Paragraph("Emp ID.", font3)); //cell15.setLeading(10f, 0f); cell15.setPadding(3); cell15.setBorderWidth(1f); cell15.setBackgroundColor(myColor1); PdfPCell cell16 = new PdfPCell(new Paragraph(rs.getString(1), font4)); // cell16.setLeading(10f, 0f); cell16.setPadding(3); cell16.setBorderWidth(1f); cell16.setBackgroundColor(myColor1); PdfPCell cell17 = new PdfPCell(new Paragraph("Bank Name", font3)); //cell17.setLeading(10f, 0f); cell17.setPadding(3); cell17.setBorderWidth(1f); cell17.setBackgroundColor(myColor1); PdfPCell cell18 = new PdfPCell(new Paragraph(rs.getString(11), font4)); //cell18.setLeading(10f, 0f); cell18.setPadding(3); cell18.setBorderWidth(1f); cell18.setBackgroundColor(myColor1); PdfPCell cell19 = new PdfPCell(new Paragraph("Location", font3)); //cell19.setLeading(10f, 0f); cell19.setPadding(3); cell19.setBorderWidth(1f); cell19.setBackgroundColor(myColor1); PdfPCell cell20 = new PdfPCell(new Paragraph(rs.getString(13), font4)); //cell20.setLeading(10f, 0f); cell20.setPadding(3); cell20.setBorderWidth(1f); cell20.setBackgroundColor(myColor1); table2.addCell(cell15); table2.addCell(cell16); table2.addCell(cell17); table2.addCell(cell18); table2.addCell(cell19); table2.addCell(cell20); PdfPCell cell21 = new PdfPCell(new Paragraph("Dsgn.", font3)); //cell21.setLeading(10f, 0f); cell21.setPadding(3); cell21.setBorderWidth(1f); cell21.setBackgroundColor(myColor1); PdfPCell cell22 = new PdfPCell(new Paragraph(rs.getString(9), font4)); // cell22.setLeading(10f, 0f); cell22.setPadding(3); cell22.setBorderWidth(1f); cell22.setBackgroundColor(myColor1); PdfPCell cell23 = new PdfPCell(new Paragraph("Acc No.", font3)); //cell23.setLeading(10f, 0f); cell23.setPadding(3); cell23.setBorderWidth(1f); cell23.setBackgroundColor(myColor1); int accno = Integer.parseInt(rs.getString(12)); String accno1[] = new String[4]; for (int i = 0; i < 4; i++) { accno1[i] = Integer.toString(accno % 10); accno /= 10; } PdfPCell cell24 = new PdfPCell(new Paragraph( "XXXXXXX" + accno1[3] + "" + accno1[2] + "" + accno1[1] + "" + accno1[0], font4)); //cell24.setLeading(10f, 0f); cell24.setPadding(3); cell24.setBorderWidth(1f); cell24.setBackgroundColor(myColor1); PdfPCell cell25 = new PdfPCell(new Paragraph("Base Br.", font3)); //cell25.setLeading(10f, 0f); cell25.setPadding(3); cell25.setBorderWidth(1f); cell25.setBackgroundColor(myColor1); PdfPCell cell26 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell26.setLeading(10f, 0f); cell26.setPadding(3); cell26.setBorderWidth(1f); cell26.setBackgroundColor(myColor1); table2.addCell(cell21); table2.addCell(cell22); table2.addCell(cell23); table2.addCell(cell24); table2.addCell(cell25); table2.addCell(cell26); PdfPCell cell27 = new PdfPCell(new Paragraph("Grade", font3)); //cell27.setLeading(10f, 0f); cell27.setPadding(3); cell27.setBorderWidth(1f); cell27.setBackgroundColor(myColor1); PdfPCell cell28 = new PdfPCell(new Paragraph("C2", font4)); // cell28.setLeading(10f, 0f); cell28.setPadding(3); cell28.setBorderWidth(1f); cell28.setBackgroundColor(myColor1); PdfPCell cell29 = new PdfPCell(new Paragraph("Days paid", font3)); //cell29.setLeading(10f, 0f); cell29.setPadding(3); cell29.setBorderWidth(1f); cell29.setBackgroundColor(myColor1); PdfPCell cell30 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt(5)), font4)); //cell30.setLeading(10f, 0f); cell30.setPadding(3); cell30.setBorderWidth(1f); cell30.setBackgroundColor(myColor1); PdfPCell cell31 = new PdfPCell(new Paragraph("Depute Br.", font3)); //cell31.setLeading(10f, 0f); cell31.setPadding(3); cell31.setBorderWidth(1f); cell31.setBackgroundColor(myColor1); PdfPCell cell32 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell32.setLeading(10f, 0f); cell32.setPadding(3); cell32.setBorderWidth(1f); cell32.setBackgroundColor(myColor1); table2.addCell(cell27); table2.addCell(cell28); table2.addCell(cell29); table2.addCell(cell30); table2.addCell(cell31); table2.addCell(cell32); PdfPCell cell33 = new PdfPCell(new Paragraph("PAN", font3)); //cell33.setLeading(10f, 0f); cell33.setPadding(3); cell33.setBorderWidth(1f); cell33.setBackgroundColor(myColor1); PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E", font4)); // cell34.setLeading(10f, 0f); cell34.setPadding(3); cell34.setBorderWidth(1f); cell34.setBackgroundColor(myColor1); PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance", font3)); //cell35.setLeading(10f, 0f); cell35.setPadding(3); cell35.setBorderWidth(1f); cell35.setBackgroundColor(myColor1); // PdfPCell cell36 = new PdfPCell(new Paragraph("EL X SL X CL X",font4)); PdfPCell cell36 = new PdfPCell(new Paragraph( "EL " + rs2.getInt(1) + " SL " + rs2.getInt(2) + " CL " + rs2.getInt(3), font4)); //cell36.setLeading(10f, 0f); cell36.setPadding(3); cell36.setBorderWidth(1f); cell36.setBackgroundColor(myColor1); PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON", font3)); //cell37.setLeading(10f, 0f); cell37.setPadding(3); cell37.setBorderWidth(1f); cell37.setBackgroundColor(myColor1); PdfPCell cell38 = new PdfPCell(new Paragraph("2616141", font4)); //cell38.setLeading(10f, 0f); cell38.setPadding(3); cell38.setBorderWidth(1f); cell38.setBackgroundColor(myColor1); table2.addCell(cell33); table2.addCell(cell34); table2.addCell(cell35); table2.addCell(cell36); table2.addCell(cell37); table2.addCell(cell38); table2.setSpacingAfter(12f); document.add(table2); PdfPTable table3 = new PdfPTable(5); // 5 columns. table3.setWidthPercentage(100); PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings", font1)); cell39.setLeading(10f, 0f); cell39.setPadding(4); cell39.setBorderWidth(1f); cell39.setBackgroundColor(myColor); PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)", font1)); cell40.setLeading(10f, 0f); cell40.setPadding(4); cell40.setBorderWidth(1f); cell40.setBackgroundColor(myColor); PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)", font1)); cell41.setLeading(10f, 0f); cell41.setPadding(4); cell41.setBorderWidth(1f); cell41.setBackgroundColor(myColor); PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions", font1)); cell42.setLeading(10f, 0f); cell42.setPadding(4); cell42.setBorderWidth(1f); cell42.setBackgroundColor(myColor); PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)", font1)); cell43.setLeading(10f, 0f); cell43.setPadding(4); cell43.setBorderWidth(1f); cell43.setBackgroundColor(myColor); table3.addCell(cell39); table3.addCell(cell40); table3.addCell(cell41); table3.addCell(cell42); table3.addCell(cell43); String[] sal = new String[10]; sal[0] = "Basic Salary"; sal[1] = "House Rent Allowance"; sal[2] = "Medical Allowance"; sal[3] = "Travelling Allowance"; sal[4] = "Personal Allowance"; sal[5] = "City Allowance"; sal[6] = "Performance Pay"; sal[7] = "Provident Fund"; sal[8] = "Professional Tax"; sal[9] = "Extra Leaves"; Float[] val = new Float[10]; val[0] = rs1.getFloat(4); val[1] = 6000.00f; val[2] = 1000.00f; val[3] = 1000.00f; val[4] = val[0] / 2; val[5] = 1000.00f; val[6] = val[4]; val[7] = val[0] * 12 / 100; val[8] = 0.00f; if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) { val[8] = (val[0] + val[4] + val[6]) / 10; } val[9] = 0.0f; if (rs2.getInt(1) < 0) val[9] -= (rs2.getInt(1) * val[0]) / 30; if (rs2.getInt(2) < 0) val[9] -= rs2.getInt(2) * val[0] / 30; if (rs2.getInt(3) < 0) val[9] -= rs2.getInt(3) * val[0] / 30; for (int i = 0; i < 7; i++) { PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i], font3)); //cell27.setLeading(10f, 0f); cell44.setPadding(3); cell44.setBorderWidth(1f); cell44.setBackgroundColor(myColor1); PdfPCell cell45 = new PdfPCell(new Paragraph("", font4)); // cell45.setLeading(10f, 0f); cell45.setPadding(3); cell45.setBorderWidth(1f); cell45.setBackgroundColor(myColor1); PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(), font3)); //cell46.setLeading(10f, 0f); cell46.setHorizontalAlignment(Element.ALIGN_RIGHT); cell46.setPadding(3); cell46.setBorderWidth(1f); cell46.setBackgroundColor(myColor1); table3.addCell(cell44); table3.addCell(cell45); table3.addCell(cell46); if (i == 0 || i == 1 || i == 2) { PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7 + i], font4)); //cell47.setLeading(10f, 0f); cell47.setPadding(3); cell47.setBorderWidth(1f); cell47.setBackgroundColor(myColor1); table3.addCell(cell47); PdfPCell cell48 = new PdfPCell(new Paragraph(val[i + 7].toString(), font3)); //cell48.setLeading(10f, 0f); cell48.setHorizontalAlignment(Element.ALIGN_RIGHT); cell48.setPadding(3); cell48.setBorderWidth(1f); cell48.setBackgroundColor(myColor1); table3.addCell(cell48); } else { PdfPCell cell47 = new PdfPCell(new Paragraph("", font4)); cell47.setBorder(PdfPCell.NO_BORDER); cell47.setBorderWidthRight(1f); cell47.setColspan(2); table3.addCell(cell47); } } PdfPCell cell48 = new PdfPCell(new Paragraph("", font4)); //cell48.setBorder(PdfPCell.NO_BORDER); cell48.setColspan(3); table3.addCell(cell48); PdfPCell cell49 = new PdfPCell(new Paragraph("", font4)); //cell49.setBorder(PdfPCell.NO_BORDER); cell49.setColspan(2); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)", font3)); //cell27.setLeading(10f, 0f); cell50.setColspan(2); cell50.setPadding(3); cell50.setBorderWidth(1f); cell50.setBackgroundColor(myColor1); table3.addCell(cell50); float a = 0.0f; for (int i = 0; i < 7; i++) { a += val[i]; } PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a), font3)); //cell27.setLeading(10f, 0f); cell55.setPadding(3); cell55.setHorizontalAlignment(Element.ALIGN_RIGHT); cell55.setBorderWidth(1f); cell55.setBackgroundColor(myColor1); table3.addCell(cell55); PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions", font3)); //cell27.setLeading(10f, 0f); //cell51.setColspan(3); cell51.setPadding(3); cell51.setBorderWidth(1f); cell51.setBackgroundColor(myColor1); table3.addCell(cell51); float b = val[7] + val[8] + val[9]; PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b), font3)); //cell27.setLeading(10f, 0f); //cell56.setColspan(3); cell56.setPadding(3); cell56.setHorizontalAlignment(Element.ALIGN_RIGHT); cell56.setBorderWidth(1f); cell56.setBackgroundColor(myColor1); table3.addCell(cell56); table3.setSpacingAfter(12f); document.add(table3); PdfPTable table4 = new PdfPTable(5); // 2 columns. table4.setWidthPercentage(100); PdfPCell cell54 = new PdfPCell(new Paragraph("", font3)); cell54.setBorder(PdfPCell.NO_BORDER); cell54.setColspan(3); table4.addCell(cell54); PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay", font5)); cell52.setLeading(10f, 0f); // cell52.setBorder(PdfPCell.ALIGN_CENTER); cell52.setHorizontalAlignment(Element.ALIGN_LEFT); cell52.setVerticalAlignment(Element.ALIGN_CENTER); cell52.setPadding(6f); cell52.setBorderWidth(1f); cell52.setBackgroundColor(myColor); table4.addCell(cell52); PdfPCell cell53 = new PdfPCell(new Paragraph("" + (a - b), font6)); cell53.setLeading(10f, 0f); cell53.setPadding(6f); cell53.setHorizontalAlignment(Element.ALIGN_CENTER); cell53.setVerticalAlignment(Element.ALIGN_CENTER); cell53.setBorderWidth(1f); table4.addCell(cell53); document.add(table4); // step 4 // document.add(new Paragraph(String.format( // "You have submitted the following text using the %s method:%s", // request.getMethod(),uname))); // document.add(new Paragraph(text)); // step 5 document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } else { response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first"); } } catch (Exception e) { // throw new IOException(e.getMessage()); System.out.println(e); System.out.println("sssssssssssssssssss"); } }
From source file:generatepayslip.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . ja v a 2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException { // setting the content type response.setContentType("application/pdf"); try { HttpSession session = request.getSession(); if (session.getAttribute("username") != null) { // Get the text that will be added to the PDF String month = request.getParameter("month"); String year = request.getParameter("year"); String id = (String) session.getAttribute("id"); // System.out.println(id); // String text = request.getParameter("text"); // if (text == null || text.trim().length() == 0) { // text = "You didn't enter any text."; // } //String id="Ultimate01"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", ""); PreparedStatement ps = con.prepareStatement("SELECT * from employee where id=?"); ps.setString(1, id); // ps.setString(2, pass); PreparedStatement ps1 = con .prepareStatement("SELECT * from payslip where employeeid=? and month=? and year=?"); ps1.setString(1, id); ps1.setString(2, month); ps1.setString(3, year); // PreparedStatement ps2 = con.prepareStatement("SELECT * from leave "); PreparedStatement ps2 = con .prepareStatement("SELECT * from `leave` where employeeid=? and month=? and year=?"); ps2.setString(1, id); ps2.setString(2, month); ps2.setString(3, year); // ResultSet rs = ps.executeQuery(); rs.next(); ResultSet rs1 = ps1.executeQuery(); ResultSet rs2 = ps2.executeQuery(); rs2.next(); if (rs1.next() == false) { response.sendRedirect("generatepayslip.jsp?id=Payslip of " + month + "/" + year + " is not generated OR Record of this Payslip is not available in our Database"); } // step 1 //System.out.println("sssssssssssssssssss"); Document document = new Document(); // step 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11); Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD); Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD); Font font4 = new Font(Font.FontFamily.HELVETICA, 10); Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font font6 = new Font(Font.FontFamily.HELVETICA, 12); //font1.setColor(BaseColor.WHITE); BaseColor myColor = WebColors.getRGBColor("#F78181"); BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA"); //step 3 document.open(); // step 3.5 PdfPTable table1 = new PdfPTable(3); // 1 columns. PdfPCell cell00 = new PdfPCell(new Paragraph("Payslip\nFEB-2015", font2)); cell00.setBorder(PdfPCell.NO_BORDER); cell00.setPaddingTop(18); PdfPCell cell01 = new PdfPCell(new Paragraph("")); cell01.setBorder(PdfPCell.NO_BORDER); Image image = Image.getInstance("cc.jpg"); PdfPCell cell0 = new PdfPCell(image, true); cell0.setBorder(PdfPCell.NO_BORDER); // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT); //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA")); table1.addCell(cell00); table1.addCell(cell01); table1.addCell(cell0); // table1.addCell(cell1); // table.addCell(cell2); // table.addCell(cell3); table1.setWidthPercentage(100); table1.setSpacingAfter(2f); //table1.setSpacingBefore(20f); //table1.setSpacingAfter(10f); document.add(table1); // table1.setWidthPercentage(100); PdfPTable table2 = new PdfPTable(6); // 3 columns. table2.setWidthPercentage(100); PdfPCell cell11 = new PdfPCell(new Paragraph((String) session.getAttribute("username"), font0)); cell11.setColspan(6); //cell11.setBorder(PdfPCell.NO_BORDER); cell11.setLeading(10f, 0f); cell11.setBorderWidth(1f); cell11.setPadding(4); cell11.setBackgroundColor(myColor1); PdfPCell cell12 = new PdfPCell(new Paragraph("Employee Details", font1)); cell12.setColspan(2); cell12.setBorderWidth(1f); cell12.setLeading(10f, 0f); cell12.setPadding(4); cell12.setBackgroundColor(myColor); PdfPCell cell13 = new PdfPCell(new Paragraph("Payment & Leave Details", font1)); cell13.setColspan(2); cell13.setLeading(10f, 0f); cell13.setPadding(4); cell13.setBorderWidth(1f); cell13.setBackgroundColor(myColor); // cell11.setLeading(15f, 1.5f); PdfPCell cell14 = new PdfPCell(new Paragraph("Location Details", font1)); cell14.setColspan(2); cell14.setLeading(10f, 0f); cell14.setPadding(4); cell14.setBorderWidth(1f); cell14.setBackgroundColor(myColor); // PdfPTable nestedTable1 = new PdfPTable(2); // nestedTable1.addCell(new Paragraph("Emp No.")); // nestedTable1.addCell(new Paragraph("379666")); // cell41.addElement(nestedTable1); table2.addCell(cell11); table2.addCell(cell12); table2.addCell(cell13); table2.addCell(cell14); PdfPCell cell15 = new PdfPCell(new Paragraph("Emp ID.", font3)); //cell15.setLeading(10f, 0f); cell15.setPadding(3); cell15.setBorderWidth(1f); cell15.setBackgroundColor(myColor1); PdfPCell cell16 = new PdfPCell(new Paragraph(rs.getString(1), font4)); // cell16.setLeading(10f, 0f); cell16.setPadding(3); cell16.setBorderWidth(1f); cell16.setBackgroundColor(myColor1); PdfPCell cell17 = new PdfPCell(new Paragraph("Bank Name", font3)); //cell17.setLeading(10f, 0f); cell17.setPadding(3); cell17.setBorderWidth(1f); cell17.setBackgroundColor(myColor1); PdfPCell cell18 = new PdfPCell(new Paragraph(rs.getString(11), font4)); //cell18.setLeading(10f, 0f); cell18.setPadding(3); cell18.setBorderWidth(1f); cell18.setBackgroundColor(myColor1); PdfPCell cell19 = new PdfPCell(new Paragraph("Location", font3)); //cell19.setLeading(10f, 0f); cell19.setPadding(3); cell19.setBorderWidth(1f); cell19.setBackgroundColor(myColor1); PdfPCell cell20 = new PdfPCell(new Paragraph(rs.getString(13), font4)); //cell20.setLeading(10f, 0f); cell20.setPadding(3); cell20.setBorderWidth(1f); cell20.setBackgroundColor(myColor1); table2.addCell(cell15); table2.addCell(cell16); table2.addCell(cell17); table2.addCell(cell18); table2.addCell(cell19); table2.addCell(cell20); PdfPCell cell21 = new PdfPCell(new Paragraph("Dsgn.", font3)); //cell21.setLeading(10f, 0f); cell21.setPadding(3); cell21.setBorderWidth(1f); cell21.setBackgroundColor(myColor1); PdfPCell cell22 = new PdfPCell(new Paragraph(rs.getString(9), font4)); // cell22.setLeading(10f, 0f); cell22.setPadding(3); cell22.setBorderWidth(1f); cell22.setBackgroundColor(myColor1); PdfPCell cell23 = new PdfPCell(new Paragraph("Acc No.", font3)); //cell23.setLeading(10f, 0f); cell23.setPadding(3); cell23.setBorderWidth(1f); cell23.setBackgroundColor(myColor1); int accno = Integer.parseInt(rs.getString(12)); String accno1[] = new String[4]; for (int i = 0; i < 4; i++) { accno1[i] = Integer.toString(accno % 10); accno /= 10; } PdfPCell cell24 = new PdfPCell(new Paragraph( "XXXXXXX" + accno1[3] + "" + accno1[2] + "" + accno1[1] + "" + accno1[0], font4)); //cell24.setLeading(10f, 0f); cell24.setPadding(3); cell24.setBorderWidth(1f); cell24.setBackgroundColor(myColor1); PdfPCell cell25 = new PdfPCell(new Paragraph("Base Br.", font3)); //cell25.setLeading(10f, 0f); cell25.setPadding(3); cell25.setBorderWidth(1f); cell25.setBackgroundColor(myColor1); PdfPCell cell26 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell26.setLeading(10f, 0f); cell26.setPadding(3); cell26.setBorderWidth(1f); cell26.setBackgroundColor(myColor1); table2.addCell(cell21); table2.addCell(cell22); table2.addCell(cell23); table2.addCell(cell24); table2.addCell(cell25); table2.addCell(cell26); PdfPCell cell27 = new PdfPCell(new Paragraph("Grade", font3)); //cell27.setLeading(10f, 0f); cell27.setPadding(3); cell27.setBorderWidth(1f); cell27.setBackgroundColor(myColor1); PdfPCell cell28 = new PdfPCell(new Paragraph("C2", font4)); // cell28.setLeading(10f, 0f); cell28.setPadding(3); cell28.setBorderWidth(1f); cell28.setBackgroundColor(myColor1); PdfPCell cell29 = new PdfPCell(new Paragraph("Days paid", font3)); //cell29.setLeading(10f, 0f); cell29.setPadding(3); cell29.setBorderWidth(1f); cell29.setBackgroundColor(myColor1); PdfPCell cell30 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt(5)), font4)); //cell30.setLeading(10f, 0f); cell30.setPadding(3); cell30.setBorderWidth(1f); cell30.setBackgroundColor(myColor1); PdfPCell cell31 = new PdfPCell(new Paragraph("Depute Br.", font3)); //cell31.setLeading(10f, 0f); cell31.setPadding(3); cell31.setBorderWidth(1f); cell31.setBackgroundColor(myColor1); PdfPCell cell32 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell32.setLeading(10f, 0f); cell32.setPadding(3); cell32.setBorderWidth(1f); cell32.setBackgroundColor(myColor1); table2.addCell(cell27); table2.addCell(cell28); table2.addCell(cell29); table2.addCell(cell30); table2.addCell(cell31); table2.addCell(cell32); PdfPCell cell33 = new PdfPCell(new Paragraph("PAN", font3)); //cell33.setLeading(10f, 0f); cell33.setPadding(3); cell33.setBorderWidth(1f); cell33.setBackgroundColor(myColor1); PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E", font4)); // cell34.setLeading(10f, 0f); cell34.setPadding(3); cell34.setBorderWidth(1f); cell34.setBackgroundColor(myColor1); PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance", font3)); //cell35.setLeading(10f, 0f); cell35.setPadding(3); cell35.setBorderWidth(1f); cell35.setBackgroundColor(myColor1); PdfPCell cell36 = new PdfPCell(new Paragraph( "EL " + rs2.getInt(1) + " SL " + rs2.getInt(2) + " CL " + rs2.getInt(3), font4)); // PdfPCell cell36 = new PdfPCell(new Paragraph("EL "+rs2.getInt(2),font4)); //cell36.setLeading(10f, 0f);rs2.getInt(1) cell36.setPadding(3); cell36.setBorderWidth(1f); cell36.setBackgroundColor(myColor1); PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON", font3)); //cell37.setLeading(10f, 0f); cell37.setPadding(3); cell37.setBorderWidth(1f); cell37.setBackgroundColor(myColor1); PdfPCell cell38 = new PdfPCell(new Paragraph("2616141", font4)); //cell38.setLeading(10f, 0f); cell38.setPadding(3); cell38.setBorderWidth(1f); cell38.setBackgroundColor(myColor1); table2.addCell(cell33); table2.addCell(cell34); table2.addCell(cell35); table2.addCell(cell36); table2.addCell(cell37); table2.addCell(cell38); table2.setSpacingAfter(12f); document.add(table2); PdfPTable table3 = new PdfPTable(5); // 5 columns. table3.setWidthPercentage(100); PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings", font1)); cell39.setLeading(10f, 0f); cell39.setPadding(4); cell39.setBorderWidth(1f); cell39.setBackgroundColor(myColor); PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)", font1)); cell40.setLeading(10f, 0f); cell40.setPadding(4); cell40.setBorderWidth(1f); cell40.setBackgroundColor(myColor); PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)", font1)); cell41.setLeading(10f, 0f); cell41.setPadding(4); cell41.setBorderWidth(1f); cell41.setBackgroundColor(myColor); PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions", font1)); cell42.setLeading(10f, 0f); cell42.setPadding(4); cell42.setBorderWidth(1f); cell42.setBackgroundColor(myColor); PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)", font1)); cell43.setLeading(10f, 0f); cell43.setPadding(4); cell43.setBorderWidth(1f); cell43.setBackgroundColor(myColor); table3.addCell(cell39); table3.addCell(cell40); table3.addCell(cell41); table3.addCell(cell42); table3.addCell(cell43); String[] sal = new String[10]; sal[0] = "Basic Salary"; sal[1] = "House Rent Allowance"; sal[2] = "Medical Allowance"; sal[3] = "Travelling Allowance"; sal[4] = "Personal Allowance"; sal[5] = "City Allowance"; sal[6] = "Performance Pay"; sal[7] = "Provident Fund"; sal[8] = "Professional Tax"; sal[9] = "Extra Leaves"; Float[] val = new Float[10]; val[0] = rs1.getFloat(4); val[1] = 6000.00f; val[2] = 1000.00f; val[3] = 1000.00f; val[4] = val[0] / 2; val[5] = 1000.00f; val[6] = val[4]; val[7] = val[0] * 12 / 100; val[8] = 0.00f; if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) { val[8] = (val[0] + val[4] + val[6]) / 10; } val[9] = 0.0f; if (rs2.getInt(1) < 0) val[9] -= (rs2.getInt(1) * val[0]) / 30; if (rs2.getInt(2) < 0) val[9] -= rs2.getInt(2) * val[0] / 30; if (rs2.getInt(3) < 0) val[9] -= rs2.getInt(3) * val[0] / 30; for (int i = 0; i < 7; i++) { PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i], font3)); //cell27.setLeading(10f, 0f); cell44.setPadding(3); cell44.setBorderWidth(1f); cell44.setBackgroundColor(myColor1); PdfPCell cell45 = new PdfPCell(new Paragraph("", font4)); // cell45.setLeading(10f, 0f); cell45.setPadding(3); cell45.setBorderWidth(1f); cell45.setBackgroundColor(myColor1); PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(), font3)); //cell46.setLeading(10f, 0f); cell46.setHorizontalAlignment(Element.ALIGN_RIGHT); cell46.setPadding(3); cell46.setBorderWidth(1f); cell46.setBackgroundColor(myColor1); table3.addCell(cell44); table3.addCell(cell45); table3.addCell(cell46); if (i == 0 || i == 1 || i == 2) { PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7 + i], font4)); //cell47.setLeading(10f, 0f); cell47.setPadding(3); cell47.setBorderWidth(1f); cell47.setBackgroundColor(myColor1); table3.addCell(cell47); PdfPCell cell48 = new PdfPCell(new Paragraph(val[i + 7].toString(), font3)); //cell48.setLeading(10f, 0f); cell48.setHorizontalAlignment(Element.ALIGN_RIGHT); cell48.setPadding(3); cell48.setBorderWidth(1f); cell48.setBackgroundColor(myColor1); table3.addCell(cell48); } else { PdfPCell cell47 = new PdfPCell(new Paragraph("", font4)); cell47.setBorder(PdfPCell.NO_BORDER); cell47.setBorderWidthRight(1f); cell47.setColspan(2); table3.addCell(cell47); } } PdfPCell cell48 = new PdfPCell(new Paragraph("", font4)); //cell48.setBorder(PdfPCell.NO_BORDER); cell48.setColspan(3); table3.addCell(cell48); PdfPCell cell49 = new PdfPCell(new Paragraph("", font4)); //cell49.setBorder(PdfPCell.NO_BORDER); cell49.setColspan(2); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)", font3)); //cell27.setLeading(10f, 0f); cell50.setColspan(2); cell50.setPadding(3); cell50.setBorderWidth(1f); cell50.setBackgroundColor(myColor1); table3.addCell(cell50); float a = 0.0f; for (int i = 0; i < 7; i++) { a += val[i]; } PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a), font3)); //cell27.setLeading(10f, 0f); cell55.setPadding(3); cell55.setHorizontalAlignment(Element.ALIGN_RIGHT); cell55.setBorderWidth(1f); cell55.setBackgroundColor(myColor1); table3.addCell(cell55); PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions", font3)); //cell27.setLeading(10f, 0f); //cell51.setColspan(3); cell51.setPadding(3); cell51.setBorderWidth(1f); cell51.setBackgroundColor(myColor1); table3.addCell(cell51); float b = val[7] + val[8] + val[9]; PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b), font3)); //cell27.setLeading(10f, 0f); //cell56.setColspan(3); cell56.setPadding(3); cell56.setHorizontalAlignment(Element.ALIGN_RIGHT); cell56.setBorderWidth(1f); cell56.setBackgroundColor(myColor1); table3.addCell(cell56); table3.setSpacingAfter(12f); document.add(table3); PdfPTable table4 = new PdfPTable(5); // 2 columns. table4.setWidthPercentage(100); PdfPCell cell54 = new PdfPCell(new Paragraph("", font3)); cell54.setBorder(PdfPCell.NO_BORDER); cell54.setColspan(3); table4.addCell(cell54); PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay", font5)); cell52.setLeading(10f, 0f); // cell52.setBorder(PdfPCell.ALIGN_CENTER); cell52.setHorizontalAlignment(Element.ALIGN_LEFT); cell52.setVerticalAlignment(Element.ALIGN_CENTER); cell52.setPadding(6f); cell52.setBorderWidth(1f); cell52.setBackgroundColor(myColor); table4.addCell(cell52); PdfPCell cell53 = new PdfPCell(new Paragraph("" + (a - b), font6)); cell53.setLeading(10f, 0f); cell53.setPadding(6f); cell53.setHorizontalAlignment(Element.ALIGN_CENTER); cell53.setVerticalAlignment(Element.ALIGN_CENTER); cell53.setBorderWidth(1f); table4.addCell(cell53); document.add(table4); // step 4 // document.add(new Paragraph(String.format( // "You have submitted the following text using the %s method:%s", // request.getMethod(),uname))); // document.add(new Paragraph(text)); // step 5 document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } else { response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first"); } } catch (Exception e) { // throw new IOException(e.getMessage()); System.out.println(e); System.out.println("sssssssssssssssssss"); } }
From source file:adams.flow.transformer.pdfproclet.SpreadSheet.java
License:Open Source License
/** * The actual processing of the document. * * @param generator the context/*from w ww .j a v a 2 s. c o m*/ * @param sheet the spreadsheet to add * @return true if successfully added * @throws Exception if something goes wrong */ protected boolean doProcess(PDFGenerator generator, adams.data.spreadsheet.SpreadSheet sheet) throws Exception { boolean result; Row row; Cell cell; int i; PdfPTable table; PdfPCell pdfCell; String pattern; DecimalFormat format; Paragraph para; Paragraph paraComments; ColumnText ct; pattern = "#0"; for (i = 0; i < m_NumDecimals; i++) { if (i == 0) pattern += "."; pattern += "0"; } format = new DecimalFormat(pattern); result = (sheet != null); if (!result) return false; // comments paraComments = null; if (m_AddComments) paraComments = new Paragraph(Utils.flatten(sheet.getComments(), "\n"), m_FontComments.toFont(m_ColorComments)); // table // 1. header table = new PdfPTable(sheet.getColumnCount()); row = sheet.getHeaderRow(); for (String key : sheet.getHeaderRow().cellKeys()) { cell = row.getCell(key); para = new Paragraph(cell.toString(), m_FontTableHeader.toFont(m_ColorTableHeader)); pdfCell = new PdfPCell(para); pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(pdfCell); } // 2. data for (i = 0; i < sheet.getRowCount(); i++) { row = sheet.getRow(i); for (String key : sheet.getHeaderRow().cellKeys()) { cell = row.getCell(key); if ((cell == null) || cell.isMissing()) { pdfCell = new PdfPCell(new Paragraph("")); } else if (cell.isNumeric()) { pdfCell = new PdfPCell(new Paragraph(format.format(cell.toDouble()), m_FontNumericContent.toFont(m_ColorNumericContent))); pdfCell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { pdfCell = new PdfPCell( new Paragraph(cell.toString(), m_FontGeneralContent.toFont(m_ColorGeneralContent))); pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT); } table.addCell(pdfCell); } } if (m_UseAbsolutePosition) { ct = addColumnTextAt(generator, m_X, m_Y); if (paraComments != null) { ct.addElement(paraComments); ct.addElement(new Paragraph("\n")); } ct.addElement(new Paragraph("\n")); ct.addElement(table); ct.go(); generator.getState().contentAdded(); } else { if (paraComments != null) { result = addElement(generator, paraComments); if (result) result = addElement(generator, new Paragraph("\n")); } if (result) result = addElement(generator, new Paragraph("\n")); if (result) result = addElement(generator, table); } return result; }
From source file:alessandrafx.MarcoVentanaController.java
@FXML private void generarReporteMenusal(MouseEvent event) { try {//from w w w .ja v a2 s . c om FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("Reporte.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); SistemaAleMC sistema = new SistemaAleMC(); Double balanceMonetario = 0.0; //Para salidas de dinero ArrayList<Capital> capitales = sistema.getRegistrosCapitalTipo('S'); cell = new PdfPCell(new Phrase("Gastos y pagos realizados")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de salidas de dinero Double totalEgreso = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario -= Double.valueOf(capital.getMonto()); totalEgreso -= Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE EGRESOS")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalEgreso.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Para Pago de mensualidades capitales = sistema.getRegistrosCapitalTipo('M'); cell = new PdfPCell(new Phrase("Pagos de mensualidad recibidos")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de pago de mensualidades de los alumnos Double totalIngresoMen = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario += Double.valueOf(capital.getMonto()); totalIngresoMen += Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE MENSUALIDADES")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalIngresoMen.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Para Pago de anualidades capitales = sistema.getRegistrosCapitalTipo('A'); cell = new PdfPCell(new Phrase("Pagos de anualidades recibidos")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de pago de anualidades de los alumnos Double totalIngresoAnu = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario += Double.valueOf(capital.getMonto()); totalIngresoAnu += Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE ANUALIDADES")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalIngresoAnu.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //PARA EL BALANCE MONETARIO capitales = sistema.getRegistrosCapitalTipo('A'); cell = new PdfPCell(new Phrase("Total")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega la celda del total monetario if (balanceMonetario == (Double) 0.0) { cell = new PdfPCell(new Phrase("No hubieron movimientos este mes")); } else { cell = new PdfPCell(new Phrase(balanceMonetario.toString())); } cell.setColspan(3); cell.setBackgroundColor(BaseColor.WHITE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); Alert alerta = new Alert(Alert.AlertType.INFORMATION); alerta.setTitle("Corre a ver tu PDF!"); alerta.setHeaderText(null); alerta.setContentText("El PDF ha sido generado, puedes revisarlo"); alerta.showAndWait(); } catch (Exception e) { Alert alerta = new Alert(Alert.AlertType.INFORMATION); alerta.setTitle("Lo sentimos"); alerta.setHeaderText(null); alerta.setContentText("La ubicacin seleccionada no es vlida y por tanto, no se generar el PDF"); alerta.showAndWait(); } }
From source file:alessandrafx.VentanaEgresoController.java
private void generarReportePagoColaborador(int pagoColaborador, int pagoSugerido) throws DatoFaltante { try {// w w w . j ava 2 s . co m FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaNueva.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el pago IDEAL cell = new PdfPCell(new Phrase("Pago sugerido recibido")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase("Pago sugerido")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el pago realizado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(pagoColaborador))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }
From source file:alessandrafx.VentanaEgresoController.java
private void generarReporteOtroGasto(int cantidad, String motivo) throws DatoFaltante { try {/* ww w. j a v a2 s.c om*/ FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaHecha.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el monto pagado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(cantidad))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el motivo del pago cell = new PdfPCell(new Phrase("Motivo: \n" + motivo)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setColspan(3); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }
From source file:alessandrafx.VentanaIngresoController.java
public void generarReportePago(String pagoSugerido, String pagoRealizado) throws DatoFaltante { try {/*w w w . j av a 2 s. c o m*/ FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaNueva.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el pago IDEAL cell = new PdfPCell(new Phrase("Pago sugerido recibido")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(pagoSugerido)); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el pago realizado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(pagoRealizado))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }
From source file:Almacen.Conciliacion.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: try {/*from w w w . j av a 2 s. c om*/ javax.swing.JFileChooser archivo = new javax.swing.JFileChooser(); archivo.setFileFilter(new ExtensionFileFilter("pdf document (*.pdf)", new String[] { "PDF" })); String ruta = null; if (archivo.showSaveDialog(null) == archivo.APPROVE_OPTION) { ruta = archivo.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); ArrayList datos = new ArrayList(); Query query = session.createSQLQuery( "select compania.nombre, orden.tipo_nombre, orden.modelo, orden.no_serie, clientes.nombre as nombres,orden.id_orden \n" + "from orden inner join compania on compania.id_compania=orden.id_compania inner join clientes on clientes.id_clientes=orden.id_cliente\n" + "where orden.id_orden=" + Integer.parseInt(orden) + ""); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); datos = (ArrayList) query.list(); // PDF reporte = new PDF(); reporte.Abrir2(PageSize.LEGAL.rotate(), "CONCILIACIN", ruta + ".pdf"); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] nuevos = new float[] { 40, 40, 25, 40, 145, 20, 50, 50, 50, 50, 50, 50, 100, 50, 20 }; com.itextpdf.text.Font font = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 7, com.itextpdf.text.Font.NORMAL); com.itextpdf.text.Font font1 = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 7, com.itextpdf.text.Font.NORMAL); BaseColor contenido = BaseColor.WHITE; BaseColor contenido1 = BaseColor.DARK_GRAY; int centro = com.itextpdf.text.Element.ALIGN_CENTER; int izquierda = com.itextpdf.text.Element.ALIGN_LEFT; int derecha = com.itextpdf.text.Element.ALIGN_RIGHT; reporte.inicioTexto(); reporte.agregaObjeto(reporte.crearImagen("imagenes/empresa300115.jpg", 730, -90, 45)); reporte.contenido.setFontAndSize(bf, 20); reporte.contenido.setColorFill(BaseColor.BLACK); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_CENTER, "CONCILIACIN PARA FACTURACIN", 395, 577, 0); reporte.contenido.setFontAndSize(bf, 12); reporte.contenido.setColorFill(BaseColor.BLACK); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "COMPAIA:", 38, 540, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "TIPO DE UNIDAD:", 38, 520, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "MODELO:", 38, 500, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "SERIE VIN:", 38, 480, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "CLIENTE:", 38, 460, 0); reporte.contenido.roundRectangle(170, 540, 410, 0, 0); reporte.contenido.roundRectangle(170, 520, 410, 0, 0); reporte.contenido.roundRectangle(170, 500, 410, 0, 0); reporte.contenido.roundRectangle(170, 480, 410, 0, 0); reporte.contenido.roundRectangle(170, 460, 410, 0, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ORDEN DE TRABAJO SET.", 605, 540, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ORDEN DE SURTIDO", 620, 480, 0); for (int i = 0; i < datos.size(); i++) { java.util.HashMap map = (java.util.HashMap) datos.get(i); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("nombre").toString(), 171, 540, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("tipo_nombre").toString(), 171, 520, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("modelo").toString(), 171, 500, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("no_serie").toString(), 171, 480, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("nombres").toString(), 171, 460, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("id_orden").toString(), 657, 520, 0); } reporte.contenido.roundRectangle(640, 520, 80, 0, 0); reporte.contenido.roundRectangle(640, 460, 80, 0, 0); reporte.finTexto(); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_CENTER); cabecera(reporte, bf, tabla, "", 2); DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); int num_r = t_datos.getRowCount(); for (int i = 0; i < num_r; i++) { for (int j = 0; j < 4; j++) { int renglon = 0; switch (j) { case 0: renglon = 8; break; case 1: renglon = 10; break; case 2: renglon = 11; break; case 3: renglon = 12; break; } if ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && t_datos.getValueAt(i, 9).toString().compareTo("N") == 0) || ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && renglon >= 10)) || (renglon == 8 && Double.parseDouble(t_datos.getValueAt(i, 10).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 11).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 12).toString()) <= 0)) { if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) contenido = BaseColor.WHITE; else contenido = BaseColor.LIGHT_GRAY; if ((boolean) t_datos.getValueAt(i, 3) == true || (boolean) t_datos.getValueAt(i, 4) == true) { //columna0 if (t_datos.getValueAt(i, 5) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna1 if (t_datos.getValueAt(i, 6) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna2 tabla.addCell(reporte.celda(t_datos.getValueAt(i, renglon).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); //columna3 if (t_datos.getValueAt(i, 14) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 14).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna4 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //columna5 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); else { switch (renglon) { case 8: tabla.addCell(reporte.celda("N", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 10: tabla.addCell(reporte.celda("D", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 11: tabla.addCell(reporte.celda("R", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 12: tabla.addCell(reporte.celda("M", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; } } //columna6 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna7 $tot aut. double n; n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 15).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna8 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 16)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna9 $tot com n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 16).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna10 11 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { switch (renglon) { case 8: n = BigDecimal.valueOf( Double.parseDouble(t_datos.getValueAt(i, 16).toString()) / 0.9d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 10: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.72d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 11: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 12: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; } } //columna12 if (t_datos.getValueAt(i, 18) == null) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 18).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } //columna13 if (t_datos.getValueAt(i, 19) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 19).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna14 tabla.addCell( reporte.celda("V", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } } } } font1.setColor(BaseColor.WHITE); tabla.addCell(reporte.celda("Faltante en Vales", font1, contenido1, centro, 15, 1, Rectangle.RECTANGLE)); for (int i = 0; i < num_r; i++) { for (int j = 0; j < 4; j++) { int renglon = 0; switch (j) { case 0: renglon = 8; break; case 1: renglon = 10; break; case 2: renglon = 11; break; case 3: renglon = 12; break; } if ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && t_datos.getValueAt(i, 9).toString().compareTo("N") == 0) || ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && renglon >= 10)) || (renglon == 8 && Double.parseDouble(t_datos.getValueAt(i, 10).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 11).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 12).toString()) <= 0)) { if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) contenido = BaseColor.WHITE; else contenido = BaseColor.LIGHT_GRAY; if ((boolean) t_datos.getValueAt(i, 3) == false && (boolean) t_datos.getValueAt(i, 4) == false && t_datos.getValueAt(i, 5) != null) { //columna0 if (t_datos.getValueAt(i, 5) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna1 if (t_datos.getValueAt(i, 6) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna2 tabla.addCell(reporte.celda(t_datos.getValueAt(i, renglon).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); //columna3 if (t_datos.getValueAt(i, 14) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 14).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna4 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //columna5 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); else { switch (renglon) { case 8: tabla.addCell(reporte.celda("N", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 10: tabla.addCell(reporte.celda("D", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 11: tabla.addCell(reporte.celda("R", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 12: tabla.addCell(reporte.celda("M", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; } } //columna6 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna7 $tot aut. double n; n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 15).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna8 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 16)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna9 $tot com n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 16).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna10 11 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { switch (renglon) { case 8: n = BigDecimal.valueOf( Double.parseDouble(t_datos.getValueAt(i, 16).toString()) / 0.9d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 10: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.72d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 11: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 12: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; } } //columna12 if (t_datos.getValueAt(i, 18) == null) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 18).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } //columna13 if (t_datos.getValueAt(i, 19) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 19).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna14 tabla.addCell( reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } } } } tabla.addCell(reporte.celda("Total", font, contenido, derecha, 11, 1, Rectangle.NO_BORDER)); tabla.addCell( reporte.celda(formatoPorcentaje.format(Double.parseDouble(total.getValue().toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, centro, 3, 1, Rectangle.NO_BORDER)); tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } } } catch (Exception e) { e.printStackTrace(); } }