List of usage examples for com.itextpdf.text.pdf PdfPTable completeRow
public void completeRow()
From source file:Almacen.Responsiva.java
private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed // TODO add your handling code here: Session session = HibernateUtil.getSessionFactory().openSession(); try {//from www . jav a 2 s. c o m String empleado = ""; String puesto = ""; if (t_datos.getRowCount() > 0) { //consulta Query q = session.createSQLQuery( "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado=" + t_id_empleado.getText() + ";"); q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); List lista = q.list(); for (int i = 0; i < lista.size(); i++) { java.util.HashMap map = (java.util.HashMap) lista.get(i); empleado = (String) map.get("empleado"); puesto = (String) map.get("puesto"); } Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; Calendar fecha1 = new GregorianCalendar(); int anio = fecha1.get(Calendar.YEAR); int mes = fecha1.get(Calendar.MONTH); int dia = fecha1.get(Calendar.DAY_OF_MONTH); //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); File folder = new File("reportes/Responsivas"); folder.mkdirs(); PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf"); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf")); PdfContentByte cb = stamp.getUnderContent(1); PdfContentByte cb2 = stamp.getUnderContent(2); AcroFields fdfDoc = stamp.getAcroFields(); // Creo una fuente BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); cb.beginText(); //dia try { if (dia < 9) fdfDoc.setField("Dia", "0" + String.valueOf(dia)); else fdfDoc.setField("Dia", String.valueOf(dia)); } catch (Exception e) { fdfDoc.setField("Dia", "error"); } //mes try { fdfDoc.setField("Mes", Mes[mes]); } catch (Exception e) { fdfDoc.setField("Mes", ""); } //ao try { fdfDoc.setField("Anio", String.valueOf(anio)); } catch (Exception e) { fdfDoc.setField("Anio", ""); } //nombre try { fdfDoc.setField("Nombre", empleado); } catch (Exception e) { fdfDoc.setField("Nombre", ""); } //puesto try { fdfDoc.setField("Puesto", puesto); } catch (Exception e) { fdfDoc.setField("Puesto", ""); } //tabla de herramientas float tam[] = new float[] { 250, 50, 180 }; Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD); PDF reporte = new PDF(); PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT); tabla.setTotalWidth(tam); BaseColor cabecera = BaseColor.GRAY; BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); for (int i = 0; i < t_datos.getRowCount(); i++) { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); if (t_datos.getValueAt(i, 3) != null) tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } tabla.completeRow(); tabla.writeSelectedRows(0, -1, 70, 720, cb2); cb.endText(); stamp.close(); reporte.cerrar(); reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"); } else { JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva"); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) { if (session.isOpen()) { session.close(); } } }
From source file:bestdeal.util.genererPdf.java
public static void main(String[] args) { // - Paramtres de connexion la base de donnes Connection connection;/*from w w w. j a v a 2 s . c o m*/ String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, }; try { String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur"; connection = MyConnection.getInstance(); mypdf = new Document(PageSize.A4, 50, 50, 50, 50); File di = new File("C:/Voucher"); File fl[] = di.listFiles(); try { OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf")); PdfWriter.getInstance(mypdf, file); mypdf.open(); Statement stm; mypdf.addAuthor("Best Deal"); mypdf.addSubject("Voucher "); mypdf.add(new Paragraph("Socite BestDeal")); mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT ")); mypdf.add(new Paragraph("TEL : xx xxx xxx")); mypdf.add(new Paragraph("FAX : xx xxx xxx")); mypdf.add(new Paragraph( " " + new Date().toString())); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" " + "Voucher N'01", FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("CLIENT :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); try { stm = connection.createStatement(); ResultSet rs = stm.executeQuery(requete); while (rs.next()) { // add a country to the document as a Chunk //mypdf.add(new Chunk(rs.getString("quantite"))); Phrase p = new Phrase("Nom: "); Phrase p2 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa = new Paragraph(); pa.add(p); pa.add(p2); mypdf.add(pa); Phrase p3 = new Phrase("Prenom: "); Phrase p4 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa1 = new Paragraph(); pa1.add(p3); pa1.add(p4); mypdf.add(pa1); Phrase p5 = new Phrase("Adresse: "); Phrase p6 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa2 = new Paragraph(); pa2.add(p5); pa2.add(p6); mypdf.add(pa2); Phrase p7 = new Phrase("Tlphone: "); Phrase p8 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa3 = new Paragraph(); pa3.add(p7); pa3.add(p8); mypdf.add(pa3); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("Vendeur :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); Phrase p9 = new Phrase("Nom: "); Phrase p10 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa4 = new Paragraph(); pa4.add(p9); pa4.add(p10); mypdf.add(pa4); Phrase p11 = new Phrase("Prnom: "); Phrase p12 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa5 = new Paragraph(); pa5.add(p11); pa5.add(p12); mypdf.add(pa5); Phrase p13 = new Phrase("Tlphone: "); Phrase p14 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa6 = new Paragraph(); pa6.add(p13); pa6.add(p14); mypdf.add(pa6); Phrase p15 = new Phrase("Adresse: "); Phrase p16 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa7 = new Paragraph(); pa7.add(p15); pa7.add(p16); mypdf.add(pa7); Phrase p17 = new Phrase("Email: "); Phrase p18 = new Phrase(new Chunk(rs.getString("email"))); Paragraph pa8 = new Paragraph(); pa8.add(p17); pa8.add(p18); mypdf.add(pa8); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); for (int i = 0; i < rs.getRow(); i++) { for (int j = 0; j < data[i].length - 1; j++) { data[i][j] = rs.getString(j + 9); // if (j==3) // data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+""; } } for (int i = 0; i < rs.getRow(); i++) { float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim()); data[i][4] = s + ""; } //mypdf.add(new Phrase("nom")); //mypdf.add(new Chunk(rs.getString("nom"))); //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom")))); //mypdf.add(new Chunk(" ")); //Chunk id = new Chunk(rs.getString("id")); // with a background color //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f); // and a text rise //id.setTextRise(6); // mypdf.add(id); mypdf.add(Chunk.NEWLINE); } } catch (SQLException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Prenom ")); // mypdf.add(new Paragraph("Adresse ")); //mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Nom de la socit ")); // mypdf.add(new Paragraph("Adresse ")); // mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph(" ")); String[] headers = new String[] { " Id_deal", " Nom Deal", " Quantit", " Prix unitaire", " Prix total" }; PdfPTable table = new PdfPTable(headers.length); for (int i = 0; i < headers.length; i++) { String header = headers[i]; PdfPCell cell = new PdfPCell(); cell.setGrayFill(0.9f); cell.setPhrase(new Phrase(header.toUpperCase())); table.addCell(cell); } table.completeRow(); for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { String datum = data[i][j]; PdfPCell cell = new PdfPCell(); cell.setPhrase(new Phrase(datum.toUpperCase())); table.addCell(cell); } table.completeRow(); } mypdf.add(table); } catch (FileNotFoundException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph( "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ", FontFactory.getFont(null, 9, Font.NORMAL))); mypdf.add(new Paragraph( " Merci pour votre confiance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.close(); } catch (DocumentException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createFrontCoverPage(Document document, String coverTitle, Bitmap photo) throws DocumentException, MalformedURLException, IOException { if (photo != null) { int imageMaxWidth; int imageMaxHeight; int imagePosX; int imagePosY; if (photo.getWidth() < photo.getHeight()) { imageMaxWidth = 900;/*w ww . j av a 2 s .c o m*/ imageMaxHeight = 1200; imagePosX = 198; imagePosY = 379; } else { imageMaxWidth = 1200; imageMaxHeight = 900; imagePosX = 162; imagePosY = 379; } OutputStream stream = new ByteArrayOutputStream(); ImageUtilities.scaleCenterCrop(photo, imageMaxWidth, imageMaxHeight).compress(CompressFormat.JPEG, 50, stream); Image coverImage = Image.getInstance(stream.toByteArray()); coverImage.setAbsolutePosition(0.0f, 0.0f); PdfTemplate t = this.writer.getDirectContent().createTemplate((float) imageMaxWidth, (float) imageMaxHeight); t.newPath(); t.moveTo(0.0f, (float) imageMaxHeight); t.lineTo(0.0f, 71.0f); t.lineTo(17.0f, 71.0f); t.lineTo(17.0f, 0.0f); t.lineTo(72.0f, 71.0f); t.lineTo((float) imageMaxWidth, 71.0f); t.lineTo((float) imageMaxWidth, (float) imageMaxHeight); t.lineTo(0.0f, (float) imageMaxHeight); t.closePath(); t.clip(); t.newPath(); t.addImage(coverImage); t.setColorStroke(new BaseColor(0, 0, 0)); t.setLineWidth(BUBBLE_TEXT_INDENT_ALTERNATE); t.newPath(); t.moveTo(0.0f, (float) imageMaxHeight); t.lineTo(0.0f, 71.0f); t.lineTo(17.0f, 71.0f); t.lineTo(17.0f, 0.0f); t.lineTo(72.0f, 71.0f); t.lineTo((float) imageMaxWidth, 71.0f); t.lineTo((float) imageMaxWidth, (float) imageMaxHeight); t.lineTo(0.0f, (float) imageMaxHeight); t.closePathStroke(); Image clipped = Image.getInstance(t); clipped.scalePercent(24.0f); clipped.setAbsolutePosition((float) imagePosX, (float) imagePosY); clipped.setCompressionLevel(this.settings.compressionLevel); clipped.setAlignment(5); document.add(clipped); } if (coverTitle != null && coverTitle.length() > 0) { PdfContentByte canvas = this.writer.getDirectContent(); Paragraph coverTitleEl = new Paragraph(coverTitle, this.serifFont24); coverTitleEl.setAlignment(1); PdfPTable table = new PdfPTable(1); table.setTotalWidth(311.0f); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(coverTitleEl); cell.setPadding(0.0f); cell.setIndent(0.0f); table.addCell(cell); table.completeRow(); table.writeSelectedRows(0, -1, 147.0f, 390.0f, canvas); } return Boolean.valueOf(true); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createBackCoverPage(Document document, String backCoverNote) throws DocumentException, MalformedURLException, IOException { document.newPage();//from ww w . j a va 2 s. c o m Image backCoverImageFrame = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/txtbook_backpage_300.png")); backCoverImageFrame.scalePercent(24.0f); backCoverImageFrame.setAbsolutePosition(87.0f, 78.0f); backCoverImageFrame.setCompressionLevel(this.settings.compressionLevel); document.add(backCoverImageFrame); PdfContentByte canvas = this.writer.getDirectContent(); PdfPTable table = new PdfPTable(1); table.setTotalWidth(215.0f); if (backCoverNote != null && backCoverNote.length() > 0) { Paragraph backCoverEl = new Paragraph(backCoverNote, this.serifFont14); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(backCoverEl); cell.setPadding(13.0f); cell.setIndent(0.0f); cell.setFixedHeight(310.0f); table.addCell(cell); table.completeRow(); } Element backUrl = new Anchor("txt-book.com", this.sansFont11Gray); backUrl.setName("txt-book.com"); backUrl.setReference("http://www.txt-book.com"); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(2); paragraph.add(backUrl); PdfPCell cell2 = new PdfPCell(); cell2.setBorder(0); cell2.setHorizontalAlignment(2); cell2.addElement(paragraph); cell2.setPadding(0.0f); cell2.setPaddingTop(0.0f); cell2.setIndent(0.0f); table.addCell(cell2); table.completeRow(); table.writeSelectedRows(0, -1, 306.0f, 400.0f, canvas); return Boolean.valueOf(true); }
From source file:de.beimax.talenttree.PageGeneratorSimple.java
License:Open Source License
/** * get celled talent text// ww w.j a v a2s. c om * @param key * @param talentBoxWidth * @param fontSize * @return * @throws Exception */ protected PdfPTable getTalentCell(String key, float talentBoxWidth, float fontSize) throws Exception { // get phrase Phrase phrase = parseTextProperty(key, fontSize, true); // table text PdfPTable table = new PdfPTable(1); table.setTotalWidth(talentBoxWidth - PDFGenerator.talentBoxStroke * 3); table.setLockedWidth(true); PdfPCell cell = new PdfPCell(phrase); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); table.completeRow(); return table; }
From source file:ExternalNonFormClasses.PDFEnator.java
public void createPDF() { try {/*from w w w . j ava2s . com*/ Rectangle one = new Rectangle(PageSize.LETTER); Document doc = new Document(one); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(getDirectory() + "\\" + data_title + ".pdf")); //doc.setMargins(1, 1, 1, 1); doc.open(); PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 11); x = one.getWidth(); y = one.getHeight(); tableX = (x / 2) - 235; tableY = y - 180; getHeader(); Paragraph para = new Paragraph("Province of " + formHeaderValues[0], font); para.setAlignment(Element.ALIGN_CENTER); doc.add(para); Paragraph para2 = new Paragraph("City/Municipality of " + formHeaderValues[1], font); para2.setAlignment(Element.ALIGN_CENTER); doc.add(para2); Paragraph para3 = new Paragraph("Barangay " + formHeaderValues[2], font); para3.setAlignment(Element.ALIGN_CENTER); doc.add(para3); doc.add(Chunk.NEWLINE); doc.add(Chunk.NEWLINE); Paragraph para4 = new Paragraph(data_title, font); para4.setAlignment(Element.ALIGN_CENTER); doc.add(para4); PdfPTable pdftable; pdftable = writeHeaders(font); //pdftable.writeSelectedRows(0, -1, (x / 2) - 235, y - 180, canvas); int counter = 1, rowCounter = 0, columnCounter = 0; int yIncrementor = 16; boolean test = true; while (counter <= this.totalDataSize) { //System.out.println("data#: " + counter + "@ (" + rowCounter + "," + (columnCounter) + ") = " + this.table.getValueAt(rowCounter, columnCounter).toString()); PdfPCell cell1 = new PdfPCell( new Paragraph(this.table.getValueAt(rowCounter, columnCounter++).toString(), font)); cell1.setPaddingBottom(5); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell1); if (counter > 0 && (counter % column) == 0) { //if there are 4 columns //pdftable.writeSelectedRows(0, -1, (x / 2) - 235, (y - 180) - yIncrementor, canvas); //print row of 4 columns yIncrementor += 16; //move to next row coordinate, so y coordinate plus plus rowCounter++; //move to next row columnCounter = 0; //back to start column boolean newPage = false; if ((tableY - ((yIncrementor - 16) + 80)) <= 72) { //if it exceeds 1 inch in footer, new page // System.out.println("(" + tableY + "-((" + yIncrementor + "-16)+" + 16 + "))"); // System.out.println("Nanobra? YES; " + (tableY - ((yIncrementor - 16) + 16))); newPage = true; } else if ((tableY - (yIncrementor + 80)) <= 72) { // System.out.println("(" + tableY + "-(" + yIncrementor + "+" + 16 + "))"); // System.out.println("Nanobra? YES; " + (tableY - (yIncrementor + 16))); newPage = true; } if (newPage) { pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); //print the data for the current page doc.newPage(); //create new page pdftable = writeHeaders(font); //write headers to new page yIncrementor = 16; //restore default } } // if (counter == this.totalDataSize) { //para lng mudouble ang data // if (test) { // test = false; // counter = 0; // rowCounter = 0; // columnCounter = 0; // } // } else if (counter == this.totalDataSize) { // if (!test) { // break; // } // } counter++; } pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); doc.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(PDFEnator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ExternalNonFormClasses.PDFEnator.java
public void createProfilePDF(String id, ArrayList<String> data) { this.data_title = "Citizen Profile"; this.table = null; this.caller = 4; this.row = 17; this.column = 2; this.personID = id; this.totalDataSize = row * column; tableHeaderData = new ArrayList<>(); tableHeaderData.add("Label"); tableHeaderData.add("Information"); ArrayList<String> dataAll = data; try {//from ww w .j av a2 s .co m getHeader(); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(getDirectory() + "\\" + data_title + ".pdf")); Rectangle one = new Rectangle(PageSize.LETTER); doc.setPageSize(one); //doc.setMargins(1, 1, 1, 1); doc.open(); PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 11); x = one.getWidth(); y = one.getHeight(); tableX = (x / 2) - 235; tableY = y - 180; Paragraph para = new Paragraph("Province of " + formHeaderValues[0], font); para.setAlignment(Element.ALIGN_CENTER); doc.add(para); Paragraph para2 = new Paragraph("City/Municipality of " + formHeaderValues[1], font); para2.setAlignment(Element.ALIGN_CENTER); doc.add(para2); Paragraph para3 = new Paragraph("Barangay " + formHeaderValues[2], font); para3.setAlignment(Element.ALIGN_CENTER); doc.add(para3); Paragraph para4 = new Paragraph(data_title, font); para4.setAlignment(Element.ALIGN_CENTER); doc.add(para4); PdfPTable pdftable; pdftable = writeHeaders(font); int counter = 1, rowCounter = 0, columnCounter = 0; int yIncrementor = 16; String label = null, value = null; System.out.println(dataAll.size()); while (counter <= this.row) { switch (counter - 1) { case 0: label = "Citizen ID"; value = id; break; case 1: label = "Last Name"; value = dataAll.get(counter - 2); break; case 2: label = "First Name"; value = dataAll.get(counter - 2); break; case 3: label = "Middle Name"; value = dataAll.get(counter - 2); break; case 4: label = "Name Suffix"; value = dataAll.get(counter - 2); break; case 5: label = "Date of Birth"; value = dataAll.get(counter - 2); break; case 6: label = "Gender"; value = dataAll.get(counter - 2); break; case 7: label = "Address"; value = dataAll.get(counter - 2); break; case 8: label = "Age"; value = dataAll.get(counter - 2); break; case 9: label = "Place of Birth"; value = dataAll.get(counter - 2); break; case 10: label = "Civil Status"; value = dataAll.get(counter - 2); break; case 11: label = "Contact"; value = dataAll.get(counter - 2); break; case 12: label = "Zip Code"; value = dataAll.get(counter - 2); break; case 13: label = "Precinct Number"; value = dataAll.get(counter - 2); break; case 14: label = "Occupation"; value = dataAll.get(counter - 2); break; case 15: label = "Email Address"; value = dataAll.get(counter - 2); break; case 16: label = "Religion"; value = dataAll.get(counter - 2); break; } if (value.length() <= 0) { value = "N/A"; } System.out.println(label + ": " + value); PdfPCell cell1 = new PdfPCell(new Paragraph(label, font)); cell1.setPaddingBottom(5); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Paragraph(value, font)); cell2.setPaddingBottom(5); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell2); if (counter > 0 && (counter % column) == 0) { //if there are 4 columns yIncrementor += 16; //move to next row coordinate, so y coordinate plus plus rowCounter++; //move to next row columnCounter = 0; //back to start column boolean newPage = false; if ((tableY - ((yIncrementor - 16) + 80)) <= 72 || (tableY - (yIncrementor + 80)) <= 72) { //if it exceeds 1 inch in footer, new page newPage = true; } if (newPage) { pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); //print the data for the current page doc.newPage(); //create new page pdftable = writeHeaders(font); //write headers to new page yIncrementor = 16; //restore default } } counter++; } pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); doc.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(PDFEnator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Builds the Patient Info Table - Info unique to the patient * * @param patientItem the patient item//w ww . ja v a 2s . c o m * @return PdfPTable the itext table to add to the document * @throws DocumentException */ public PdfPTable createPatientInfoTable(PatientItem patientItem) throws DocumentException { PdfPTable table = getDefaultTable(3); table.addCell(getStyledPhrase("Patient ID: ", Integer.toString(patientItem.getId()))); table.completeRow(); // Row 1 table.addCell(getStyledPhrase("Name: ", patientItem.getFirstName() + " " + patientItem.getLastName())); table.addCell(getStyledPhrase("DOB: ", outputStringOrNA(patientItem.getFriendlyDateOfBirth()))); table.addCell(getStyledPhrase("Age: ", outputStringOrNA((patientItem.getAge())))); // Row 2 table.addCell(getStyledPhrase("Sex: ", outputStringOrNA(patientItem.getSex()))); //[FEMR-113] Contributed by Robert Massicotte during the CEN5035 course at FSU int patientHeightFeet = patientItem.getHeightFeet(); int patientHeightInches = patientItem.getHeightInches(); if (patientHeightFeet == 0 && patientHeightInches == 0) { // display null height as N/A table.addCell(getStyledPhrase("Height: ", "N/A")); } else { // otherwise, display normally (e.g. 5'8") table.addCell(getStyledPhrase("Height: ", outputHeightOrNA(patientHeightFeet, patientHeightInches))); } table.addCell(getStyledPhrase("Weight: ", outputFloatOrNA(patientItem.getWeight()) + " lbs")); table.completeRow(); // Row 3 table.addCell(getStyledPhrase("City: ", outputStringOrNA(patientItem.getCity()))); table.addCell(getStyledPhrase("Address: ", outputStringOrNA(patientItem.getAddress()))); table.addCell(getStyledPhrase("Phone Number: ", outputStringOrNA(patientItem.getPhoneNumber()))); table.completeRow(); return table; }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Builds the Vitals Table - The vitals of the encounter * * @param encounter the encounter item/*from ww w .ja v a2s .co m*/ * @param vitalMap the map of the vital values * @return PdfPTable the itext table to add to the document */ private PdfPTable createVitalsTable(PatientEncounterItem encounter, VitalMultiMap vitalMap) { PdfPTable table = getDefaultTable(3); table.addCell(getDefaultHeaderCell("Patient Vitals", 3)); table.addCell(getVitalMapCell("Blood Pressure: ", "bloodPressure", vitalMap)); table.addCell(getVitalMapCell("Temperature:", "temperature", vitalMap)); table.addCell(getVitalMapCell("Glucose:", "glucose", vitalMap)); table.addCell(getVitalMapCell("Heart Rate: ", "bloodPressure", vitalMap)); table.addCell(getVitalMapCell("Respiration Rate:", "respiratoryRate", vitalMap)); table.addCell(getVitalMapCell("Oxygen Saturation:", "oxygenSaturation", vitalMap)); //Sam Zanni PdfPCell cell = new PdfPCell(table.getDefaultCell()); cell.setPaddingTop(2); table.addCell(getVitalMapCell("Weeks Pregnant:", "weeksPregnant", vitalMap)); table.completeRow(); return table; }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Builds the Assessments Table - The assessment fields for the encounter * * @param tabFieldMultiMap multimap of the encounter's tab fields * @param prescriptionItems a list of the encounter's prescriptions * @param problemItems a list of the encounter's problems * @return PdfPTable the itext table to add to the document *///w ww . j ava 2 s . c o m private PdfPTable getAssessments(TabFieldMultiMap tabFieldMultiMap, List<PrescriptionItem> prescriptionItems, List<ProblemItem> problemItems) { PdfPTable table = getDefaultTable(3); //Set table to span 3 columns to counteract tablesize for dispensed prescriptions table.addCell(getDefaultHeaderCell("Assessments", 3)); // Row 1 PdfPCell cellMSH = new PdfPCell(table.getDefaultCell()); TabFieldItem msh = tabFieldMultiMap.getMostRecentOrEmpty("medicalSurgicalHistory", null); cellMSH.addElement(getStyledPhrase("Medical Surgical History: ", outputStringOrNA(msh.getValue()))); cellMSH.setColspan(3); table.addCell(cellMSH); // Row 2 PdfPCell cellCM = new PdfPCell(table.getDefaultCell()); TabFieldItem cm = tabFieldMultiMap.getMostRecentOrEmpty("currentMedication", null); cellCM.addElement(getStyledPhrase("Medication: ", outputStringOrNA(cm.getValue()))); cellCM.setColspan(3); table.addCell(cellCM); // Row 3 PdfPCell cellSH = new PdfPCell(table.getDefaultCell()); TabFieldItem sh = tabFieldMultiMap.getMostRecentOrEmpty("socialHistory", null); cellSH.addElement(getStyledPhrase("Social History: ", outputStringOrNA(sh.getValue()))); cellSH.setColspan(3); table.addCell(cellSH); // Row 4 PdfPCell cellAssesment = new PdfPCell(table.getDefaultCell()); TabFieldItem assessment = tabFieldMultiMap.getMostRecentOrEmpty("assessment", null); cellAssesment.addElement(getStyledPhrase("Assessment: ", outputStringOrNA(assessment.getValue()))); cellAssesment.setColspan(3); table.addCell(cellAssesment); // Row 5 PdfPCell cellFH = new PdfPCell(table.getDefaultCell()); TabFieldItem fh = tabFieldMultiMap.getMostRecentOrEmpty("familyHistory", null); cellFH.addElement(getStyledPhrase("Family History: ", outputStringOrNA(fh.getValue()))); cellFH.setColspan(3); table.addCell(cellFH); // Row 6 PdfPCell cellTreatment = new PdfPCell(table.getDefaultCell()); TabFieldItem treatment = tabFieldMultiMap.getMostRecentOrEmpty("procedure_counseling", null); cellTreatment.addElement(getStyledPhrase("Procedure/Counseling: ", outputStringOrNA(treatment.getValue()))); cellTreatment.setColspan(3); table.addCell(cellTreatment); // Loop through and add any potential Custom Field Names // Row 7+ , set cells to colspan of 2 so they fill the whole page for (String customField : tabFieldMultiMap.getCustomFieldNameList()) { String value = tabFieldMultiMap.getMostRecentOrEmpty(customField, null).getValue(); PdfPCell customCell = new PdfPCell(table.getDefaultCell()); customCell.setColspan(3); customCell.addElement(getStyledPhrase(customField + " :", outputStringOrNA(value))); table.addCell(customCell); } // AJ Saclayan Dispensed Table Paragraph prescriptionsTitle = new Paragraph("Dispensed Prescription(s):", getTitleFont()); PdfPCell prescriptionCell = new PdfPCell(table.getDefaultCell()); prescriptionCell.setPaddingRight(10); prescriptionCell.addElement(prescriptionsTitle); prescriptionCell.setColspan(3); table.addCell(prescriptionCell); table.completeRow(); if (!prescriptionItems.isEmpty()) { //Create Dispensed Table. Paragraph originalMedsTitle = new Paragraph("Original", getTitleFont()); PdfPCell cell = new PdfPCell(originalMedsTitle); table.addCell(cell); Paragraph replacedMedsTitle = new Paragraph("Replacement", getTitleFont()); cell = new PdfPCell(replacedMedsTitle); table.addCell(cell); table.completeRow(); for (PrescriptionItem prescription : prescriptionItems) { String medicationForm = prescription.getMedicationForm(); if (medicationForm == null || medicationForm.equals("")) { medicationForm = "N/A"; } else { medicationForm = medicationForm.trim(); } if (prescription.getReplacementMedicationName() != null) { Paragraph originalMedName = new Paragraph( "Prescription #" + prescription.getId() + " - Replaced \n" + prescription.getAmount() + " " + prescription.getName() + " (" + medicationForm + ")", getValueFont()); cell = new PdfPCell(originalMedName); table.addCell(cell); Paragraph replacedMedName = new Paragraph("Prescription #" + prescription.getReplacementId() + " \n" + prescription.getReplacementAmount() + " " + prescription.getReplacementMedicationName(), getValueFont()); cell = new PdfPCell(replacedMedName); table.addCell(cell); } else { Paragraph medName = new Paragraph("Prescription #" + prescription.getId() + "\n" + prescription.getAmount() + " " + prescription.getName() + " (" + medicationForm + ")", getValueFont()); cell = new PdfPCell(medName); table.addCell(cell); Paragraph blankCell = new Paragraph(" ", getValueFont()); cell = new PdfPCell(blankCell); table.addCell(cell); } table.completeRow(); } } // Get Problems Paragraph problemsTitle = new Paragraph("Problem(s):", getTitleFont()); PdfPCell problemsCell = new PdfPCell(table.getDefaultCell()); problemsCell.addElement(problemsTitle); for (ProblemItem problem : problemItems) { Paragraph probText = new Paragraph(" - " + problem.getName(), getValueFont()); problemsCell.addElement(probText); } table.addCell(problemsCell); table.completeRow(); return table; }