List of usage examples for com.itextpdf.text Image setAlignment
public void setAlignment(final int alignment)
From source file:classes.utils.createPDF_NetPresent.java
public String writePDF(Scene scene, String datos) throws FileNotFoundException, DocumentException, BadElementException, IOException { javafx.scene.control.TextField projectName = (javafx.scene.control.TextField) scene .lookup(CNodeID.TEXTFIELD_PROJECT_NAME); String project = projectName.getText(); StringTokenizer st = new StringTokenizer(datos, "_"); period = st.nextToken();//ww w. j ava2s . co m principal = st.nextToken(); interestRate = st.nextToken(); tax = st.nextToken(); salvageV = st.nextToken(); periodSalvage = st.nextToken(); data = st.nextToken(); Document document = new Document(PageSize.LETTER, 80, 80, 50, 50); FileOutputStream salida = new FileOutputStream(project + "_NetPresentValue.pdf"); PdfWriter writer = PdfWriter.getInstance(document, salida); writer.setInitialLeading(0); Paragraph paragraph = new Paragraph(); paragraph.setFont(new Font(FontFactory.getFont("Courier", 20, Font.BOLDITALIC, BaseColor.RED))); paragraph.add("\n\n\nNET PRESENT VALUE"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); //Image image = Image.getInstance("/home/isaac/IdeaProjects/ProjectEvaluation/src/images/logo_report.png"); //image.scaleToFit(150, 150); Image image1 = Image.getInstance(project + "/" + project + "_NPV_CCF.png"); image1.scaleToFit(300, 300); //image.setAlignment(Chunk.ALIGN_RIGHT); image1.setAlignment(Chunk.ALIGN_CENTER); Paragraph paragraph_2 = new Paragraph(); paragraph_2.setFont(new Font(FontFactory.getFont("Courier", 12, Font.BOLD, BaseColor.BLUE))); paragraph_2.add( "\n\n\n\n\n\n\n\n\n\n\nADMINISTRACION Y EVALUACION DE PROYECTOS\n\n SERGIO VALDES TORRES A01365520\n ERIK MARTIN A01365096\nISAAC SECUNDINO A01361162\n IVAN CABRER A01184937"); paragraph_2.setAlignment(Paragraph.ALIGN_RIGHT); Paragraph paragraph_3 = new Paragraph(); paragraph_3.setFont(new Font(FontFactory.getFont("Courier", 11, Font.BOLD, BaseColor.BLACK))); paragraph_3.add("\n " + data); paragraph_3.setAlignment(Paragraph.ALIGN_LEFT); Paragraph paragraph_5 = new Paragraph(); paragraph_5.setFont(new Font(FontFactory.getFont("Courier", 10, Font.BOLD, BaseColor.BLUE))); paragraph_5.add("\n\nP OUTFLOW INFLOW NET CASH FLOW CUMULATIVE CASH "); paragraph_5.setAlignment(Paragraph.ALIGN_LEFT); Paragraph paragraph_4 = new Paragraph(); paragraph_4.setFont(new Font(FontFactory.getFont("Courier", 9, Font.BOLD, BaseColor.BLACK))); paragraph_4.add("Nombre del Evaluador: \nPeriods: " + period + "\n Principal: " + principal + " \n Interest Rate%: " + interestRate + " \n Tax Rate %: " + tax + "\n Salvage Value: " + salvageV + " \n Period SV: " + periodSalvage); paragraph_4.setAlignment(Paragraph.ALIGN_LEFT); Paragraph paragraph_6 = new Paragraph(); paragraph_6.setFont(new Font(FontFactory.getFont("Courier", 15, Font.BOLD, BaseColor.GRAY))); paragraph_6.add("\n GRAFICAS\n"); paragraph_6.setAlignment(Paragraph.ALIGN_CENTER); document.open(); //document.add(image); document.add(paragraph); document.add(paragraph_4); document.add(paragraph_5); document.add(paragraph_3); document.add(paragraph_6); document.add(image1); Image image2 = Image.getInstance(project + "/" + project + "_NPV_NCF.png"); document.add(image2); document.add(paragraph_2); document.close(); return null; }
From source file:classes.utils.createPDF_PayBack.java
public String writePDF(Scene scene, String datos) throws FileNotFoundException, DocumentException, BadElementException, IOException { javafx.scene.control.TextField projectName = (javafx.scene.control.TextField) scene .lookup(CNodeID.TEXTFIELD_PROJECT_NAME); String project = projectName.getText(); StringTokenizer st = new StringTokenizer(datos, "_"); period = st.nextToken();//from w ww. ja v a 2 s . c o m principal = st.nextToken(); interestRate = st.nextToken(); data = st.nextToken(); Document document = new Document(PageSize.LETTER, 80, 80, 50, 50); FileOutputStream salida = new FileOutputStream(project + "_PayBackPeriod.pdf"); PdfWriter writer = PdfWriter.getInstance(document, salida); writer.setInitialLeading(0); Paragraph paragraph = new Paragraph(); paragraph.setFont(new Font(FontFactory.getFont("Courier", 20, Font.BOLDITALIC, BaseColor.RED))); paragraph.add("\n\n\nPAYBACK PERIOD"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); // TODO: Change absolute to relative //Image image = Image.getInstance("/home/isaac/IdeaProjects/ProjectEvaluation/src/images/logo_report.png"); //image.scaleToFit(150, 150); Image image1 = Image.getInstance(project + "/" + project + "_PBP_CCF.png"); image1.scaleToFit(300, 300); //image.setAlignment(Chunk.ALIGN_RIGHT); image1.setAlignment(Chunk.ALIGN_CENTER); Paragraph paragraph_2 = new Paragraph(); paragraph_2.setFont(new Font(FontFactory.getFont("Courier", 12, Font.BOLD, BaseColor.BLUE))); paragraph_2.add( "\n\n\n\n\n\n\n\n\n\n\nADMINISTRACION Y EVALUACION DE PROYECTOS\n\n SERGIO VALDES TORRES A01365520\n ERIK MARTIN A01365096\nISAAC SECUNDINO A01361162\n IVAN CABRER A01184937"); paragraph_2.setAlignment(Paragraph.ALIGN_RIGHT); Paragraph paragraph_3 = new Paragraph(); paragraph_3.setFont(new Font(FontFactory.getFont("Courier", 11, Font.BOLD, BaseColor.BLACK))); paragraph_3.add("\n " + data); paragraph_3.setAlignment(Paragraph.ALIGN_LEFT); Paragraph paragraph_5 = new Paragraph(); paragraph_5.setFont(new Font(FontFactory.getFont("Courier", 10, Font.BOLD, BaseColor.BLUE))); paragraph_5.add("\n\nP OUTFLOW INFLOW CUMMULATIVE CASH... "); paragraph_5.setAlignment(Paragraph.ALIGN_LEFT); Paragraph paragraph_4 = new Paragraph(); paragraph_4.setFont(new Font(FontFactory.getFont("Courier", 9, Font.BOLD, BaseColor.BLACK))); paragraph_4.add("Nombre del Evaluador: \n Principal: " + principal + " \n Numero de Periodos: " + period + "\nInterest Rate %" + interestRate); paragraph_4.setAlignment(Paragraph.ALIGN_LEFT); Paragraph paragraph_6 = new Paragraph(); paragraph_6.setFont(new Font(FontFactory.getFont("Courier", 15, Font.BOLD, BaseColor.GRAY))); paragraph_6.add("\n GRAFICAS\n"); paragraph_6.setAlignment(Paragraph.ALIGN_CENTER); document.open(); //document.add(image); document.add(paragraph); document.add(paragraph_4); document.add(paragraph_5); document.add(paragraph_3); document.add(paragraph_6); Image image2 = Image.getInstance(project + "/" + project + "_PBP_NCF.png"); document.add(image1); document.add(image2); document.add(paragraph_2); document.close(); return null; }
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;/* w ww . j a v a 2s .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(); 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 . ja v a2 s . co 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;/* w w w .j av 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(); 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); }
From source file:client.welcome3.java
private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed Document doc = new Document(); PdfWriter docWriter = null;// w ww .ja va 2s . 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(); 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); }
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfDeSaida(ArrayList<Equipamento> equipamentos, String solicitante, String autorizante, String responsavel, String numeroSaida) { Document documento = new Document(); try {//ww w.ja v a2 s . co m Path path = Paths.get("\\files\\saidas.pdf"); if (!Files.isDirectory(path.getParent())) { Files.createDirectory(path.getParent()); Files.createFile(path); } PdfWriter pdf; pdf = PdfWriter.getInstance(documento, new FileOutputStream("\\files\\saidas.pdf")); documento.open(); documento.addTitle("SOLICITAO DE EQUIPAMENTOS E PRODUTOS"); /** * Responsavel pelo cabealho do documento */ Image imagem = Image.getInstance("atacadao.jpg"); imagem.setAlignment(Element.ALIGN_CENTER); documento.add(imagem); Paragraph titulo = new Paragraph("SOLICITAO DE EQUIPAMENTOS E PRODUTOS", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 16, 0, BaseColor.BLACK)); titulo.setAlignment(Element.ALIGN_CENTER); documento.add(titulo); documento.setMargins(0, 0, 18, 0); Date datas = new Date(); Locale local = new Locale("pt", "BR"); SimpleDateFormat sdf = new SimpleDateFormat("E dd/MM/yyyy", local); Paragraph espaco = new Paragraph( "\n\nDeclaro para os devidos fins que eu " + solicitante + " recebi na " + sdf.format(datas) + " os equipamentos abaixo relacionados da empresa " + "Atacado dos Pisos por " + autorizante + " e autorizado por " + responsavel + ".\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.BLACK)); documento.add(espaco); documento.add(new Paragraph("\n Numero de registro : " + numeroSaida + "\n\n")); /** * Responsavel por cria a tabela da sada dos equipamentos */ PdfPTable pdfT = new PdfPTable(4); PdfPCell celulas = new PdfPCell(new Paragraph( "Relao de equipamentos solicitados para seus devidos fins." + " Favor caso haja devoluo manter o maximo possvel do estado atual dos mesmos. Grato !!!", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 11, 0, BaseColor.GRAY))); celulas.setColspan(4); PdfPCell patrimonio = new PdfPCell(new Paragraph("PATRIMONIO", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); patrimonio.setBackgroundColor(BaseColor.GRAY); patrimonio.setPadding((float) 1); PdfPCell Nome = new PdfPCell(new Paragraph("NOME", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); Nome.setBackgroundColor(BaseColor.GRAY); Nome.setPadding((float) 1); PdfPCell Situacao = new PdfPCell(new Paragraph("SITUAO", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); Situacao.setBackgroundColor(BaseColor.GRAY); Situacao.setPadding((float) 1); PdfPCell valor = new PdfPCell(new Paragraph("DESTINO", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); valor.setBackgroundColor(BaseColor.GRAY); valor.setPadding((float) 1); pdfT.addCell(celulas); pdfT.addCell(patrimonio); pdfT.addCell(Nome); pdfT.addCell(Situacao); pdfT.addCell(valor); for (Equipamento equipamento : equipamentos) { PdfPCell patrimonios = new PdfPCell( new Paragraph(equipamento.getPatrimonio(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); patrimonios.setBackgroundColor(BaseColor.WHITE); Situacao.setPadding((float) 0.8); pdfT.addCell(patrimonios); PdfPCell nomes = new PdfPCell(new Paragraph(equipamento.getNome(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); nomes.setBackgroundColor(BaseColor.WHITE); nomes.setPadding((float) 0.8); pdfT.addCell(nomes); PdfPCell situacoes = new PdfPCell( new Paragraph(equipamento.getSituacao(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); situacoes.setBackgroundColor(BaseColor.WHITE); situacoes.setPadding((float) 0.8); pdfT.addCell(situacoes); PdfPCell valores = new PdfPCell(new Paragraph(equipamento.getCodigo(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); valores.setBackgroundColor(BaseColor.WHITE); valores.setPadding((float) 0.8); pdfT.addCell(valores); } documento.add(pdfT); /** * Cria tabela para assinatura do solicitante e autorizado */ PdfPTable pdfTs = new PdfPTable(5); Paragraph sol = new Paragraph("\n\n" + solicitante, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, Font.ITALIC)); sol.setAlignment(Element.ALIGN_CENTER); PdfPCell ass = new PdfPCell(sol); ass.setBorder(0); ass.setBorderWidthTop(1); ass.setColspan(2); PdfPCell espacos = new PdfPCell(); espacos.setBorder(0); Paragraph auth = new Paragraph("\n\n" + autorizante, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, Font.ITALIC)); auth.setAlignment(Element.ALIGN_CENTER); PdfPCell ass2 = new PdfPCell(auth); ass2.setBorder(0); ass2.setBorderWidthTop(1); ass2.setColspan(2); pdfTs.addCell(ass); pdfTs.addCell(espacos); pdfTs.addCell(ass2); documento.add(new Paragraph("\n\n\n")); documento.add(pdfTs); documento.close(); ImpressaoDeDocumentos imprimir = new ImpressaoDeDocumentos("\\files\\saidas.pdf"); // Desktop.getDesktop().open(new File("\\files\\saidas.pdf")); } catch (DocumentException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfImpressaoBarraDeCodigo(String codigo) { Document documento = new Document(new Rectangle(90, 65)); documento.setMargins(0, 0, 0, 0);//from w ww. j a v a 2s . co m PdfWriter pdf; try { pdf = PdfWriter.getInstance(documento, new FileOutputStream("codigodebarras.pdf")); documento.open(); PdfContentByte contB = pdf.getDirectContent(); Barcode128 barCode = new Barcode128(); barCode.setCode(codigo); barCode.setCodeType(Barcode128.CODE128); Image image = barCode.createImageWithBarcode(contB, BaseColor.BLACK, BaseColor.BLACK); Paragraph titulo = new Paragraph("ATCADO DOS PISOS\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 5)); titulo.setPaddingTop(0); titulo.setAlignment(Element.ALIGN_CENTER); float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin() - 0) / image.getWidth()) * 60; image.scalePercent(scaler); image.setPaddingTop(0); image.setAlignment(Element.ALIGN_CENTER); documento.add(titulo); documento.add(image); documento.close(); Desktop.getDesktop().open(new File("codigodebarras.pdf")); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * /*from w w w. ja v a 2 s. co m*/ * PDF Title Page * * @param doc * @param writer */ public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload) throws Exception { Font fnTitle = new Font(bfKorean, 20, Font.BOLD); Font fnLabel = new Font(bfKorean, 11, Font.BOLD); Font fnText = new Font(bfKorean, 11); LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5); doc.newPage(); doc.add(Chunk.NEWLINE); event.setTitleFlag(true); int toc = writer.getPageNumber(); Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif")); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); img.scalePercent(80, 80); doc.add(img); Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle); titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); titlePh.setSpacingBefore(50); titlePh.setSpacingAfter(30); doc.add(titlePh); doc.add(UNDERLINE); PdfPTable t1 = new PdfPTable(2); t1.setSpacingBefore(20); t1.setWidths(new int[] { 110, 290 }); t1.getDefaultCell().setBorder(0); t1.getDefaultCell().setFixedHeight(32); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel)); t1.addCell(new Phrase(upload.getProjectNm(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel)); t1.addCell(new Phrase(upload.getDepartment(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(), upload.getAfterWas()), fnText)); doc.add(t1); doc.add(UNDERLINE); Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel); executedPh.setSpacingBefore(30); executedPh.setSpacingAfter(15); executedPh.setIndentationLeft(50); doc.add(executedPh); PdfPTable t2 = new PdfPTable(2); t2.getDefaultCell().setFixedHeight(28); t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel)); t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t2.addCell(new Phrase(upload.getPerson(), fnText)); t2.addCell(new Phrase(upload.getOrgRole(), fnText)); doc.add(t2); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * // w ww.j a va 2 s .c o m * image * * @param section image section ? * @param e image element * @throws Exception */ public static void setImage(Section section, Element e) throws Exception { Image img = Image.getInstance(PDFDocGenerator.class.getResource(e.getText())); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); if (e.getAttributeValue("scale") != null) { float scale = Float.parseFloat(e.getAttributeValue("scale")); img.scalePercent(scale, scale); } section.add(img); }