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:Controller.Receipt.Controller_FXML_Receipt.java
public void createReceipt(String filename, String patientid) throws DocumentException, IOException, PrinterException { {/* ww w .j a v a2s . c o m*/ //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. Document document = new Document(); String receipt_id = null; String patientname = null; String date = null; String total_sum = null; try { try { PdfWriter.getInstance(document, new FileOutputStream(filename)); } catch (FileNotFoundException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } document.open(); Font font = new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD); //getFont("c:/windows/fonts/Shruti.ttf", //BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); //document.add(new Paragraph("english",font)); com.itextpdf.text.Image img = null; // try { // img = com.itextpdf.text.Image.getInstance("C:"); // img.scalePercent(80f); // } catch (BadElementException ex) { // Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); // } catch (IOException ex) { // Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); // } /*try { document.add(img); } catch (DocumentException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); }*/ Paragraph title = new Paragraph("RECEIPT", font); Paragraph header = new Paragraph("SHARDA HOSPITAL"); header.setAlignment(Element.ALIGN_CENTER); title.setAlignment(Element.ALIGN_CENTER); Paragraph receiptid = new Paragraph("R.No" + receipt_id, font); receiptid.setAlignment(Element.ALIGN_LEFT); Paragraph Date = new Paragraph("Date :" + date, font); Date.setAlignment(Element.ALIGN_RIGHT); try { document.add(header); } catch (DocumentException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } try { document.add(title); } catch (DocumentException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } try { document.add(receiptid); } catch (DocumentException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } try { document.add(Date); } catch (DocumentException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } String DOJ = null; String diagnosis = null; String no_of_days = null; String DOD = null; Paragraph patient_details = new Paragraph("Received " + total_sum + "from Mr./Mrs. " + patientname + " towards indoor/outdoor charges detailed as below." + " He/She was admitted in hospital/under treatment from" + DOJ + "to " + DOD + ". He/She is suffering from " + diagnosis + "." + " He/She has to take future medicie for" + no_of_days + ".", font); try { document.add(patient_details); } catch (DocumentException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Chaitanya"); Object newValue = null; //Check whether item is selected and set value of selected item to Label if (table.getSelectionModel().getSelectedItem() != null) { TableView.TableViewSelectionModel selectionModel = table.getSelectionModel(); ObservableList selectedCells = selectionModel.getSelectedCells(); TablePosition tablePosition = (TablePosition) selectedCells.get(0); Object val1 = tablePosition.getTableColumn().getCellData(newValue); System.out.println("Fee Type Value" + val1); TablePosition tablePosition1 = (TablePosition) selectedCells.get(1); Object val2 = tablePosition1.getTableColumn().getCellData(newValue); System.out.println("Charges Value" + val2); } document.close(); String pdfFile = "report.pdf"; try { printPDF(pdfFile); } catch (IOException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } catch (PrinterException ex) { Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:crearpdf.CrearPDF.java
private void crearReportePDForacle(String select) throws Exception { Class.forName("oracle.jdbc.OracleDriver"); //Invocamos el Driver de Oracle Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "willson"/*usuario*/, "123456"/*contrasea*/); //Creamos la conexion para acceder a la base de datos Statement stmt = con.createStatement(); ResultSet resultados = stmt.executeQuery(select); //Hacemos el select de la info que extraeremos de la base de datos Document reportePDF = new Document(PageSize.LETTER, 88, 88, 80, 15); //Creamos un nuevo Documento usando la libreria itextpdf importada. PdfWriter.getInstance(reportePDF, new FileOutputStream("REPORTE.pdf"));//Instanciamos y creamos el archivo reportePDF.open(); //Abrimos el archivo creado arriba. Paragraph parrafo = new Paragraph("Reporte del dia"); parrafo.add("Este es el repote que nos da los datos"); parrafo.setAlignment(Element.ALIGN_CENTER); PdfPTable Treportes = new PdfPTable(5);//Aqui asignamos el numero de columnas que tendra la tabla, en este casi 5. PdfPCell celdas_tabla;//Creamos las celdas que seran llenadas con los datos extraidos //Agregamos los titulos de cada Columna Treportes.addCell("ID"); Treportes.addCell("Nombre"); Treportes.addCell("Edad"); Treportes.addCell("Mes Nacimiento"); Treportes.addCell("Universidad"); //ciclo para empezar a aadir los datos de la base de datos a las celdas correspondientes en el PDF ///System.out.println("Llenando pdf"); while (resultados.next()) { String id = resultados.getString("ID"); celdas_tabla = new PdfPCell(new Phrase(id)); Treportes.addCell(celdas_tabla); String nombre = resultados.getString("NOMBRE"); celdas_tabla = new PdfPCell(new Phrase(nombre)); Treportes.addCell(celdas_tabla); String edad = resultados.getString("EDAD"); celdas_tabla = new PdfPCell(new Phrase(edad)); Treportes.addCell(celdas_tabla); String nacimiento = resultados.getString("MES_NACIMIENTO"); celdas_tabla = new PdfPCell(new Phrase(nacimiento)); Treportes.addCell(celdas_tabla); String universidad = resultados.getString("UNIVERSIDAD"); celdas_tabla = new PdfPCell(new Phrase(universidad)); Treportes.addCell(celdas_tabla); //System.out.println(id+" "+nombre+" "+edad); }//from ww w . j a v a2 s .c om // System.out.println("Listo!"); parrafo.add(Treportes); reportePDF.add(parrafo); //reportePDF.add(Treportes); //Insertamos los datos de la tabla en el PDF. reportePDF.close(); //Cerramos el archivo PDF una vez completado //Cerrar todas las conexiones resultados.close(); stmt.close(); con.close(); }
From source file:crearpdf.CrearPDF.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.OracleDriver"); //Invocamos el Driver de Oracle Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "willson"/*usuario*/, "123456"/*contrasea*/); //Creamos la conexion para acceder a la base de datos Statement stmt = con.createStatement(); ResultSet resultados = stmt/* w w w. j a v a 2 s . c om*/ .executeQuery("SELECT ID, NOMBRE, EDAD, MES_NACIMIENTO, UNIVERSIDAD FROM PERSONAS"); //Hacemos el select de la info que extraeremos de la base de datos Document reportePDF = new Document(PageSize.B4, 88, 88, 80, 15); //Creamos un nuevo Documento usando la libreria itextpdf importada. PdfWriter.getInstance(reportePDF, new FileOutputStream("REPORTE.pdf"));//Instanciamos y creamos el archivo reportePDF.open(); //Abrimos el archivo creado arriba. Paragraph parrafo = new Paragraph("Reporte del dia"); parrafo.setAlignment(Element.ALIGN_CENTER); PdfPTable Treportes = new PdfPTable(5);//Aqui asignamos el numero de columnas que tendra la tabla, en este casi 5. PdfPCell celdas_tabla;//Creamos las celdas que seran llenadas con los datos extraidos //Agregamos los titulos de cada Columna Treportes.addCell("ID"); Treportes.addCell("Nombre"); Treportes.addCell("Edad"); Treportes.addCell("Mes Nacimiento"); Treportes.addCell("Universidad"); //ciclo para empezar a aadir los datos de la base de datos a las celdas correspondientes en el PDF System.out.println("Llenando pdf"); while (resultados.next()) { String id = resultados.getString("ID"); celdas_tabla = new PdfPCell(new Phrase(id)); Treportes.addCell(celdas_tabla); String nombre = resultados.getString("NOMBRE"); celdas_tabla = new PdfPCell(new Phrase(nombre)); Treportes.addCell(celdas_tabla); String edad = resultados.getString("EDAD"); celdas_tabla = new PdfPCell(new Phrase(edad)); Treportes.addCell(celdas_tabla); String nacimiento = resultados.getString("MES_NACIMIENTO"); celdas_tabla = new PdfPCell(new Phrase(nacimiento)); Treportes.addCell(celdas_tabla); String universidad = resultados.getString("UNIVERSIDAD"); celdas_tabla = new PdfPCell(new Phrase(universidad)); Treportes.addCell(celdas_tabla); System.out.println(id + " " + nombre + " " + edad); } System.out.println("Listo!"); reportePDF.add(parrafo); reportePDF.add(Treportes); //Insertamos los datos de la tabla en el PDF. reportePDF.close(); //Cerramos el archivo PDF una vez completado //Cerrar todas las conexiones resultados.close(); stmt.close(); con.close(); }
From source file:crs.Manager_DailyReturnController.java
@FXML private void onDownload(ActionEvent event) { if (report_datepicker.getValue() == null) return;/* ww w .j a va 2 s . c om*/ String date = report_datepicker.getValue().toString(); Vlist = CRS.getDailyReturn(date, -1); bdata = getDailyReturnByBranch(date); cdata = getReturnByCategory(date); String filename = report_datepicker.getValue().toString() + "_DailyRental.pdf"; DirectoryChooserBuilder builder = DirectoryChooserBuilder.create(); builder.title("Hello World"); String cwd = System.getProperty("user.dir"); File file = new File(cwd); builder.initialDirectory(file); DirectoryChooser chooser = builder.build(); File chosenDir = chooser.showDialog(null); if (chosenDir != null) { System.out.println(chosenDir.getAbsolutePath()); } else { System.out.print("no directory chosen"); } Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename)); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add("Daily Return Report of " + report_datepicker.getValue().toString()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(40); document.add(paragraph); document.add(createPDFTableVehicle(Vlist)); paragraph.clear(); paragraph.add(" "); paragraph.setSpacingAfter(20); document.add(paragraph); document.add(createPDFTableByCategory(cdata)); paragraph.setSpacingAfter(20); document.add(paragraph); document.add(createPDFTableByBranch(bdata)); document.close(); label_result.setText("Download successfully"); label_result.setVisible(true); } catch (FileNotFoundException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:crs.Manager_Report_bybranchController.java
@FXML private void onDownload(ActionEvent event) { if (report_datepicker.getValue() == null || combo_loc.getValue() == null) return;/* ww w . j a v a 2 s. c o m*/ String date = report_datepicker.getValue().toString(); bid = getBranchid(combo_loc.getValue().toString()); Vlist = CRS.getDailyRental(date, bid); cdata = getRentalByCategory(date); String filename = report_datepicker.getValue().toString() + "_DailyRental_" + combo_loc.getValue().toString() + ".pdf"; DirectoryChooserBuilder builder = DirectoryChooserBuilder.create(); builder.title("Hello World"); String cwd = System.getProperty("user.dir"); File file = new File(cwd); builder.initialDirectory(file); DirectoryChooser chooser = builder.build(); File chosenDir = chooser.showDialog(null); if (chosenDir != null) { System.out.println(chosenDir.getAbsolutePath()); } else { System.out.print("no directory chosen"); } Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename)); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add("Daily Report of " + report_datepicker.getValue().toString() + " location: " + combo_loc.getValue().toString()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(40); document.add(paragraph); document.add(createPDFTableVehicle(Vlist)); paragraph.clear(); paragraph.add(" "); paragraph.setSpacingAfter(20); document.add(paragraph); document.add(createPDFTableByCategory(cdata)); document.close(); label_result.setText("Download successfully"); label_result.setVisible(true); } catch (FileNotFoundException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:crs.Manager_Report_DailyController.java
@FXML private void onDownload(ActionEvent event) { if (report_datepicker.getValue() == null) return;/* w w w . j a v a 2s.com*/ String filename = report_datepicker.getValue().toString() + "_DailyRental.pdf"; DirectoryChooserBuilder builder = DirectoryChooserBuilder.create(); builder.title("Hello World"); String cwd = System.getProperty("user.dir"); File file = new File(cwd); builder.initialDirectory(file); DirectoryChooser chooser = builder.build(); File chosenDir = chooser.showDialog(null); if (chosenDir != null) { System.out.println(chosenDir.getAbsolutePath()); } else { System.out.print("no directory chosen"); } Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename)); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add("Daily Report of " + report_datepicker.getValue().toString()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(40); document.add(paragraph); document.add(createPDFTableVehicle(Vlist)); paragraph.clear(); paragraph.add(" "); paragraph.setSpacingAfter(20); document.add(paragraph); document.add(createPDFTableByCategory(cdata)); paragraph.setSpacingAfter(20); document.add(paragraph); document.add(createPDFTableByBranch(bdata)); document.close(); label_result.setText("Download successfully"); label_result.setVisible(true); } catch (FileNotFoundException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:crs.Manager_ReturnbybranchController.java
@FXML private void onDownload(ActionEvent event) { if (report_datepicker.getValue() == null || combo_loc.getValue() == null) return;//from ww w. ja v a2s . c om String date = report_datepicker.getValue().toString(); bid = getBranchid(combo_loc.getValue().toString()); Vlist = CRS.getDailyReturn(date, bid); cdata = getReturnByCategory(date); String filename = report_datepicker.getValue().toString() + "_DailyRental_" + combo_loc.getValue().toString() + ".pdf"; DirectoryChooserBuilder builder = DirectoryChooserBuilder.create(); builder.title("Hello World"); String cwd = System.getProperty("user.dir"); File file = new File(cwd); builder.initialDirectory(file); DirectoryChooser chooser = builder.build(); File chosenDir = chooser.showDialog(null); if (chosenDir != null) { System.out.println(chosenDir.getAbsolutePath()); } else { System.out.print("no directory chosen"); } Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename)); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add("Daily Report of " + report_datepicker.getValue().toString() + " location: " + combo_loc.getValue().toString()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(40); document.add(paragraph); document.add(createPDFTableVehicle(Vlist)); paragraph.clear(); paragraph.add(" "); paragraph.setSpacingAfter(20); document.add(paragraph); document.add(createPDFTableByCategory(cdata)); document.close(); label_result.setText("Download successfully"); label_result.setVisible(true); } catch (FileNotFoundException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:CTD.planer2.util.ExportToPdf.java
/** * We create the table we want to add to our pdf * // ww w . ja v a 2 s .c o m * @param subCatPart * @throws BadElementException */ private static void createTable(Section subCatPart) throws BadElementException { // Get the number of days per Week from the Settings int daysPerWeek = App.theSettings.getDaysPerWeek(); PdfPTable table = new PdfPTable(daysPerWeek + 1); String[] WeekDay = { "Zeit", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" }; for (int i = 0; i < daysPerWeek + 1; i++) { PdfPCell c1 = new PdfPCell(new Phrase(WeekDay[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); if (i == daysPerWeek) { table.setHeaderRows(1); } } // We take the first day to get the number of units and so the number of // times we have to run this. for (int j = 0; j < planExport.getWeekday(1).size(); j++) { // For each day available, we run this loop once. for (int k = 1; k < daysPerWeek + 1; k++) { // Read one unit per day and write it in a new cell of the pdf List<Units> tmp = planExport.getWeekday(k); // If it's the first day, we also want a first cell per line // containing the time this unit starts if (k == 1) { SimpleDateFormat df = new SimpleDateFormat("HH:mm"); String time = df.format(tmp.get(j).getTime()); table.addCell(time); String room = " "; // Check whether a room is given if (tmp.get(j).getRooms().size() < 1) { room = " "; } else { room = tmp.get(j).getRooms().get(0).toString(); } String teacher = " "; if (tmp.get(j).getPerson() == null) { teacher = " "; } else { teacher = tmp.get(j).toString(); } String subject = " "; if (tmp.get(j).getSubjects().size() < 1) { subject = " "; } else { subject = tmp.get(j).getSubjects().get(0).toString(); } // If the plan is for a room, we just need the time and the // teachers name if (CPlaner.selRoom != null) { table.addCell(teacher); // If the plan is for a class, we need the time, the // room and the teachers name } else if (CPlaner.selClass != null) { table.addCell(room + ", " + teacher); // For a teachers plan, we need the room and the subject } else { table.addCell(room + ", " + subject); } } else { // If it's not the first day, we don't need to print the // start time again String room = " "; // Check again whether a room is given if (tmp.get(j).getRooms().size() < 1) { room = " "; } else { room = tmp.get(j).getRooms().get(0).toString(); } String teacher = " "; if (tmp.get(j).getPerson() == null) { teacher = " "; } else { teacher = tmp.get(j).toString(); } String subject = " "; if (tmp.get(j).getSubjects().size() < 1) { subject = " "; } else { subject = tmp.get(j).getSubjects().get(0).toString(); } // If the plan is for a room, we just need the time and the // teachers name if (CPlaner.selRoom != null) { table.addCell(teacher); // If the plan is for a class, we need the time, the // room and the teachers name } else if (CPlaner.selClass != null) { table.addCell(room + ", " + teacher); // For a teachers plan, we need the room and the subject } else { table.addCell(room + ", " + subject); } } } } // Add the whole table we've just created to the pdf file subCatPart.add(table); }
From source file:CTD.planer2.util.ExportToPdf.java
/** * We create the table we want to add to our pdf * // w ww .j av a 2s .c o m * @param subCatPart * @throws BadElementException */ private static void createTable(Section subCatPart, Room room) throws BadElementException { // Get the number of days per Week from the Settings int daysPerWeek = App.theSettings.getDaysPerWeek(); PdfPTable table = new PdfPTable(daysPerWeek + 1); String[] WeekDay = { "Zeit", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" }; for (int i = 0; i < daysPerWeek + 1; i++) { PdfPCell c1 = new PdfPCell(new Phrase(WeekDay[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); if (i == daysPerWeek) { table.setHeaderRows(1); } } double calc = 0; // Simplify the Date since we just need the time SimpleDateFormat df = new SimpleDateFormat("HH:mm"); Date start = null; Date uSize = null; try { start = df.parse(App.theSettings.getStartingTimeH() + ":" + App.theSettings.getStartingTimeM()); uSize = new Date(MINUTES.toMillis(App.theSettings.getUnitsSize())); } catch (ParseException e) { } // We take the first day to get the number of units and so the number of // times we have to run this. for (int j = 0; j < Tools.calcRows(); j++) { calc = j == 0 ? start.getTime() : (calc + (uSize.getTime())); // For each day available, we run this loop once. for (int k = 1; k < daysPerWeek + 1; k++) { Units u = room.getUnitByRowCol(k, j); // If it's the first day, we also want a first cell per line // containing the time this unit starts if (k == 1) { table.addCell(df.format(calc)); // Check whether a room is given String teacher = " "; if (u != null) { teacher = u.toString(); } table.addCell(teacher); } else { // If it's not the first day, we don't need to print the // start time again String teacher = " "; if (u != null) { teacher = u.toString(); } table.addCell(teacher); } } } // Add the whole table we've just created to the pdf file subCatPart.add(table); }
From source file:CTD.planer2.util.ExportToPdf.java
private static void createDayTable(Section subCatPart) throws BadElementException { List<Person> personList = App.theSemester.getPersonList(); PdfPTable table = new PdfPTable(personList.size() + 1); PdfPCell c1 = new PdfPCell(new Phrase(" ")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);// ww w . j ava 2 s . c om for (Person p : personList) { c1 = new PdfPCell(new Phrase(p.toString())); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); int k = 1; // We take the first person to get the number of units and so the // number // of // times we have to run this. for (int j = 1; j < p.getEntity().size(); j++) { // For each person available, we run this loop once. List<Units> tmp = p.getEntity(); if (k == 1) { SimpleDateFormat df = new SimpleDateFormat("HH:mm"); String time = df.format(tmp.get(j).getTime()); table.addCell(time); String classes = " "; // Check whether a class is given if (tmp.get(j).getClasses().size() < 1) { classes = " "; } else { classes = tmp.get(j).getClasses().get(0).toString(); } table.addCell(classes); } else { // If it's not the first day, we don't need to print the // start time again String classes = " "; // Check whether a class is given if (tmp.get(j).getClasses().size() < 1) { classes = " "; } else { classes = tmp.get(j).getClasses().get(0).toString(); } table.addCell(classes); } k = k + 1; } } // Add the whole table we've just created to the pdf file subCatPart.add(table); }