List of usage examples for com.itextpdf.text Phrase Phrase
private Phrase(final boolean dummy)
From source file:watermark.java
public static void main(String[] args) { try {/* ww w .jav a 2 s. c om*/ PdfReader reader = new PdfReader(args[0]); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(args[1])); stamp.getWriter().setCompressionLevel(9); // without this code it'll 3 times bigger int bottom_margin = Integer.parseInt(args[2]); String lic = String.format(LIC, args[3]); BaseFont bf = BaseFont.createFont(FONTFILE, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Chunk c = new Chunk(lic, new Font(bf, 7, Font.NORMAL, TCOLOR)); c.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1 / 800f, null); Phrase phrase = new Phrase(c); int pages = reader.getNumberOfPages(); int xpos = 90; for (int i = 1; i <= pages; i++) { if (i % 2 == 0) xpos = 160; else xpos = 90; PdfContentByte under = stamp.getUnderContent(i); ColumnText.showTextAligned(under, Element.ALIGN_LEFT, phrase, xpos, bottom_margin, -0); } stamp.setFullCompression(); // without this code it'll 3 times bigger stamp.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:pdf_Demo.java
public static void main(String[] args) throws Exception { // Create Connection objects // Class.forName("oracle.jdbc.OracleDriver"); // Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "hr", "hr"); // Statement stmt = conn.createStatement(); /* Define the SQL query */ // ResultSet query_set = stmt.executeQuery("SELECT DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID FROM DEPARTMENTS"); /* Step-2: Initialize PDF documents - logical objects */ Document my_pdf_report = new Document(); PdfWriter.getInstance(my_pdf_report, new FileOutputStream("F:\\report.pdf")); my_pdf_report.open();//from ww w . java2 s . c o m // we have four columns in our table PdfPTable my_report_table = new PdfPTable(4); // create a cell object PdfPCell table_cell; String dept_id = "ID"; table_cell = new PdfPCell(new Phrase(dept_id)); my_report_table.addCell(table_cell); String dept_name = "Name"; table_cell = new PdfPCell(new Phrase(dept_name)); my_report_table.addCell(table_cell); /* Attach report table to PDF */ my_pdf_report.add(my_report_table); // my_pdf_report.close(); /* Close all DB related objects */ // query_set.close(); // stmt.close(); // conn.close(); }
From source file:PDFmaker.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(2); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Uitgiftepunt")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w ww .jav a 2s . c o m c1 = new PdfPCell(new Phrase("Pakketten deze week (" + LocalDate.now() + ")")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); try { SQLget sql = new SQLget(); ResultSet rs = sql.getProductielijst(); while (rs.next()) { String uitgiftepunt = rs.getString("Uitgiftepunt"); int aantalPakketten = rs.getInt("Pakketten"); table.addCell(uitgiftepunt); table.addCell(Integer.toString(aantalPakketten)); } } catch (Exception e) { } subCatPart.add(table); }
From source file:Pdfsave.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from w w w . jav a 2 s. co m*/ c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }
From source file:pdf_demo2.java
private static void createTable(Section section) throws BadElementException { // number of table-column = 3 PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/* w ww.java 2 s . co m*/ c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); // table.setHeaderRows(1); ?? table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); section.add(table); }
From source file:CrearPdf.java
private void createTable(Document document) throws BadElementException, DocumentException { PdfPTable table = new PdfPTable(6); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1;// w ww . j ava 2 s .c o m for (int i = 0; i < columnas.length; i++) { c1 = new PdfPCell(new Phrase(columnas[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); System.out.println("columnas" + columnas[i]); } table.setHeaderRows(1); for (int i = 0; i < d; i++) { for (int j = 0; j < columnas.length; j++) { System.out.print(datos[i][j] + " "); table.addCell(datos[i][j]); } System.out.println(); } document.add(table); }
From source file:FullPageTable.java
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(PageSize.A4, 0, 0, 0, 0); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();/*from www . j av a 2s . c o m*/ PdfPTable table = new PdfPTable(10); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); // first row PdfPCell cell = new PdfPCell(new Phrase("DateRange")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("Calldate"); table.addCell("Calltime"); table.addCell("Source"); table.addCell("DialedNo"); table.addCell("Extension"); table.addCell("Trunk"); table.addCell("Duration"); table.addCell("Calltype"); table.addCell("Callcost"); table.addCell("Site"); for (int i = 0; i < 100; i++) { table.addCell("date" + i); table.addCell("time" + i); table.addCell("source" + i); table.addCell("destination" + i); table.addCell("extension" + i); table.addCell("trunk" + i); table.addCell("dur" + i); table.addCell("toc" + i); table.addCell("callcost" + i); table.addCell("Site" + i); } document.add(table); document.close(); }
From source file:imprimer.java
public void quitter_territoire() { Document document = new Document(PageSize.A4); try {// www . j a v a 2s . c o m PdfWriter.getInstance(document, new FileOutputStream("quitter territoire.pdf")); document.open(); imagee(document); document.open(); imagee(document); SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy"); java.util.Date now = new java.util.Date(); String tdnow = td.format(now); Paragraph pa = new Paragraph("Autorisation de quitter le territoire", FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY)); pa.setAlignment(Paragraph.ALIGN_CENTER); document.add(pa); for (int i = 0; i < 4; i++) { document.add(new Paragraph(" ")); } // cell = new PdfPCell(new Phrase("Fusion de 2 cellules de la premire colonne")); // cell.setRowspan(2); // table.addCell(cell); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(); //contenu du tableau. table.addCell("\nNom:\n\n"); table.addCell("\n\n"); table.addCell("\nPrenom:\n\n"); table.addCell("\n\n"); table.addCell("\nGRADE :\n\n"); table.addCell("\n\n"); table.addCell("\nADRESSE PERSONNELLE :\n\n"); table.addCell("\n\n"); table.addCell("\nAFFECTATION :\n\n"); table.addCell("\n\n"); cell = new PdfPCell( new Phrase("\nJai lhonneur de solliciter une autorisation dabsence.\n\n")); cell.setColspan(2); table.addCell(cell); table.addCell("\nDU:\n\n"); table.addCell("\n\n"); table.addCell("\nAU:\n\n"); table.addCell("\n\n"); table.addCell("\nMOTIF :\n\n"); table.addCell("\n\n"); table.addCell("\nAVIS DU CHEF \nDETABLISSEMENT:\n\n"); table.addCell("\n\nFAVORABLE.def\n\n"); cell = new PdfPCell(new Phrase("\nFait Ouarzazate le :" + tdnow + "\n\n")); cell.setColspan(2); table.addCell(cell); table.addCell("Signature du demandeur\n\n\n\n\n\n\n\n\n"); table.addCell("Cachet et signature\n\n\n\n\n\n\n\n"); document.add(table); document.close(); Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("quitter territoire.pdf")); } else { System.out.println("Open is not supported"); } } catch (Exception ex) { System.out.print("catch"); } }
From source file:alessandrafx.MarcoVentanaController.java
@FXML private void generarReporteMenusal(MouseEvent event) { try {//from w w w . j a va 2 s .com FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("Reporte.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); SistemaAleMC sistema = new SistemaAleMC(); Double balanceMonetario = 0.0; //Para salidas de dinero ArrayList<Capital> capitales = sistema.getRegistrosCapitalTipo('S'); cell = new PdfPCell(new Phrase("Gastos y pagos realizados")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de salidas de dinero Double totalEgreso = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario -= Double.valueOf(capital.getMonto()); totalEgreso -= Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE EGRESOS")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalEgreso.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Para Pago de mensualidades capitales = sistema.getRegistrosCapitalTipo('M'); cell = new PdfPCell(new Phrase("Pagos de mensualidad recibidos")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de pago de mensualidades de los alumnos Double totalIngresoMen = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario += Double.valueOf(capital.getMonto()); totalIngresoMen += Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE MENSUALIDADES")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalIngresoMen.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Para Pago de anualidades capitales = sistema.getRegistrosCapitalTipo('A'); cell = new PdfPCell(new Phrase("Pagos de anualidades recibidos")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de pago de anualidades de los alumnos Double totalIngresoAnu = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario += Double.valueOf(capital.getMonto()); totalIngresoAnu += Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE ANUALIDADES")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalIngresoAnu.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //PARA EL BALANCE MONETARIO capitales = sistema.getRegistrosCapitalTipo('A'); cell = new PdfPCell(new Phrase("Total")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega la celda del total monetario if (balanceMonetario == (Double) 0.0) { cell = new PdfPCell(new Phrase("No hubieron movimientos este mes")); } else { cell = new PdfPCell(new Phrase(balanceMonetario.toString())); } cell.setColspan(3); cell.setBackgroundColor(BaseColor.WHITE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); Alert alerta = new Alert(Alert.AlertType.INFORMATION); alerta.setTitle("Corre a ver tu PDF!"); alerta.setHeaderText(null); alerta.setContentText("El PDF ha sido generado, puedes revisarlo"); alerta.showAndWait(); } catch (Exception e) { Alert alerta = new Alert(Alert.AlertType.INFORMATION); alerta.setTitle("Lo sentimos"); alerta.setHeaderText(null); alerta.setContentText("La ubicacin seleccionada no es vlida y por tanto, no se generar el PDF"); alerta.showAndWait(); } }
From source file:alessandrafx.VentanaEgresoController.java
private void generarReportePagoColaborador(int pagoColaborador, int pagoSugerido) throws DatoFaltante { try {/*from w ww. j a va 2 s .c o m*/ FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaNueva.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el pago IDEAL cell = new PdfPCell(new Phrase("Pago sugerido recibido")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase("Pago sugerido")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el pago realizado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(pagoColaborador))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }