List of usage examples for com.itextpdf.text Paragraph setAlignment
public void setAlignment(int alignment)
From source file:util.ImageExample.java
public ImageExample(Calendar date, int settings, ArrayList<String> courses, String time, String eventAddress, int totalPrice, String comments, boolean kunde) throws Exception { this.date = date; this.settings = settings; this.courses = courses; this.time = time; this.eventAddress = eventAddress; this.totalPrice = totalPrice; this.comments = comments; this.fileName = ""; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.getAllFonts();//from w w w .ja v a 2 s.c o m FontFactory.register("C:/Windows/Fonts/ARLRDBD.TTF", "Arial Rounded"); Font font = FontFactory.getFont("Arial Rounded", 22, Font.NORMAL, new BaseColor(51, 102, 102)); Document document = new Document(); System.out.println("Pdf creation startet"); try { if (kunde) { fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + ".pdf"; } else { fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + "Prisliste.pdf"; } FileOutputStream file = new FileOutputStream(new File("C:/Users/Mark/Desktop", fileName)); PdfWriter writer = PdfWriter.getInstance(document, file); document.open(); Image img = Image.getInstance("src/pictures/cirkles.png"); img.scaleToFit(277, 277); img.setAbsolutePosition(40, PageSize.A4.getHeight() - img.getHeight()); document.add(img); Chunk chunk = new Chunk("Grillmester 'Frankie'", font); chunk.setCharacterSpacing(3); Paragraph header = new Paragraph(chunk); header.setAlignment(Element.ALIGN_RIGHT); header.setSpacingBefore(15); document.add(header); Paragraph title = new Paragraph( "Tilbud angende d. " + new SimpleDateFormat("dd. MMMMM yyyy").format(date.getTime()) + ".", new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD)); title.setAlignment(Element.ALIGN_LEFT); title.setIndentationLeft(235); title.setSpacingBefore(100); title.setLeading(17); document.add(title); Paragraph subtitle = new Paragraph("(Arrangement til " + settings + " personer).", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.ITALIC)); subtitle.setAlignment(Element.ALIGN_LEFT); subtitle.setIndentationLeft(235); subtitle.setLeading(17); document.add(subtitle); Paragraph body = new Paragraph("\n\nDer er aftalt:\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 18)); body.setAlignment(Element.ALIGN_LEFT); body.setIndentationLeft(235); body.setLeading(17); for (String course : courses) { body.add(course + "\n\n"); } body.add("\nServeres klokken " + time + " i " + eventAddress + "."); document.add(body); Paragraph ending = new Paragraph("\n\n\nPris: " + totalPrice + ",-kr.", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); ending.setAlignment(Element.ALIGN_LEFT); ending.setIndentationLeft(235); ending.setLeading(17); document.add(ending); if (!comments.equals("null")) { if (!comments.equals("")) { Paragraph comment = new Paragraph("\n\nKommentarer\n" + comments, new Font(Font.FontFamily.TIMES_ROMAN, 18)); comment.setAlignment(Element.ALIGN_LEFT); comment.setIndentationLeft(235); comment.setLeading(17); document.add(comment); } } Image footerImg = Image.getInstance("src/pictures/grillmester.png"); footerImg.scaleToFit(210, 210); footerImg.setAbsolutePosition(40, 40); document.add(footerImg); Image img2 = Image.getInstance("src/pictures/Contact.png"); img2.scaleToFit(250, 250); img2.setAbsolutePosition(20, PageSize.A4.getHeight() - img.getHeight() - 250); document.add(img2); document.close(); System.out.println("Pdf finish"); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getLocalizedMessage()); } }
From source file:utiles.ContarCajaPdf.java
/** * metodo que hace uso de la clase itext para generar archivos PDF * @param venta datos del tablemodels//from www . j av a 2 s . c o m * @throws Exception */ public static void ITextHelloWorld(double venta) throws Exception { Document document = new Document(); Paragraph parrafo, parrafo1, parrafo2; Image imagen = Image.getInstance("src/icon/Spa.jpg"); // Le indicamos donde se guardara el archivo PdfWriter.getInstance(document, new FileOutputStream("src/pdfGenerados/" + venta + "_" + "caja_del_dia.pdf")); // Este codigo genera una tabla de 2 columnas PdfPTable table = new PdfPTable(2); String total = venta + " "; // addCell() agrega una celda a la tabla, el cambio de fila // ocurre automaticamente al llenar la fila table.addCell("Caja total del dia:"); table.addCell(total); document.open(); //Creamos una cantidad significativa de paginas para probar el encabezado parrafo = new Paragraph("Gracias por confiar en nuestros servicios SpaRelajate"); parrafo1 = new Paragraph(" "); parrafo2 = new Paragraph(" "); //este codigo hace que se nos centre tanto el texto como la imagen parrafo.setAlignment(Element.ALIGN_CENTER); parrafo1.setAlignment(Element.ALIGN_CENTER); parrafo2.setAlignment(Element.ALIGN_CENTER); imagen.setAlignment(Element.ALIGN_CENTER); //aade la documentacion que tendra el pdf document.add(imagen); document.add(parrafo1); document.add(table); document.add(parrafo2); document.add(parrafo); document.close(); }
From source file:utiles.FacturaPdf.java
/** * metodo que hace uso de la clase itext para generar archivos PDF recogiendo * los datos para una factura/*from w w w .j a va 2s .c o m*/ * @param _nombre recoge el cliente que realiza la reserva * @param _dni optiene la documentacion del cliente * @param _telefono se le pasa numero de contacto del cliente * @param _cantidad se indica numero de servicios que ha comprado * @param _servicio recoge el nombre del servicio comprado * @param _fecha optiene fecha en la que el cliente tiene la "cita" * @param _total coste de todos los servicios comprados "cantidad*precio del servicio - la promocion" * @throws Exception */ public static void ITextHelloWorld(String _nombre, String _dni, String _telefono, String _cantidad, String _servicio, String _fecha, String _total) throws Exception { Document document = new Document(); Paragraph parrafo, paragraph_2, parrafo2, parrafo3, parrafo4; Image imagen = Image.getInstance("src/icon/Spa.jpg"); // Le indicamos donde se guardara el archivo PdfWriter.getInstance(document, new FileOutputStream("src/pdfGenerados/" + "Factura_" + _nombre + "_" + _servicio + "_" + _cantidad + "_" + _total + ".pdf")); // Este codigo genera una tabla de 2 columnas PdfPTable table = new PdfPTable(7); table.setWidthPercentage(100); String nombre = _nombre; String dni = _dni; String telefono = _telefono; String cantidad = _cantidad; String servicio = _servicio; String fecha = _fecha; String total = _total + " "; // addCell() agrega una celda a la tabla, el cambio de fila // ocurre automaticamente al llenar la fila table.addCell("Nombre"); table.addCell("Dni"); table.addCell("Telefono"); table.addCell("Cantidad"); table.addCell("Servicio"); table.addCell("Fecha reserva"); table.addCell("Precio total"); table.addCell(nombre); table.addCell(dni); table.addCell(telefono); table.addCell(cantidad); table.addCell(servicio); table.addCell(fecha); table.addCell(total); document.open(); //Creamos una cantidad significativa de paginas para probar el encabezado parrafo = new Paragraph("Gracias por confiar en nuestros servicios SpaRelajate"); paragraph_2 = new Paragraph(" FACTURA "); parrafo2 = new Paragraph(" "); parrafo3 = new Paragraph(" "); parrafo4 = new Paragraph(" "); //este codigo hace que se nos centre tanto el texto como la imagen parrafo.setAlignment(Element.ALIGN_CENTER); paragraph_2.setAlignment(Element.ALIGN_CENTER); parrafo2.setAlignment(Element.ALIGN_CENTER); imagen.setAlignment(Element.ALIGN_CENTER); paragraph_2.setFont(new Font(FontFactory.getFont("Helvetica", 40, Font.BOLD, BaseColor.BLACK))); //aade la documentacion que tendra el pdf document.add(parrafo4); document.add(parrafo4); document.add(imagen); document.add(parrafo4); document.add(parrafo4); document.add(paragraph_2); document.add(parrafo3); document.add(parrafo4); document.add(parrafo4); document.add(parrafo4); document.add(parrafo4); document.add(table); document.add(parrafo4); document.add(parrafo2); document.add(parrafo3); document.add(parrafo4); document.add(parrafo4); document.add(parrafo4); document.add(parrafo4); document.add(parrafo4); document.add(parrafo2); document.add(parrafo); document.close(); }
From source file:utilities.itext.Turnover.java
public static void createTurnOver(String title, StatisticType type, Date from, Date to) { Document document = new Document(); try {//w ww. j a va 2s. c o m PdfWriter.getInstance(document, new FileOutputStream("text.pdf")); document.open(); Paragraph headline = new Paragraph("Umsatzstatistik von: " + title, Fonts.DOCUMENTHEADLINE); headline.setAlignment(Element.ALIGN_CENTER); document.add(headline); HashMap<String, BigDecimal> expenseData = null; if (type.equals(StatisticType.CATEGORY)) { expenseData = db.getTotalExpensesByCategory(from, to); } Paragraph tables = createTablesWithoutDetails(expenseData); tables.setSpacingBefore(30f); document.add(tables); // document.add(createPieChart(expenseData, "Ausgaben")); Category cat = bl.getBillCategoryByName("Elektrogerte"); document.add(createTablesWithDetails(bl.getPaymentPositionsByCategory(cat, from, to))); document.close(); System.exit(0); } catch (Exception ex) { Logger.getLogger(Turnover.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Utility.PDFDemo.java
public void cretePDF(String name, String rpor) throws FileNotFoundException { try {/* ww w.j a v a 2 s .com*/ //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); try { // //file path //String path = "docs/" + name; docwriter = PdfWriter.getInstance(doc, new FileOutputStream(rpor + ".pdf")); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(rpor); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks Paragraph pp = new Paragraph("Cocoa Health And Extension", forTitle); pp.setAlignment(Element.ALIGN_CENTER); Paragraph palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); Chunk chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position Paragraph underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); Chunk chuk1 = new Chunk("Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); Chunk chuk2 = new Chunk(name, bfBold12); Paragraph regionText = new Paragraph(rpor, bfBold12); regionText.setAlignment(Element.ALIGN_CENTER); String rporx = ""; // ResultSet dir = manager.PDFdemos(name); // try { // if (dir.next()) { // rporx = dir.getString(12); // // } // } catch (SQLException ex) { // Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); // } Paragraph regionTexts = new Paragraph(rporx, bfBold12); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports()); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion Paragraph newDate = new Paragraph(new Date().toString(), bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); //close the document doc.close(); //close the writer docwriter.close(); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:utils.pdf.cv_templates.Template1.java
private void addPersonalInformation(User user) throws DocumentException { Paragraph paragraph; PdfPCell cell;/*from w ww . j a va 2 s. c o m*/ PdfPTable table; table = new PdfPTable(new float[] { 0.5f, 2f }); table.setWidthPercentage(100); table.setSpacingBefore(5); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(" "); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_RIGHT); cell.setPaddingRight(10); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(55); cell.setPaddingTop(0); paragraph = new Paragraph(user.name + " " + user.surnames, font1); cell.setBorder(PdfPCell.NO_BORDER); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(" "); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_RIGHT); cell.setPaddingRight(10); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(55); cell.setPaddingTop(0); paragraph = new Paragraph(user.birthDate + "\n", font4); cell.setBorder(PdfPCell.NO_BORDER); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(" "); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_RIGHT); cell.setPaddingRight(10); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(55); cell.setPaddingTop(0); paragraph = new Paragraph("Calle " + user.residenceAddress + " N " + user.residenceNumber + " " + user.residenceZipCode + " " + user.residenceCity + "\n", font2); paragraph.setSpacingBefore(20); cell.setBorder(PdfPCell.NO_BORDER); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(" "); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_RIGHT); cell.setPaddingRight(10); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(55); cell.setPaddingTop(0); paragraph = new Paragraph(user.phoneNumber, font2); paragraph.setSpacingBefore(20); cell.setBorder(PdfPCell.NO_BORDER); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(" "); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_RIGHT); cell.setPaddingRight(10); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(55); cell.setPaddingTop(0); paragraph = new Paragraph(user.email, font2); paragraph.setSpacingBefore(20); cell.setBorder(PdfPCell.NO_BORDER); cell.addElement(paragraph); table.addCell(cell); document.add(table); }
From source file:utils.pdf.cv_templates.Template1.java
private void addProfessionalExperience(List<ProfessionalExperience> experienceList) throws DocumentException { Paragraph paragraph; PdfPCell cell;//from w w w . j av a 2 s.c o m PdfPTable table; for (int i = 0; i < experienceList.size(); i++) { table = new PdfPTable(new float[] { 1f, 0.5f }); table.setWidthPercentage(100); table.setSpacingBefore(5); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); if (i == 0) { paragraph = new Paragraph("Experiencia Profesional", font1); cell.setBorder(PdfPCell.NO_BORDER); } else { paragraph = new Paragraph(""); } paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setPaddingLeft(10); cell.setPaddingTop(0); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(""); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(experienceList.get(i).job + "." + " " + experienceList.get(i).company, font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //Second column cell = new PdfPCell(); cell.setPaddingLeft(10); cell.setPaddingTop(0); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(experienceList.get(i).startDate + " - " + experienceList.get(i).endDate, font3); cell.addElement(paragraph); table.addCell(cell); document.add(table); } }
From source file:utils.pdf.cv_templates.Template1.java
private void addStudies(User user) throws DocumentException { Paragraph paragraph; PdfPCell cell;//from ww w. ja va2 s . c om PdfPTable table; if (!user.studyTitle.equals("")) { table = new PdfPTable(new float[] { 1f }); table.setWidthPercentage(100); table.setSpacingBefore(5); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph("Estudios", font1); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph(user.studyTitle + "." + " " + user.studyLocation, font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); document.add(table); } }
From source file:utils.pdf.cv_templates.Template1.java
private void addSoftware(List<Software> softwareList) throws DocumentException { Paragraph paragraph1; Paragraph paragraph2;/*from w ww . j a v a2 s. c o m*/ PdfPCell cell; PdfPTable table; table = new PdfPTable(new float[] { 1f }); table.setWidthPercentage(100); table.setSpacingBefore(5); //First column cell = new PdfPCell(); for (int i = 0; i < softwareList.size(); i++) { cell.setBorder(PdfPCell.NO_BORDER); if (i == 0) { paragraph1 = new Paragraph("Programas informticos:", font1); paragraph2 = new Paragraph( softwareList.get(i).software + "." + " Nivel: " + softwareList.get(i).level, font2); cell.setBorder(PdfPCell.NO_BORDER); } else { paragraph1 = new Paragraph(""); paragraph2 = new Paragraph( softwareList.get(i).software + "." + " Nivel: " + softwareList.get(i).level, font2); } paragraph1.setAlignment(Paragraph.ALIGN_LEFT); paragraph2.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph1); cell.addElement(paragraph2); } table.addCell(cell); document.add(table); }
From source file:utils.pdf.cv_templates.Template1.java
private void addSkills(User user, List<String> personalCharacteristics, List<Skill> skills) throws DocumentException { Paragraph paragraph; PdfPCell cell;/* w ww .ja va2s.com*/ PdfPTable table; List<String> rankedSkills = selectSkills(skills); if (personalCharacteristics.size() != 0 && rankedSkills.size() != 0) { table = new PdfPTable(new float[] { 1f }); table.setWidthPercentage(100); table.setSpacingBefore(5); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph("Sobre mi...", font1); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph( "Me defino como una persona de carcter " + personalCharacteristics.get(1).toLowerCase() + " y " + personalCharacteristics.get(0).toLowerCase() + ".", font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph("Entre mis puntos fuertes destacan las " + rankedSkills.get(0).toLowerCase() + " y las " + rankedSkills.get(1).toLowerCase() + ".", font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph( "Considero que soy una persona activa que presenta " + rankedSkills.get(2).toLowerCase() + ".", font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph("Adems, una de las caractersticas que me define es que soy " + personalCharacteristics.get(2).toLowerCase() + ".", font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); if (!user.drivingLicense.equals("No tengo carnet")) { //First column cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); paragraph = new Paragraph("Permiso de conducir: " + user.drivingLicense + ".", font2); cell.setBorder(PdfPCell.NO_BORDER); paragraph.setAlignment(Paragraph.ALIGN_LEFT); cell.setPaddingRight(10); cell.setPaddingLeft(35); cell.addElement(paragraph); table.addCell(cell); } document.add(table); } }