List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:Clases.NuevoPdf.java
private static void addTitlePage(Document document) throws DocumentException, IOException { Paragraph encabezado = new Paragraph(); Paragraph empresa = new Paragraph("REFACCIONARIA AUTOMOTRIZ ANCONA S.A de C.V", smallBold); Paragraph direccion = new Paragraph( "AV. PUERTO JUAREZ, LTE. 29 MZA. 1, REG. 92, CANCUN MPIO BENITO JUAREZ Q.ROO C.P 77516", small); Paragraph telefono = new Paragraph("TELS: (998) 888-60-69", small); Paragraph rfc = new Paragraph("RAA020304893", small); Paragraph reg = new Paragraph("REGIMEN GENERAL DE LEY PERSONAS MORALES", small); encabezado.setAlignment(Element.ALIGN_CENTER); empresa.setAlignment(Element.ALIGN_CENTER); direccion.setAlignment(Element.ALIGN_CENTER); telefono.setAlignment(Element.ALIGN_CENTER); rfc.setAlignment(Element.ALIGN_CENTER); reg.setAlignment(Element.ALIGN_CENTER); Paragraph[] arregloParrafos = { empresa, direccion, telefono, rfc, reg }; tableDatosEncabezado(arregloParrafos, document); }
From source file:Clases.NuevoPdf.java
private static void tableDatosEncabezado(Paragraph[] arregloParrafos, Document document) throws BadElementException, IOException { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(99);/*ww w . j a v a 2 s . c o m*/ PdfPCell c1 = new PdfPCell(new Phrase()); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBorder(0); addLogo(c1, "LOGO.png"); table.addCell(c1); PdfPCell c2 = new PdfPCell(); for (int i = 0; i < arregloParrafos.length; i++) { c2.addElement(arregloParrafos[i]); } c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setBorder(0); table.addCell(c2); float[] columnWidths = new float[] { 25f, 75f }; try { table.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } Paragraph p = new Paragraph(); p.add(table); try { document.add(p); } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:Clases.NuevoPdf.java
private static void addTableClienteYFactura(Document doc) throws DocumentException { PdfPTable encabezados = new PdfPTable(2); encabezados.setWidthPercentage(99);/*from w w w. java2s . c o m*/ PdfPCell c1 = new PdfPCell(new Phrase("CLIENTE", normalWhite)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.RED); c1.setBorder(0); encabezados.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("FOLIO FISCAL", normalWhite)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setBackgroundColor(BaseColor.RED); c2.setBorder(0); encabezados.addCell(c2); PdfPTable datos = new PdfPTable(2); datos.setWidthPercentage(99); Paragraph rfc = new Paragraph("N de Folio: " + Variables.idFactura, medium); Paragraph rfc2 = new Paragraph(Variables.RFC, medium); Paragraph nombre = new Paragraph(Variables.NombreCliente, medium); Paragraph direccion = new Paragraph(Variables.delegacion, medium); Paragraph ciudad = new Paragraph(Variables.municipio + " " + Variables.Estado + " MEXICO", medium); Paragraph cp = new Paragraph("CP: " + Variables.codpostal, medium); Paragraph[] datosCliente = { rfc, rfc2, nombre, direccion, ciudad, cp }; PdfPCell c3 = new PdfPCell(); for (int i = 0; i < datosCliente.length; i++) { c3.addElement(datosCliente[i]); } datos.addCell(c3); float[] columnWidths = new float[] { 60f, 40f }; try { encabezados.setWidths(columnWidths); datos.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } Paragraph folioFactura = new Paragraph("CS434-BYOR3343-GVLR03-034", smallBold); Paragraph csd = new Paragraph("No de serie del certificado CSD", smallBold); Paragraph codigo = new Paragraph("03490941023923", smallBold); Paragraph fecha = new Paragraph("Fecha y hora de emisin", smallBold); Paragraph datosfecha = new Paragraph(Variables.FechaSistema, smallBold); folioFactura.setAlignment(Element.ALIGN_CENTER); csd.setAlignment(Element.ALIGN_CENTER); codigo.setAlignment(Element.ALIGN_CENTER); fecha.setAlignment(Element.ALIGN_CENTER); datosfecha.setAlignment(Element.ALIGN_CENTER); Paragraph[] datosFactura = { folioFactura, csd, codigo, fecha, datosfecha }; PdfPCell c4 = new PdfPCell(); for (int i = 0; i < datosFactura.length; i++) { c4.addElement(datosFactura[i]); } datos.addCell(c4); Paragraph p = new Paragraph(); p.add(encabezados); p.add(datos); doc.add(p); }
From source file:Clases.NuevoPdf.java
private static void addTableProducts(Document doc) throws DocumentException { PdfPTable table = new PdfPTable(6); table.setWidthPercentage(99);/*from ww w. ja v a 2s .c o m*/ PdfPCell c1 = new PdfPCell(new Phrase("CLAVE", normalWhite)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.RED); c1.setBorder(0); table.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("CANTIDAD", normalWhite)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setBackgroundColor(BaseColor.RED); c2.setBorder(0); table.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("UM", normalWhite)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); c3.setBackgroundColor(BaseColor.RED); c3.setBorder(0); table.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("DESCRIPCION", normalWhite)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); c4.setBackgroundColor(BaseColor.RED); c4.setBorder(0); table.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("PRECIO UNITARIO", normalWhite)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); c5.setBackgroundColor(BaseColor.RED); c5.setBorder(0); table.addCell(c5); PdfPCell c6 = new PdfPCell(new Phrase("IMPORTE", normalWhite)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); c6.setBackgroundColor(BaseColor.RED); c6.setBorder(0); table.addCell(c6); float[] columnWidths = new float[] { 15f, 15f, 10f, 30f, 15f, 15f }; try { table.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } for (int i = 0; i < Variables.claves.size(); i++) { table.addCell(new Phrase(String.valueOf(Variables.claves.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.cantidades.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.ums.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.descripciones.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.preciosunitarios.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.importes.get(i)), normal)); } /*table.addCell(new Phrase("R0-510055-TIM",normal)); table.addCell(new Phrase("2.0",normal)); table.addCell(new Phrase("PIEZAS",normal)); table.addCell(new Phrase("BALERO DOBLE",normal)); table.addCell(new Phrase("$336.47",normal)); table.addCell(new Phrase("$672.94",normal));*/ Paragraph p = new Paragraph(); p.add(table); doc.add(p); }
From source file:Clases.NuevoPdf.java
private static void addTableTotales(Document doc) throws DocumentException, IOException { Paragraph totalEnLetras = new Paragraph("SON : SEISCIENTOS SETENTA Y TRES PESOS 52/100 M.N"); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(99);//from ww w . j av a2 s . c o m PdfPCell c1 = new PdfPCell(); Paragraph comentariotitulo = new Paragraph("Comentario", smallBold); Paragraph comentario = new Paragraph(Variables.Comentario, small); Paragraph cv = new Paragraph("Condicion de venta: CONTADO", smallBold); Paragraph fp = new Paragraph("Forma de pago: UNA SOLA EXHIBICION", smallBold); Paragraph mp = new Paragraph("Metodo de pago: EFECTIVO", smallBold); Paragraph[] formasPago = { comentariotitulo, comentario, cv, fp, mp }; for (int i = 0; i < formasPago.length; i++) { c1.addElement(formasPago[i]); } c1.setBorder(0); table.addCell(c1); PdfPCell c2 = new PdfPCell(); Paragraph s = new Paragraph("Suma:", small); Paragraph d = new Paragraph("Descuento:", small); Paragraph st = new Paragraph("Subtotal:", small); Paragraph iv = new Paragraph("IVA: 16%:", small); Paragraph t = new Paragraph("Total:", smallBold); Paragraph[] tags = { s, d, st, iv, t }; for (int i = 0; i < tags.length; i++) { c2.addElement(tags[i]); } c2.setBorder(0); table.addCell(c2); PdfPCell c3 = new PdfPCell(); Paragraph ns = new Paragraph("$" + String.valueOf(Variables.suma), small); Paragraph nd = new Paragraph("$" + String.valueOf(Variables.descuento), small); Paragraph nst = new Paragraph("$" + String.valueOf(Variables.subtotal), small); Paragraph niv = new Paragraph("$" + String.valueOf(Variables.iva), small); Paragraph nt = new Paragraph("$" + String.valueOf(Variables.total), smallBold); Paragraph[] totales = { ns, nd, nst, niv, nt }; for (int i = 0; i < totales.length; i++) { c3.addElement(totales[i]); } c3.setBorder(0); table.addCell(c3); float[] columnWidths = new float[] { 66f, 17f, 17f }; try { table.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } Paragraph p = new Paragraph(); Paragraph espaciador = new Paragraph(""); Paragraph sellodigital1 = new Paragraph("Sello digital del CFDI", smallBold); Paragraph sellodigital2 = new Paragraph( "fk0fok0f94kf09fk049fk340fk42f034kf04fk340fi43kf034fk340fk34f034kf034fk340fk340fk34f0o34kf034ofk340fo3k4f03kg35ihjlofkajflakjfl4kfj3l2kfj2f03jgoerkgjsfvns,vmernv034fv349fi2jf034ijf20gfijdqdkqejfoej", small); Paragraph sellodigital3 = new Paragraph("Sello del SAT", smallBold); Paragraph sellodigital4 = new Paragraph( "cmdvkdovewwdqwCWEFRWRVIW3903r930frvDGHERGWRBRVEGRWGWRddkfjdkfrjgkwvnsdlkcmasx,sqpsqlkcwproigkrofik24203940e2932d,swlsk qms12dikd39kdw0oc,wrjbnwepobvkjqevo24f0rwkvwri0bj35ob iwemvlw,amsc,meovkjw0bn0234or0fj", small); Paragraph sellodigital5 = new Paragraph("No de serie del complemento de certificacion del SAT:", smallBold); Paragraph sellodigital6 = new Paragraph("00000100000002133560001", smallBold); Paragraph sellodigital7 = new Paragraph("Fecha y hora de certificacion:", smallBold); Paragraph sellodigital8 = new Paragraph(Variables.FechaFactura, small); Paragraph sellodigital9 = new Paragraph("Expedido en:", smallBold); Paragraph sellodigital10 = new Paragraph("CANCUN, QUINTANA ROO", small); Paragraph sellodigital11 = new Paragraph("ESTE DOCUMENTO ES UNA REPRESENTACION IMPRESA DE UN CFDI ", smallBold); Paragraph[] parrafosSellos = { sellodigital1, sellodigital2, sellodigital3, sellodigital4 }; PdfPTable datosSAT = new PdfPTable(2); datosSAT.setWidthPercentage(99); PdfPCell cS1 = new PdfPCell(new Phrase()); cS1.setHorizontalAlignment(Element.ALIGN_CENTER); cS1.setBorder(0); addLogo(cS1, "qr.jpg"); datosSAT.addCell(cS1); PdfPCell cS2 = new PdfPCell(); for (int i = 0; i < parrafosSellos.length; i++) { cS2.addElement(parrafosSellos[i]); } cS2.setBorder(0); datosSAT.addCell(cS2); float[] columnWidths2 = new float[] { 20f, 80f }; try { datosSAT.setWidths(columnWidths2); } catch (Exception ex) { System.out.println(ex.getMessage()); } p.add(table); p.add(espaciador); p.add(espaciador); p.add(datosSAT); p.add(sellodigital5); p.add(sellodigital6); p.add(sellodigital7); p.add(sellodigital8); p.add(sellodigital9); p.add(sellodigital10); p.add(sellodigital11); doc.add(p); }
From source file:classes.PdfFiles.java
public static void addTitlePage(Document document) throws DocumentException { Paragraph title = new Paragraph("Paragon", catFont); title.setAlignment(Element.ALIGN_CENTER); document.add(title);//from w w w . j a v a 2 s . c o m Paragraph preface = new Paragraph(); addEmptyLine(preface, 1); preface.add(new Paragraph("Wygenerowano: " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 5); document.add(preface); }
From source file:classes.PdfFiles.java
private static void createTable(Document document, java.util.List<Product> selling_list) { /*Create table*/ PdfPTable table = new PdfPTable(4); /*Create price*/ Double price = 0.0;//from w w w . j a va 2 s .com /*Add cells*/ PdfPCell c1 = new PdfPCell(new Phrase("Nazwa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cena")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("VAT")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Ilosc")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); /*Add cells for each product*/ for (Product p : selling_list) { table.addCell(p.getName()); table.addCell(Double.toString(p.getRetail_price())); table.addCell(Double.toString(p.getVat())); table.addCell(Integer.toString(p.getQuantity())); } Function f = new Function(); /*Get price*/ price = f.getPriceFromProductList(selling_list); try { /*Add table*/ Paragraph p = new Paragraph(); p.add(table); addEmptyLine(p, 2); Paragraph p2 = new Paragraph(Double.toString(price) + " PLN"); p2.setAlignment(Element.ALIGN_RIGHT); p.add(p2); document.add(p); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error genrating Invoice"); Logger.getLogger(PdfFiles.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:client.welcome0.java
private void genRepButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButton1ActionPerformed Document doc = new Document(); PdfWriter docWriter = null;/*from ww w. j a v a 2 s. c om*/ int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1); DecimalFormat df = new DecimalFormat("0.00"); //Date d = Calendar.getInstance().getTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); String fileName = null; job_title = JobTitleChoice.getSelectedItem(); try { //special font sizes com.itextpdf.text.Font bfBold12 = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.TIMES_ROMAN, 12, com.itextpdf.text.Font.BOLD, new BaseColor(0, 0, 0)); com.itextpdf.text.Font bf12 = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.TIMES_ROMAN, 12); //file path String dt = dateFormat.format(date); sFileName = "Report No- " + repID + " Workers Report- " + dt + " Job Title " + job_title + " .pdf"; String path = "src/WorkerReports/" + sFileName; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm"); String d = dateFormat3.format(Calendar.getInstance().getTime()); //document header attributes doc.addCreationDate(); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("src/Images/logo for pdf.png"); com.itextpdf.text.Font font1 = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 25, com.itextpdf.text.Font.BOLD); Paragraph paragraph = new Paragraph(); Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d + "\nYou can see Yatzig's workers by the job title you chose"); image.setAlignment(com.itextpdf.text.Image.RIGHT); doc.add(image); //specify column widths float[] columnWidths = { 3f, 3f, 3f, 4f, 3f, 3f, 5f, 3f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); //insert column headings insertCell(table, "Worker ID", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "First Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Last Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Phone", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Address", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Birth Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Email", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Job Title", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/ //create section heading by cell merging /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/ /*double orderTotal, total = 0;*/ String add1, add2, add3, add4, add5, add6, add7, add8; if (job_title.equals("All")) try { String sql = "select worker_id,first_name,last_name,worker_phone,worker_add,birth_date,email,job_title from workers order by job_title "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("worker_id"); add2 = rs.getString("first_name"); add3 = rs.getString("last_name"); add4 = rs.getString("worker_phone"); add5 = rs.getString("worker_add"); add6 = dateFormat.format(rs.getDate("birth_date")); add7 = rs.getString("email"); add8 = rs.getString("job_title"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add8, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } else try { String sql = "select worker_id,first_name,last_name,worker_phone,worker_add,birth_date,email,job_title from workers where job_title='" + job_title + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("worker_id"); add2 = rs.getString("first_name"); add3 = rs.getString("last_name"); add4 = rs.getString("worker_phone"); add5 = rs.getString("worker_add"); add6 = dateFormat.format(rs.getDate("birth_date")); add7 = rs.getString("email"); add8 = rs.getString("job_title"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add8, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } //add the PDF table to the paragraph paragraph2.add(table); // add the paragraph to the document doc.add(new Paragraph("\nWorkers Report " + dt + "\n", font1)); doc.add(paragraph2); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!"); } if (docWriter != null) { //close the writer docWriter.close(); } } saveToDB(job_title, date, repID); }
From source file:client.welcome1.java
private void genrateItemRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genrateItemRepButtonActionPerformed Document doc = new Document(); PdfWriter docWriter = null;//from w w w. j a v a 2 s . c o m int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1); DecimalFormat df = new DecimalFormat("0.00"); //Date d = Calendar.getInstance().getTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); try { //special font sizes com.itextpdf.text.Font bfBold12 = new com.itextpdf.text.Font(FontFamily.TIMES_ROMAN, 12, com.itextpdf.text.Font.BOLD, new BaseColor(0, 0, 0)); com.itextpdf.text.Font bf12 = new com.itextpdf.text.Font(FontFamily.TIMES_ROMAN, 12); //file path String dt = dateFormat.format(date); sFileName = "Report No- " + repID + " Items Report- " + dt + " Status " + itemRepChoice + " .pdf"; String path = "src/ItemsReports/" + sFileName; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm"); String d = dateFormat3.format(Calendar.getInstance().getTime()); //document header attributes doc.addCreationDate(); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph Image image = Image.getInstance("src/Images/logo for pdf.png"); Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Paragraph paragraph = new Paragraph(); Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d + "\nYou can see " + itemRepChoice + " Items"); image.setAlignment(Image.RIGHT); doc.add(image); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 3f, 2f, 2f, 2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); //insert column headings insertCell(table, "Item ID", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Item Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Quantity", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Min Quantity Level", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Warehouse", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Row", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Shelf", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/ //create section heading by cell merging /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/ /*double orderTotal, total = 0;*/ String add1, add2, add3, add4, add5, add6, add7; if (itemRepChoice.equals("All")) { try { String sql = "select item_id,item_name,quantity,min_quantity_level,warehouse,row,shelf from items"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("item_id"); add2 = rs.getString("item_name"); add3 = rs.getString("quantity"); add4 = rs.getString("min_quantity_level"); add5 = rs.getString("warehouse"); add6 = rs.getString("row"); add7 = rs.getString("shelf"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else if (itemRepChoice.equals("Warehouse")) { String wh = wareHouschoice.getSelectedItem(); try { String sql = "select item_id,item_name,quantity,min_quantity_level,warehouse,row,shelf from items where warehouse='" + wh + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("item_id"); add2 = rs.getString("item_name"); add3 = rs.getString("quantity"); add4 = rs.getString("min_quantity_level"); add5 = rs.getString("warehouse"); add6 = rs.getString("row"); add7 = rs.getString("shelf"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else if (itemRepChoice.equals("Min Level")) { String wh = wareHouschoice.getSelectedItem(); try { String sql = "select item_id,item_name,quantity,min_quantity_level,warehouse,row,shelf from items where min_quantity_level>=quantity"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("item_id"); add2 = rs.getString("item_name"); add3 = rs.getString("quantity"); add4 = rs.getString("min_quantity_level"); add5 = rs.getString("warehouse"); add6 = rs.getString("row"); add7 = rs.getString("shelf"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } //add the PDF table to the paragraph paragraph2.add(table); // add the paragraph to the document doc.add(new Paragraph("\nItems Status Report " + dt + "\n", font1)); doc.add(paragraph2); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!"); } if (docWriter != null) { //close the writer docWriter.close(); } } saveToDB(itemRepChoice, date, repID); }
From source file:client.welcome2.java
private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed Document doc = new Document(); PdfWriter docWriter = null;//from w ww .j a v a 2 s . com int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1); DecimalFormat df = new DecimalFormat("0.00"); //Date d = Calendar.getInstance().getTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); try { //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); //file path String dt = dateFormat.format(date); sFileName = "Report No- " + repID + " Project Report- " + dt + " Status " + report_status + " .pdf"; String path = "src/ProjectReports/" + sFileName; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm"); String d = dateFormat3.format(Calendar.getInstance().getTime()); //document header attributes doc.addCreationDate(); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy"); String sd2 = dateFormat2.format(pBeginDateChooser.getDate()); String ed2 = dateFormat2.format(pEndDateChooser.getDate()); Image image = Image.getInstance("src/Images/logo for pdf.png"); Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Paragraph paragraph = new Paragraph(); Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d + "\nYou can see all projects from " + sd2 + " to " + ed2); image.setAlignment(Image.RIGHT); doc.add(image); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); //insert column headings insertCell(table, "Project ID", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Project Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Start Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Due Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Status", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/ //create section heading by cell merging /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/ /*double orderTotal, total = 0;*/ String add1, add2, add3, add4, add5; DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); String sd = dateFormat1.format(pBeginDateChooser.getDate()); String ed = dateFormat1.format(pEndDateChooser.getDate()); if (report_status.equals("All")) { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where status = '" + report_status + "' and due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } //add the PDF table to the paragraph paragraph2.add(table); // add the paragraph to the document doc.add(new Paragraph("\nProject Status Report " + dt + "\n", font1)); doc.add(paragraph2); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!"); } if (docWriter != null) { //close the writer docWriter.close(); } } saveToDB(report_status, date, repID); }