List of usage examples for com.itextpdf.text Document newPage
public boolean newPage()
From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // build a controller SwingController controller = new SwingController(); // Build a SwingViewFactory configured with the controller SwingViewBuilder factory = new SwingViewBuilder(controller); // Use the factory to build a JPanel that is pre-configured //with a complete, active Viewer UI. JPanel viewerComponentPanel = factory.buildViewerPanel(); // add copy keyboard command ComponentKeyBinding.install(controller, viewerComponentPanel); // add interactive mouse link annotation support via callback controller.getDocumentViewController().setAnnotationCallback( new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController())); // Create a JFrame to display the panel in JFrame window = new JFrame("Using the Viewer Component"); window.getContentPane().add(viewerComponentPanel); window.pack();//from w w w .j ava 2 s . com window.setVisible(true); String Path; JFileChooser fr = new JFileChooser(); FileSystemView fw = fr.getFileSystemView(); // System.out.println(fw.getDefaultDirectory()); Path = fw.getDefaultDirectory() + "/reporter.pdf"; try { br1 = new BufferedReader(new FileReader(f)); BufferedReader b1 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } String line = ""; bull1 = new String[number_of_rows - 1][]; int k = 0; BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } try { while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); if (k != 0) { System.out.println(Bull.length); bull1[k - 1] = new String[Bull.length]; for (int j = 0; j < Bull.length; j++) { bull1[k - 1][j] = Bull[j]; } } k++; } } catch (IOException ex) { } Document doc = new Document(); PdfWriter docWriter = null; DecimalFormat df = new DecimalFormat("0.00"); try { //special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path)); //document header attributes doc.addAuthor("Shubh Chopra"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Shubh Chopra"); doc.addTitle("BES"); doc.setPageSize(PageSize.LETTER.rotate()); //open document doc.open(); //create a paragraph Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n"); paragraph.setFont(bfBold20); paragraph.setAlignment(Element.ALIGN_CENTER); Image img = Image.getInstance("VETMED.png"); img.scaleToFit(300f, 150f); doc.add(paragraph); PdfPTable table1 = new PdfPTable(2); table1.setWidthPercentage(100); PdfPCell cell = new PdfPCell(img); cell.setBorder(PdfPCell.NO_BORDER); table1.addCell(cell); String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64] + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: " + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); if (dlm3.size() == 1) { String str; str = dlm3.get(0).toString(); String[] parts = str.split(":"); String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; String[][] temp = new String[25][6]; temp[0][0] = "Tag"; temp[0][1] = bull1[row][7]; temp[0][2] = "Comments"; temp[0][3] = ""; temp[0][4] = "Total Count"; temp[0][5] = ""; temp[1][0] = "Tatoo"; temp[1][1] = bull1[row][8]; temp[1][2] = "All Normal"; temp[1][3] = "Yes"; temp[2][0] = "RFID"; temp[2][1] = bull1[row][6]; temp[2][2] = "Eyes"; temp[2][3] = bull1[row][10]; temp[3][0] = "Lot#"; temp[3][1] = bull1[row][5]; temp[3][2] = "Feet"; temp[3][3] = bull1[row][12]; temp[4][0] = "Brand"; temp[4][1] = bull1[row][2]; temp[4][2] = "Legs"; temp[4][3] = bull1[row][14]; temp[5][0] = "Date of Birth"; temp[5][1] = bull1[row][4]; temp[5][2] = "Testicals"; temp[5][3] = bull1[row][16]; temp[6][0] = "Age"; temp[6][1] = bull1[row][0]; temp[6][2] = "Accessory Sex Glands"; temp[6][3] = bull1[row][18]; temp[7][0] = "Breed"; temp[7][1] = bull1[row][3]; temp[7][2] = "Inguinal"; temp[7][3] = bull1[row][20]; temp[8][0] = "Other"; temp[8][1] = bull1[row][9]; temp[8][2] = "Scrotal"; temp[8][3] = bull1[row][22]; temp[9][0] = "Clinic Info"; temp[9][1] = "xx"; temp[9][2] = "Epidydimides"; temp[9][3] = bull1[row][24]; temp[10][4] = "Measurements"; temp[10][5] = "xx"; temp[10][0] = "Clinic Name"; temp[10][1] = bull1[row][73]; temp[10][2] = "Penis"; temp[10][3] = bull1[row][26]; temp[11][4] = "Scrotal Cirumference"; temp[11][5] = bull1[row][54]; temp[11][0] = "Veterinarian Name"; temp[11][1] = bull1[row][74] + " " + bull1[row][75]; temp[11][2] = "Prepuce"; temp[11][3] = bull1[row][28]; temp[12][4] = "Body Condition"; temp[12][5] = bull1[row][47]; temp[12][0] = "Address"; temp[12][1] = bull1[row][66] + " " + bull1[row][67]; temp[12][2] = "Scrotum"; temp[12][3] = bull1[row][30]; temp[13][4] = "Pelvic X Measure"; temp[13][5] = bull1[row][52]; temp[13][0] = "City"; temp[13][1] = bull1[row][68]; temp[13][2] = "Sex Drive"; temp[13][3] = "xx"; temp[14][4] = "Pelvic Y Measure"; temp[14][5] = bull1[row][53]; temp[14][0] = "State"; temp[14][1] = bull1[row][71]; temp[14][2] = "Breeding seasons used"; temp[14][3] = bull1[row][40]; temp[15][4] = "Hip Hight"; temp[15][5] = bull1[row][50]; temp[15][0] = "Zip Code"; temp[15][1] = bull1[row][72]; temp[15][2] = "Performance last season"; temp[15][3] = bull1[row][38]; temp[16][4] = "Frame Score"; temp[16][5] = bull1[row][49]; temp[16][0] = "Email"; temp[16][1] = bull1[row][69]; temp[16][2] = "Single or Multi sire"; temp[16][3] = bull1[row][41]; temp[17][4] = "Other"; temp[17][5] = bull1[row][48]; temp[17][0] = "Phone"; temp[17][1] = bull1[row][70]; temp[17][2] = "Other"; temp[17][3] = bull1[row][39]; temp[18][4] = "Motility"; temp[18][5] = "xx"; temp[18][0] = "Classification"; temp[18][1] = bull1[row][35]; temp[18][2] = "Comments"; temp[18][3] = bull1[row][37]; temp[19][4] = "Individual Motility"; temp[19][5] = bull1[row][45]; temp[19][0] = "Comments"; temp[19][1] = bull1[row][36]; temp[19][2] = ""; temp[19][3] = ""; temp[20][4] = "Motility %"; temp[20][5] = bull1[row][46]; temp[20][0] = ""; temp[20][1] = ""; temp[20][2] = ""; temp[20][3] = ""; temp[21][4] = "Gross Motility"; temp[21][5] = bull1[row][44]; temp[21][0] = ""; temp[21][1] = ""; temp[21][2] = ""; temp[21][3] = ""; for (int i = 9; i <= 29; i += 2) { if (bull1[row][i].equals("FALSE")) { temp[1][4] = "No"; break; } } int i; int total = 0; for (i = 77; i < header.length && i < bull1[row].length; i++) { temp[i - 76][4] = header[i].split("_")[1]; temp[i - 76][5] = bull1[row][i]; total += Integer.parseInt(bull1[row][i]); } temp[0][5] = Integer.toString(total); for (int j = i; j <= 85; j++) { temp[j - 76][4] = ""; temp[j - 76][5] = ""; } PdfPTable table = new PdfPTable(6); PdfPCell cell11, cell12, cell13; cell11 = new PdfPCell(new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell11.setColspan(2); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell11); cell12 = new PdfPCell( new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell12.setColspan(2); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell12); cell13 = new PdfPCell(new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell13.setColspan(2); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell13); for (int l = 0; l <= 21; l++) { for (int j = 0; j < 6; j++) { // System.out.println(l+" "+j); if (!temp[l][j].equals("xx") && temp[l][j] != null) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10))); cell.setBorder(PdfPCell.NO_BORDER); if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4) || (l == 18 && j == 4)) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); } table.addCell(cell); } } } table.setWidthPercentage(90f); Reporter re; re = new Reporter(); doc.add(table); if (jCheckBox2.isSelected() || jCheckBox1.isSelected()) doc.newPage(); } else { //specify column widths int temp = dlm2.size(); float[] columnWidths = new float[temp]; for (int x = 0; x < columnWidths.length; x++) { columnWidths[x] = 2f; } //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(90f); Reporter re; re = new Reporter(); re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12); for (int i = 0; i < dlm2.size(); i++) { String[] parts = dlm2.get(i).toString().split(": "); String part2 = parts[1]; re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12); } table.setHeaderRows(1); //insert an empty row //create section heading by cell merging //just some random data to fill for (int x = 0; x < dlm3.size(); x++) { String str = dlm3.get(x).toString(); //System.out.println(str); String[] parts = str.split(":"); String part2 = parts[1]; // System.out.println(part2); int row = Integer.parseInt(part2) - 1; re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12); for (int i = 0; i < dlm2.getSize(); i++) { for (int j = 0; j < header.length && j < bull1[row].length; j++) { String str1 = dlm2.get(i).toString(); String[] p1 = str1.split(": "); String p2 = p1[0]; if (p2.equals(header[j])) { re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12); } } } // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12); } doc.add(table); } if (jCheckBox2.isSelected()) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < dlm3.size(); i++) { String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1); } else { dataSet.setValue(0, "Percent", header[j]); } } } JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false); if (dlm3.size() > 12) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } if (jCheckBox1.isSelected()) { for (int i = 0; i < dlm3.size(); i++) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2); } else { dataSet.setValue(0, "Percent", header[j]); } } JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1, "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); doc.newPage(); } } } catch (DocumentException dex) { dex.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } controller.openDocument(Path); }
From source file:eeebees.PDFGen.java
public static void main(String[] args) { try {/* www. j a va2 s. c o m*/ OutputStream file = new FileOutputStream(new File("D:\\PDF_Java4s.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); //Inserting Image in PDF //Image image = Image.getInstance ("src/pdf/java4s.png"); //image.scaleAbsolute(120f, 60f);//image width,height //Inserting Table in PDF PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Paragraph("Java4s.com")); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("Name"); table.addCell("Address"); table.addCell("Country"); table.addCell("Java4s"); table.addCell("NC"); table.addCell("United States"); table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(30.0f); // Space After table starts, like margin-Bottom in CSS //Inserting List in PDF List list = new List(true, 30); list.add(new ListItem("Java4s")); list.add(new ListItem("Php4s")); list.add(new ListItem("Some Thing...")); //Text formating in PDF Chunk chunk = new Chunk("Welecome To Java4s Programming Blog..."); chunk.setUnderline(+1f, -2f);//1st co-ordinate is for line width,2nd is space between Chunk chunk1 = new Chunk("Php4s.com"); chunk1.setUnderline(+4f, -8f); chunk1.setBackground(new BaseColor(17, 46, 193)); //Now Insert Every Thing Into PDF Document document.open();//PDF document opened........ //document.add(image); document.add(Chunk.NEWLINE); //Something like in HTML :-) document.add(new Paragraph("Dear Java4s.com")); document.add(new Paragraph("Document Generated On - " + new Date().toString())); document.add(table); document.add(chunk); document.add(chunk1); document.add(Chunk.NEWLINE); //Something like in HTML :-) document.newPage(); //Opened new page document.add(list); //In the new page we are going to add list document.close(); file.close(); System.out.println("Pdf created successfully.."); } catch (Exception e) { e.printStackTrace(); } }
From source file:employee.payroll.system.searchEmpSalarySlip.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String value = txt_firstname.getText(); String value0 = txt_surname.getText(); String value1 = txt_id.getText(); String value2 = txt_desig.getText(); String value3 = txt_desig.getText(); JFileChooser dialog = new JFileChooser(); dialog.setSelectedFile(new File(value + " " + value0 + "-Salary Slip" + ".pdf")); int dialogResult = dialog.showSaveDialog(null); if (dialogResult == JFileChooser.APPROVE_OPTION) { String filePath = dialog.getSelectedFile().getPath(); try {//w w w . j av a 2s . c o m // TODO add your handling code here: String sql = "select * from Deductions where emp_id = '" + value1 + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); String val = rs.getString(5); String reason = rs.getString(6); rs.close(); pst.close(); String sq = "select * from Allowance where emp_id = '" + value1 + "'"; pst = conn.prepareStatement(sq); rs = pst.executeQuery(); int calcTotal = Integer.parseInt(txt_salary.getText()); float x = Float.valueOf(rs.getString(9)); int v = Integer.parseInt(val); float total = calcTotal + x - v; Document myDocument = new Document(); PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath)); myDocument.open(); myDocument .add(new Paragraph("PAY SLIP", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD))); myDocument.add(new Paragraph(new Date().toString())); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.add((new Paragraph("EMPLOYEE DETAILS", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD)))); myDocument.add((new Paragraph("Name of Employee: " + value + " " + value0, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN)))); myDocument.add((new Paragraph("Designation: " + value2, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN)))); myDocument.add((new Paragraph("Department: " + value3, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN)))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument .add(new Paragraph("SALARY", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD))); myDocument.add(new Paragraph("Basic Salary: $" + calcTotal, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Overtime: " + rs.getString(2) + " Hours", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Medical: $" + rs.getString(3), FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Bonus: $" + rs.getString(4), FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Other: $" + rs.getString(5), FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.add( new Paragraph("DEDUCTION", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD))); myDocument.add(new Paragraph("Deduction Details: " + reason, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Total Deductions : $" + val, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.add(new Paragraph("TOTAL PAYMENT", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD))); myDocument.add(new Paragraph("Total Earnings: " + rs.getString(9), FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Net Pay : " + total, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.newPage(); myDocument.close(); JOptionPane.showMessageDialog(null, "Report was successfully generated"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } }
From source file:employeepayroll.Searchempsalary.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String value = txt_fname.getText(); String value0 = txt_sname.getText(); int value1 = parseInt(txt_id.getText()); String value2 = txt_dest.getText(); String value3 = txt_dept.getText(); String overtime = " "; String medical = " "; String bonus = " "; String other = " "; String earnings = " "; JFileChooser dialog = new JFileChooser(); dialog.setSelectedFile(new File(value + " " + value0 + "-SalarySlip" + ".pdf")); int dialogResult = dialog.showSaveDialog(null); if (dialogResult == JFileChooser.APPROVE_OPTION) { String filePath = dialog.getSelectedFile().getPath(); try {/*from www. j a v a2s. co m*/ String sql = "select * from deductions where emp_id =" + value1; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { val = rs.getString(5); reason = rs.getString(6); v = Integer.parseInt(val); } rs.close(); pst.close(); String sql2 = "select * from allowance where emp_id =" + value1; pst = conn.prepareStatement(sql2); rs = pst.executeQuery(); while (rs.next()) { x = Float.valueOf(rs.getString(9)); overtime = rs.getString(2); medical = rs.getString(3); bonus = rs.getString(4); other = rs.getString(5); earnings = rs.getString(9); } //v = Integer.parseInt(val); int calcTotal = Integer.parseInt(txt_sal.getText()); float total = calcTotal + x - v; Document myDocument = new Document(); PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath)); myDocument.open(); myDocument .add(new Paragraph("PAY SLIP", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD))); myDocument.add(new Paragraph(new Date().toString())); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.add((new Paragraph("EMPLOYEE DETAILS", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD)))); myDocument.add((new Paragraph("Name of Employee: " + value + " " + value0, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN)))); myDocument.add((new Paragraph("Designation: " + value2, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN)))); myDocument.add((new Paragraph("Department: " + value3, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN)))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument .add(new Paragraph("SALARY", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD))); myDocument.add(new Paragraph("Basic Salary: $" + calcTotal, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Overtime: " + overtime + " Hours", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Medical: $" + medical, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Bonus: $" + bonus, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Other: $" + other, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.add( new Paragraph("DEDUCTION", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD))); myDocument.add(new Paragraph("Deduction Details: " + reason, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Total Deductions : $" + val, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.add(new Paragraph("TOTAL PAYMENT", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD))); myDocument.add(new Paragraph("Total Earnings: " + earnings, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph("Net Pay : " + total, FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.PLAIN))); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); myDocument.newPage(); myDocument.close(); JOptionPane.showMessageDialog(null, "Report was successfully generated"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e + "\n creating report problem 00x333"); } finally { try { rs.close(); pst.close(); } catch (SQLException e) { JOptionPane.showMessageDialog(null, e + "/n creating report problem 00x341"); } } } }
From source file:engine.Pdf.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);/*from w w w . j av a 2s . c o m*/ // Lets write a big header preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement.", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:es.jscan.Pantallas.PantallaPrincipal.java
License:Apache License
@Action public Boolean guardarPdf() { if (contimagen < 1) { return false; }/*www . j ava2 s . co m*/ final PantallaBarra pantbarra = new PantallaBarra(PantallaPrincipal.this, false); pantbarra.setTitle("Generando fichero de destino"); pantbarra.botonParar.setVisible(false); errorpdf = false; new Thread() { @Override public void run() { Document pdfDocument = new Document(); // Document pdfDocument = new Document(PageSize.A4, 0, 0, 0, 0); Calendar cal = Calendar.getInstance(); String anio = String.valueOf(cal.get(Calendar.YEAR)); String mes = String.valueOf((cal.get(Calendar.MONTH) + 1)).length() == 1 ? "0" + String.valueOf((cal.get(Calendar.MONTH) + 1)) : String.valueOf((cal.get(Calendar.MONTH) + 1)); String dia = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)).length() == 1 ? "0" + String.valueOf(cal.get(Calendar.DAY_OF_MONTH)) : String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); String hora = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)).length() == 1 ? "0" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY)) : String.valueOf(cal.get(Calendar.HOUR_OF_DAY)); String minuto = String.valueOf(cal.get(Calendar.MINUTE)).length() == 1 ? "0" + String.valueOf(cal.get(Calendar.MINUTE)) : String.valueOf(cal.get(Calendar.MINUTE)); String segundo = String.valueOf(cal.get(Calendar.SECOND)).length() == 1 ? "0" + String.valueOf(cal.get(Calendar.SECOND)) : String.valueOf(cal.get(Calendar.SECOND)); try { if (DEBUG) { Utilidades.escribeLog("Generando PDFs -guardarPdf-"); } if (contimagen < 2) { pantbarra.barra.setMinimum(1); pantbarra.barra.setMaximum(2); } else { pantbarra.barra.setMinimum(1); pantbarra.barra.setMaximum(rutaboton.length); } pantbarra.barra.setValue(1); pantbarra.setTitle(pantbarra.getTitle()); pantbarra.validate(); String nombrefichero = "Documentacion.pdf"; String ruta = rutalote + separador + nombrefichero + ".pdf"; if (!textoFichero.getText().isEmpty()) { nombrefichero = textoFichero.getText() + ".pdf"; } if (!textoDirectorio.getText().isEmpty()) { ruta = textoDirectorio.getText(); ruta = ruta + separador + nombrefichero; } FileOutputStream ficheroPdf = new FileOutputStream(ruta); File filename = new File(rutaboton[0].toString()); java.awt.image.BufferedImage imagen = javax.imageio.ImageIO.read(filename); com.itextpdf.text.Image imagenpdf = com.itextpdf.text.Image.getInstance(imagen, null); pdfDocument.setPageSize(new Rectangle(imagenpdf.getWidth(), imagenpdf.getHeight())); PdfWriter writer = PdfWriter.getInstance(pdfDocument, ficheroPdf); writer.open(); pdfDocument.open(); pdfDocument.addHeader("IP", lote.substring(16, 19) + "." + lote.substring(19, 22) + "." + lote.substring(22, 25) + "." + lote.substring(25, 28)); pdfDocument.addHeader("fechadigita", lote.substring(6, 8) + "/" + lote.substring(4, 6) + "/" + lote.substring(0, 4) + " " + lote.substring(9, 11) + ":" + lote.substring(11, 13) + ":" + lote.substring(13, 15)); pdfDocument.addHeader("fechacreacion", dia + "/" + mes + "/" + anio + " " + hora + ":" + minuto + ":" + segundo); for (int i = 0; i < rutaboton.length; i++) { filename = new File(rutaboton[i].toString()); imagen = javax.imageio.ImageIO.read(filename); imagenpdf = com.itextpdf.text.Image.getInstance(imagen, null); // imagenpdf.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); // imagenpdf.setAlignment(com.itextpdf.text.Image.ALIGN_JUSTIFIED_ALL); // com.itextpdf.text.Image instance = com.itextpdf.text.Image.getInstance(imagenpdf); // pdfDocument.setPageSize(new com.itextpdf.text.Rectangle(PageSize.A4.getWidth(), PageSize.A4.getHeight())); pantbarra.barra.setValue(i); pantbarra.setTitle(titulo + " " + (i + 1) + " de " + rutaboton.length); pdfDocument.setPageSize(new Rectangle(imagenpdf.getWidth(), imagenpdf.getHeight())); // pdfDocument.add(instance); pdfDocument.add(imagenpdf); pdfDocument.newPage(); pantbarra.validate(); } pdfDocument.close(); writer.close(); } catch (Exception e) { Utilidades.escribeLog("Error Generando PDFs -guardarPdf- " + e.getMessage()); errorpdf = true; } pantbarra.dispose(); } }.start(); pantbarra.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); pantbarra.setVisible(false); pantbarra.setVisible(true); return !errorpdf; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.PdfGenerator.java
License:Open Source License
private int createPdf(OutputStream os, int indexSize, IProgressMonitor monitor) throws DocumentException, IOException { Document document = new Document(PageSize.A4, MARGIN_LEFT, MARGIN_RIGHT, MARGIN_UP, MARGIN_DOWN); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setStrictImageSequence(true); writer.setLinearPageMode();// used to reorder page; // writer.setPdfVersion(PdfWriter.PDF_VERSION_1_6); ChapterSectionTOC event = new ChapterSectionTOC(); writer.setPageEvent(event);/*from w ww . java 2 s. c o m*/ event.pagenumber = rcf.startingPageNumber(); writer.setBoxSize("art", new Rectangle(MARGIN_LEFT, 0, PageSize.A4.getWidth() - MARGIN_RIGHT, FOOTER_HEIGHT)); monitor.beginTask("Generating Report", 100); document.open(); rcf.buildContent(writer, document, new SubProgressMonitor(monitor, 85)); if (rcf.buildIndex()) { document.newPage(); event.setIndex(true); int toc = writer.getPageNumber(); buildIndex(writer, document); document.newPage(); monitor.worked(10); int total = writer.reorderPages(null); int tocLenght = total - toc + 1; int[] order = new int[total]; order[0] = 1; for (int i = 0; i < tocLenght; i++) { order[i + 1] = toc + i; } for (int i = 2; i < toc; i++) { order[i + tocLenght - 1] = i; } writer.reorderPages(order); document.close(); monitor.worked(5); return tocLenght; } return -1; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
public void buildContent(PdfWriter writer, Document document, IProgressMonitor monitor) { monitor.beginTask("Generating Report", 100); try {/*from w w w . jav a2 s . co m*/ buildFirstPage(writer, document); document.newPage(); monitor.worked(1); int chapNum = 1; if (genrateIntroductionChapter()) { Chapter c = new Chapter(chapNum++); buildIntorductionChapter(c); document.add(c); c.setComplete(true); } monitor.worked(9); if (generateSocialViewChapter()) { Chapter c = new Chapter(chapNum++); buildSocialViewChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateInformationViewChapter()) { Chapter c = new Chapter(chapNum++); buildInformationViewChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateAuthorisationViewChapter()) { Chapter c = new Chapter(chapNum++); buildAuthorisationViewChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateSecurityRequirementsChapter()) { Chapter c = new Chapter(chapNum++); buildSecurityRequirementsChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateAnalysisChapter()) { Chapter c = new Chapter(chapNum++); buildAnalysisChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateAppendixAChapter()) { Chapter c = new Chapter(chapNum++); buildAppendixAChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateAppendixBChapter()) { Chapter c = new Chapter(chapNum++); buildAppendixBChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateAppendixCChapter()) { Chapter c = new Chapter(chapNum++); buildAppendixCChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); if (generateAppendixDChapter()) { Chapter c = new Chapter(chapNum++); buildAppendixDChapter(c, document); document.add(c); c.setComplete(true); } monitor.worked(10); } catch (DocumentException e) { e.printStackTrace(); } finally { if (monitor != null) monitor.done(); } }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
public void processNote(Document document, Note note, int count) throws Exception { String name = Utilities.makeXmlSafe(note.getName()); String form = note.getForm(); DaoImages daoImages = new DaoImages(); if (form != null && form.length() > 0) { JSONObject sectionObject = new JSONObject(form); if (!sectionObject.has(FormUtilities.ATTR_SECTIONNAME)) { return; }/*www . j a v a 2s. c o m*/ String sectionName = sectionObject.getString(FormUtilities.ATTR_SECTIONNAME); Anchor anchor = new Anchor(sectionName); anchor.setName(sectionName); Chapter currentChapter = new Chapter(new Paragraph(anchor), count); addEmptyLine(currentChapter, 3); PdfPTable infoTable = new PdfPTable(2); infoTable.setHeaderRows(0); infoTable.setWidthPercentage(90); currentChapter.add(infoTable); addKeyValueToTableRow(infoTable, "Timestamp", new Date(note.getTimeStamp()).toString()); addKeyValueToTableRow(infoTable, "Latitude", note.getLat() + ""); addKeyValueToTableRow(infoTable, "Longitude", note.getLon() + ""); addEmptyLine(currentChapter, 3); List<String> formsNames = TagsManager.getFormNames4Section(sectionObject); for (String formName : formsNames) { Paragraph section = new Paragraph(formName); currentChapter.addSection(section); addEmptyLine(currentChapter, 3); PdfPTable currentTable = new PdfPTable(2); currentTable.setHeaderRows(1); currentTable.setWidthPercentage(90); currentChapter.add(currentTable); JSONObject form4Name = TagsManager.getForm4Name(formName, sectionObject); JSONArray formItems = TagsManager.getFormItems(form4Name); for (int i = 0; i < formItems.length(); i++) { JSONObject formItem = formItems.getJSONObject(i); if (!formItem.has(FormUtilities.TAG_KEY)) { continue; } String type = formItem.getString(FormUtilities.TAG_TYPE); String key = formItem.getString(FormUtilities.TAG_KEY); String value = formItem.getString(FormUtilities.TAG_VALUE); String label = key; if (formItem.has(FormUtilities.TAG_LABEL)) { label = formItem.getString(FormUtilities.TAG_LABEL); } if (type.equals(FormUtilities.TYPE_PICTURES)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else if (type.equals(FormUtilities.TYPE_MAP)) { if (value.trim().length() == 0) { continue; } String imageId = value.trim(); Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } else if (type.equals(FormUtilities.TYPE_SKETCH)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else { addKeyValueToTableRow(currentTable, label, value); } } } document.add(currentChapter); document.newPage(); } }
From source file:eu.trentorise.smartcampus.citizenportal.service.PdfCreator.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);//ww w. ja v a 2s .co m // Lets write a big header preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }