List of usage examples for com.itextpdf.text Document setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java
@Override public void enregistrerBulletin() { if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) { if (eleveAnneeClasse.getId() != null) { classematieres.clear();//from w ww . j ava 2 s.c o m matieres.clear(); notesPropres.clear(); matiereCompses.clear(); eleveAnneeClasse = eleveAnneeClasseFacade.find(eleveAnneeClasse.getId()); if (sequence != null) { Annee an = anneeFacade.findByEtatSingle(true); Eleveanneeclasse eleveClasse = eleveAnneeClasseFacade.getEleveAnneeClaseByAnneClasse( eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee()); if (eleveClasse != null) { List<Naturematiere> nature = natureMatiereFacade.findAll(); if (!nature.isEmpty()) { List<Evaluation> notes = evaluationFacadeLocal.getByEleveAnneeSequence( eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee(), sequence.getIdsequencean()); /*if (!notes.isEmpty()) {*/ try { String bulletinName = "" + eleveAnneeClasse.getEleve().getNom() + "_" + eleveAnneeClasse.getEleve().getPrenom() + "_" + sequence.getIdsequence().getNom() + ".pdf"; Document bulletin = new Document(); PdfWriter.getInstance(bulletin, new FileOutputStream(Utilitaires.path + "/" + Utilitaires.repertoireParDefautBulletin + "/" + bulletinName)); bulletin.setMargins(5, 5, 5, 5); bulletin.addCreator("School Manager"); bulletin.setPageSize(PageSize.A4); bulletin.open(); //tableau qui va contenir les notes PdfPTable table = new PdfPTable(5); table.setComplete(true); //entete de bulletin table.addCell( PrintUtils.createPdfPCell("COLLEGE POZAM Anne Scolaire " + an.getCode() + " - " + (an.getCode() + 1) + " " + an.getTheme(), 5, detail)); table.addCell(PrintUtils.createPdfPCell( "BULLETIN DE NOTES DE : " + sequence.getIdsequence().getNom(), 5, true)); table.addCell(PrintUtils .createPdfPCell("Nom : " + eleveAnneeClasse.getEleve().getNom(), 2, false)); PdfPCell cellLogo = new PdfPCell(new Paragraph(" ")); cellLogo.setRowspan(2); table.addCell(cellLogo); table.addCell(PrintUtils.createPdfPCell( "Matricule : " + eleveAnneeClasse.getEleve().getMatricule(), 2, false)); table.addCell(PrintUtils.createPdfPCell( "Prnom : " + eleveAnneeClasse.getEleve().getPrenom(), 2, false)); //table.addCell("kenne"); PdfPCell cellClasse = new PdfPCell( new Paragraph("Classe : " + eleveClasse.getIdclasse().getNom())); cellClasse.setColspan(2); table.addCell(cellClasse); //debut de saisis de notes PdfPTable entete = new PdfPTable(5); table.addCell(new Paragraph("Dicipline")); table.addCell(PrintUtils.createPdfPCell("Note ", true)); table.addCell(PrintUtils.createPdfPCell("Cofficient ", true)); table.addCell(PrintUtils.createPdfPCell("Total", true)); table.addCell(PrintUtils.createPdfPCell("Apprciation", true)); //partie qui contient es totaux PdfPTable total = new PdfPTable(5); int totalCoef = 0; float totalPoint = 0; classematieres = classeMatiereFacade .get(eleveAnneeClasse.getIdclasse().getIdclasse()); if (!classematieres.isEmpty()) { for (Classematiere m : classematieres) { matieres.add(m.getIdmatiere()); } /*for (Evaluation e : notes) { if (matieres.contains(e.getIdmatiere())) { notesPropres.add(e); matiereCompses.add(e.getIdmatiere()); } }*/ for (int i = 0; i < nature.size(); i++) { table.addCell( PrintUtils.createPdfPCell("Matires " + nature.get(i).getLibelle(), 5, false, PrintUtils.blueFont)); int totalCoefBloc = 0; int totalPointBloc = 0; for (int a = 0; a < matieres.size(); a++) { if (matiereCompses.contains(matieres.get(a))) { //if (Objects.equals(notesPropres.get(a).getIdmatiere(), nature.get(i).getIdnaturematiere())) {; //decompte des coefficient et nombre point globaux //totalCoef += notesPropres.get(a).getIdmatiere().getCoeficient(); // totalPoint += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient(); //decompte des coef et point par groupe //totalCoefBloc += notesPropres.get(a).getIdmatiere().getCoeficient(); //totalPointBloc += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient(); // table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getNote(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); //table.addCell(PrintUtils.createPdfPCell("" + (notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient()), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getObservation(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC))); // } } else { if (Objects.equals( matieres.get(a).getIdnaturematiere().getIdnaturematiere(), nature.get(i).getIdnaturematiere())) { //decompte des coefficient et nombre point globaux // totalCoef += matieres.get(a).get totalPoint += 0; //decompte des coef et point par groupe // totalCoefBloc += matieres.get(a).getCoeficient(); totalPointBloc += 0; // table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("O", true, new Font( Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); // table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("0", true, new Font( Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("Pas encore valu", true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC))); } } } //le texte Total pour chaque bloc PdfPCell cellTotalBlocText = new PdfPCell( new Paragraph("Total Matires " + nature.get(i).getLibelle() + " ", new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); cellTotalBlocText.setColspan(2); table.addCell(cellTotalBlocText); table.addCell(PrintUtils.createPdfPCell("" + totalCoefBloc, true, new Font( Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED))); table.addCell(PrintUtils.createPdfPCell("" + totalPointBloc, 2, true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED))); table.addCell(PrintUtils.createPdfPCell( "Moyenne Matires " + nature.get(i).getLibelle(), 3, false, PrintUtils.blueFont)); if (totalCoefBloc != 0) { table.addCell(PrintUtils.createPdfPCell( "" + (totalPointBloc / totalCoefBloc) + "/20", 2, true, PrintUtils.redFont)); } else { table.addCell(PrintUtils.createPdfPCell("......", 2, true, PrintUtils.redFont)); } table.addCell(PrintUtils.createPdfPCell(" ", 5, false)); } } else { } //on ecrit totaux table.addCell(PrintUtils.createPdfPCell("Totaux ", 2, false, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE))); //on met le total de coefficient table.addCell(PrintUtils.createPdfPCell("" + totalCoef, true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED))); //on met le total de point table.addCell(PrintUtils.createPdfPCell("" + totalPoint, 2, true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED))); table.addCell(PrintUtils.createPdfPCell( "Moyenne de la " + sequence.getIdsequence().getNom(), 3, false, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLUE))); if (totalCoef != 0) { table.addCell(PrintUtils.createPdfPCell((totalPoint / totalCoef) + "/20", 2, true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED))); } bulletin.add(table); bulletin.close(); JsfUtil.addSuccessMessage( "Opration russie,redirigez-vous dans le repertoire bulletin"); } catch (DocumentException ex) { Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex); } /*} else { JsfUtil.addErrorMessage("L'lve selectionn n a aucune note la squence slectionne"); }*/ } else { JsfUtil.addErrorMessage("Aucune nature de matiere parametre"); } } else { JsfUtil.addErrorMessage("l'eleve n a pas de classe"); } } else { JsfUtil.addErrorMessage("veuillez selectionner une squence !"); } } else { JsfUtil.addErrorMessage("Veuillez selectionner un lve"); } } else { String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); try { FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html"); } catch (IOException ex) { Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java
@Override public void imprimerListeClasse() { if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) { if (classe != null) { Annee an = anneeFacade.findByEtatSingle(true); if (an != null) { List<Eleveanneeclasse> elevs = eleveAnneeClasseFacade.findByAnneeClasse(an.getIdannee(), classe.getIdclasse()); if (!elevs.isEmpty()) { try { String listeName = "liste_des_eleve_" + classe.getNom() + ".pdf"; Document liste = new Document(); liste.setMargins(2, 2, 2, 2); PdfWriter.getInstance(liste, new FileOutputStream(Utilitaires.path + "/" + Utilitaires.repertoireParDefautClasse + "/" + listeName)); liste.open();// w w w . j a v a 2 s . co m PdfPTable table = new PdfPTable(4); table.setComplete(true); table.addCell(PrintUtils.createPdfPCell("Liste des lves de la " + classe.getNom() + " Anne Scolaire : " + an.getCode() + " - " + (an.getCode() + 1), 4, true)); table.addCell(PrintUtils.createPdfPCell("NOM", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("PRENOM", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("MATRICULE", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("DATE DE NAISSANCE", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); //debut d'ecriture des lignes; for (int i = 0; i < elevs.size(); i++) { table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getNom(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getPrenom(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getMatricule(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell( "" + elevs.get(i).getEleve().getDatenaissance().getDay() + "-" + elevs.get(i).getEleve().getDatenaissance().getMonth() + "-" + elevs.get(i).getEleve().getDatenaissance().getYear(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); } liste.add(table); liste.close(); JsfUtil.addSuccessMessage("Impression russie !"); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex); } } else { JsfUtil.addErrorMessage("La classe selectionne n'a aucune !"); } } else { JsfUtil.addFatalErrorMessage("L'anne en cours n'est pas parametre"); } } else { JsfUtil.addErrorMessage("Veuillez selectionner une classe !"); } } else { String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); try { FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html"); } catch (IOException ex) { Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:gestionEtat.imprimerListeEleve.ListeEleveCtrl.java
@Override public void imprimerListeClasse() { if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) { if (classe != null) { Annee an = anneeFacade.findByEtatSingle(true); if (an != null) { List<Eleveanneeclasse> elevs = eleveAnneeClasseFacade.findByAnneeClasse(an.getIdannee(), classe.getIdclasse()); if (!elevs.isEmpty()) { try { String listeName = "liste_des_eleve_" + classe.getNom() + ".pdf"; Document liste = new Document(); liste.setMargins(2, 2, 2, 2); PdfWriter.getInstance(liste, new FileOutputStream(Utilitaires.path + "/" + Utilitaires.repertoireParDefautClasse + "/" + listeName)); liste.open();//w w w . j a v a 2 s . c o m PdfPTable table = new PdfPTable(4); table.setComplete(true); table.addCell(PrintUtils.createPdfPCell("Liste des lves de la " + classe.getNom() + " Anne Scolaire : " + an.getCode() + " - " + (an.getCode() + 1), 4, true)); table.addCell(PrintUtils.createPdfPCell("NOM", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("PRENOM", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("MATRICULE", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("DATE DE NAISSANCE", true, new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL))); //debut d'ecriture des lignes; for (int i = 0; i < elevs.size(); i++) { table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getNom(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getPrenom(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getMatricule(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell( "" + elevs.get(i).getEleve().getDatenaissance().getDay() + "-" + elevs.get(i).getEleve().getDatenaissance().getMonth() + "-" + elevs.get(i).getEleve().getDatenaissance().getYear(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); } liste.add(table); liste.close(); JsfUtil.addSuccessMessage("Impression russie !"); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(ListeEleveCtrl.class.getName()).log(Level.SEVERE, null, ex); } } else { JsfUtil.addErrorMessage("La classe selectionne n'a aucune !"); } } else { JsfUtil.addFatalErrorMessage("L'anne en cours n'est pas parametre"); } } else { JsfUtil.addErrorMessage("Veuillez selectionner une classe !"); } } else { String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); try { FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html"); } catch (IOException ex) { Logger.getLogger(ListeEleveCtrl.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:ics4u.ics4u_final_project.Recipe.java
License:Open Source License
/** * Exports the recipe to a PDF/* w w w. j a va 2s .co m*/ * * @param path the path to save the recipe to */ public void export(File path) { //get the Data Database.recipe(this, true, true); //create the new document Document doc = new Document(); try { //create the file PdfWriter.getInstance(doc, new FileOutputStream(path)); } catch (FileNotFoundException | DocumentException ex) { System.out.println("Error: " + ex.toString()); } //set the margins doc.setMargins(36, 36, 18, 18); doc.open(); //add properties to the document addMetaData(doc); //add the data to the document addData(doc); //close the document, finish writing to disk doc.close(); }
From source file:itext_result.Main.java
private int developScreeningSheet() { new SwingWorker<Object, Object>() { String filename;/* w w w. j a v a2 s . c o m*/ @Override protected void done() { // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException { BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.EAN8); barcode.setCode(code); PdfPCell cell = new PdfPCell( barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true); cell.setPadding(10); return cell; } class ImageContent implements PdfPTableEvent { protected com.itextpdf.text.Image content; public ImageContent(com.itextpdf.text.Image content) { this.content = content; } public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { try { PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; float x = widths[3][1] + 10; float y = heights[3] - 10 - content.getScaledHeight(); content.setAbsolutePosition(x, y); canvas.addImage(content); } catch (DocumentException e) { throw new ExceptionConverter(e); } } } @Override protected Object doInBackground() throws Exception { // System.err.println(" Roll No Received ....." + rollno); Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A5); doc.setMargins(15f, 15f, 15f, 15f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); //DONE BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN8); Barcode128 code128 = new Barcode128(); code128.setCode(String.valueOf("123456")); Barcode128 code128_jacket = new Barcode128(); code128_jacket.setCode(String.valueOf("10345")); codeEAN.setCode(String.valueOf("123456")); com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null); // imageEAN.scalePercent(10f); //464f, 725f // imageEAN.setAbsolutePosition(474f, 662f); int i = 1; while (i <= pageno) { doc.newPage(); // cb.addImage(imageRight); // cb.addImage(imageEAN); i++; } com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null); carcode.scaleAbsolute(100f, 35f); carcode.setAbsolutePosition(500f, 600f); writer.addDirectImageSimple(carcode); // cb.addImage(carcode); com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null); carcode2.scaleAbsolute(100f, 35f); carcode2.setAbsolutePosition(450f, 760f); writer.addDirectImageSimple(carcode2); // cb.addImage(carcode2); Image image1 = Image.getInstance("jklogo.gif"); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(99); table.addCell(image1); doc.add(table); table = new PdfPTable(4); table.setWidthPercentage(99); float[] columnWidths = { 6, 2 }; PdfPTable CandidateTable = new PdfPTable(columnWidths); Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall)); PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall)); // DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // String today = formatter.format(cInfo.getDob()); PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall)); PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall)); PdfPCell type = new PdfPCell(new Phrase("Total Time #" + String.valueOf("350.00"), fsmall)); // String scrtoday = formatter.format(cInfo.getScreeningdate()); // System.out.println("Today : " + today); PdfPCell scrdate = new PdfPCell(new Phrase("Laps #" + String.valueOf("4"), fsmall)); PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall)); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); CandidateTable.addCell(rollno); CandidateTable.addCell(cell); CandidateTable.addCell(cname); CandidateTable.addCell(cell); CandidateTable.addCell(dob); CandidateTable.addCell(cell); PdfPTable CandidateOtherTable = new PdfPTable(columnWidths); CandidateOtherTable.addCell(fname); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(scrdate); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(type); CandidateOtherTable.addCell(cell); PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall)); PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall)); PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00 ", fsmall)); race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths); CandidateRaceDetails.addCell(race_start_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_end_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_total_time); CandidateRaceDetails.addCell(cell); PdfPTable tablewith3cells = new PdfPTable(3); //1 St Col for Roll No Name and DOB tablewith3cells.addCell(CandidateTable); //2 nd Col for Father Name sCREEning Date Gurkha tablewith3cells.addCell(CandidateOtherTable); //3rd Col for Barcode to be Printed tablewith3cells.addCell(CandidateRaceDetails); // Setting the Width here to 101 tablewith3cells.setWidthPercentage(99); doc.add(tablewith3cells); PdfPTable userArea = new PdfPTable(1); userArea.setWidthPercentage(99); userArea.addCell(" \n \n Congratulations \n \n "); doc.add(userArea); PdfPTable footerCSBC = new PdfPTable(2); footerCSBC.setWidthPercentage(99); PdfPCell height_box = new PdfPCell(new Phrase("Height \n\n\n", f)); height_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_box = new PdfPCell(new Phrase("Chest \n\n\n", f)); chest_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp \n\n\n", f)); chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup \n\n\n", f)); pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX); //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); footerCSBC.addCell(height_box); footerCSBC.addCell(chest_box); footerCSBC.addCell(chest_exp_box); footerCSBC.addCell(pushup_box); doc.add(footerCSBC); float[] columnWidths_ForBarcode = { 6, 3 }; PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode); // terminalinfo.setWidthPercentage(99); String computername = InetAddress.getLocalHost().getHostName(); System.out.println(computername); PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f)); String UserMatchScore = "\t Barcode\n\n"; PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f)); PdfPCell barcode = new PdfPCell(carcode2); PdfPCell jacketnumber = new PdfPCell(carcode); pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); terminalinfo.addCell(score); terminalinfo.addCell(pcname); terminalinfo.addCell(barcode); terminalinfo.addCell(jacketnumber); doc.add(terminalinfo); PdfPCell eula_notice = new PdfPCell(new Phrase(" ", f)); eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable eula_notice_table = new PdfPTable(1); eula_notice_table.setWidthPercentage(25); eula_notice_table.addCell(eula_notice); doc.add(eula_notice_table); } catch (Exception e) { System.err.println(e.getMessage()); // ConsoleMsg(e.getMessage()); } finally { doc.close(); doc.close(); doc.close(); } //ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); return 0; }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
private int saveSheet(Document document, int listCount, ReportModel model) throws DocumentException, IOException, SaveReportException { model.updatePages(0);// w ww .j av a 2 s .c o m ReportPage pageFormat = model.getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle((float) paper.getWidth(), (float) paper.getHeight()); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } document.setPageSize(pageSize); document.setMargins((float) pageFormat.getLeftMargin(Units.PT), (float) pageFormat.getRightMargin(Units.PT), (float) pageFormat.getTopMargin(Units.PT), (float) pageFormat.getBottomMargin(Units.PT)); if (listCount > 0) { document.newPage(); } listCount++; TableRowModel rowModel = model.getRowModel(); float columnMargin = (float) Units.PT.setXPixels(model.getColumnModel().getColumnMargin()); ReportPrintable printable = new ReportPrintable(model); int pageCount = printable.calcCountPage(model.getReportPage()); Map<Integer, PageClip> clips = printable.getPageClips(); int leftCol; int topRow; int rightCol; int bottomRow; for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) { PageClip pageClip = clips.get(pageIndex); if (pageClip == null) break; leftCol = pageClip.getLeftCol(); rightCol = pageClip.getRightCol(); topRow = pageClip.getTopRow(); bottomRow = pageClip.getBottomRow(); int columnCount = rightCol - leftCol; float[] widths = new float[columnCount]; for (int c = 0; c < widths.length; c++) { ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c); widths[c] = (float) column.getNativeWidth() + columnMargin; } PdfPTable table = createPdfTable(columnCount, widths, document.getPageSize()); for (int row = topRow; row < bottomRow; row++) { TableRow reportRow = rowModel.getRow(row); for (int col = leftCol; col < rightCol; col++) { jdbreport.model.Cell srcCell = reportRow.getCellItem(col); if (!srcCell.isChild()) { PdfPCell pdfCell = writeCell(model, srcCell, row, col); table.addCell(pdfCell); } } } document.add(table); if (pageIndex < clips.size()) { document.newPage(); } } return listCount; }
From source file:jsimpresos.ConexionCorteCaja.java
public void crearPdf(int idCorte) { try {//from w w w . j a va 2 s. c o m String query1 = "select * from detalleabono where idcorte=?"; PreparedStatement st = this.getConexion().prepareStatement(query1); st.setInt(1, idCorte); ResultSet rs = st.executeQuery(); ArrayList<Abono> abonos = new ArrayList(); while (rs.next()) { abonos.add(new Abono(rs.getInt(1), rs.getDouble(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getInt(6))); } String query2 = "select * from transaccionesmiembro where idcorte=?"; PreparedStatement st2 = this.getConexion().prepareStatement(query2); st2.setInt(1, idCorte); ResultSet rs2 = st2.executeQuery(); ArrayList<TransaccionesMiembro> transaccionesMiembro = new ArrayList(); while (rs2.next()) { transaccionesMiembro.add(new TransaccionesMiembro(rs2.getInt(1), rs2.getString(2), rs2.getDouble(3), rs2.getString(4), rs2.getInt(5))); } String query3 = "select * from cortesdecaja where idcorte =?"; PreparedStatement st3 = this.getConexion().prepareStatement(query3); st3.setInt(1, idCorte); ResultSet rs3 = st3.executeQuery(); String fecha = ""; while (rs3.next()) { fecha = Fechas.convertirFecha(rs3.getString(2)); } ArrayList<Abono> abonosEfectivo = new ArrayList(); ArrayList<Abono> abonosTarjeta = new ArrayList(); ArrayList<TransaccionesMiembro> recargasSaldo = new ArrayList(); ArrayList<TransaccionesMiembro> transaccionesPaypal = new ArrayList(); ArrayList<TransaccionesMiembro> registrosCliente = new ArrayList(); for (int i = 0; i < abonos.size(); i++) { String tipo = abonos.get(i).getTipoPago(); switch (tipo) { case "Efectivo": abonosEfectivo.add(abonos.get(i)); break; case "Tarjeta": abonosTarjeta.add(abonos.get(i)); break; } } for (int i = 0; i < transaccionesMiembro.size(); i++) { String tipo = transaccionesMiembro.get(i).getMovimiento(); switch (tipo) { case "Recarga": recargasSaldo.add(transaccionesMiembro.get(i)); break; case "Paypal": transaccionesPaypal.add(transaccionesMiembro.get(i)); break; case "Registro": registrosCliente.add(transaccionesMiembro.get(i)); break; } } int mayorEfectivo; if (abonosEfectivo.size() >= recargasSaldo.size() && abonosEfectivo.size() >= registrosCliente.size()) { mayorEfectivo = abonosEfectivo.size(); } else { if (recargasSaldo.size() >= registrosCliente.size()) { mayorEfectivo = recargasSaldo.size(); } else { mayorEfectivo = registrosCliente.size(); } } int mayorOtros; if (abonosTarjeta.size() >= transaccionesPaypal.size()) { mayorOtros = abonosTarjeta.size(); } else { mayorOtros = transaccionesPaypal.size(); } Document documento = new Document(); FileOutputStream ficheroPdf; try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/corte.pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); PdfPTable tabla = new PdfPTable(8); tabla.setWidths(new float[] { 20, 10, 10, 20, 10, 10, 20, 10 }); tabla.setWidthPercentage(100); PdfPCell celdaVacia = new PdfPCell(new Paragraph(" ")); celdaVacia.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda1 = new PdfPCell(new Paragraph("Corte de caja del da " + fecha, FontFactory.getFont("Arial", 12, Font.BOLD))); celda1.setColspan(3); celda1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda1); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda2 = new PdfPCell( new Paragraph("Transacciones en efectivo: ", FontFactory.getFont("Arial", 11, Font.BOLD))); celda2.setColspan(3); celda2.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda2); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda3 = new PdfPCell( new Paragraph("Abonos en efectivo", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Paragraph("Monto", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda4); tabla.addCell(celdaVacia); PdfPCell celda5 = new PdfPCell( new Paragraph("Recargas de saldo", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda5); tabla.addCell(celda4); tabla.addCell(celdaVacia); PdfPCell celda6 = new PdfPCell( new Paragraph("Registro de clientes", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda6); tabla.addCell(celda4); double totalAbonosEfectivo = 0; double totalRecargasSaldo = 0; double totalRegistrosCliente = 0; for (int i = 0; i <= mayorEfectivo; i++) { if (abonosEfectivo.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Abono a la nota " + abonosEfectivo.get(i).getId(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + abonosEfectivo.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalAbonosEfectivo += abonosEfectivo.get(i).getMonto(); } else { if (abonosEfectivo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalAbonosEfectivo, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (recargasSaldo.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Recarga al cliente " + recargasSaldo.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + recargasSaldo.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalRecargasSaldo += recargasSaldo.get(i).getMonto(); } else { if (recargasSaldo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalRecargasSaldo, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (registrosCliente.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Registro del cliente " + registrosCliente.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + registrosCliente.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalRegistrosCliente += registrosCliente.get(i).getMonto(); } else { if (recargasSaldo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalRegistrosCliente, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } } PdfPCell celda9 = new PdfPCell(new Paragraph( "Total de pagos en efectivo: $" + (totalAbonosEfectivo + totalRecargasSaldo + totalRegistrosCliente), FontFactory.getFont("Arial", 9, Font.BOLD))); celda9.setBorder(Rectangle.NO_BORDER); celda9.setColspan(8); tabla.addCell(celda9); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda10 = new PdfPCell( new Paragraph("Otras transacciones: ", FontFactory.getFont("Arial", 11, Font.BOLD))); celda10.setColspan(3); celda10.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda10); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda11 = new PdfPCell( new Paragraph("Abonos con tarjeta", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda11); PdfPCell celda12 = new PdfPCell( new Paragraph("Monto", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda12); tabla.addCell(celdaVacia); PdfPCell celda13 = new PdfPCell( new Paragraph("Paypal", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda13); tabla.addCell(celda12); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); double totalAbonosTarjeta = 0; double totalPaypal = 0; for (int i = 0; i <= mayorOtros; i++) { if (abonosTarjeta.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Abono a la nota " + abonosTarjeta.get(i).getId(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + abonosTarjeta.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalAbonosTarjeta += abonosTarjeta.get(i).getMonto(); } else { if (abonosTarjeta.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalAbonosTarjeta, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (transaccionesPaypal.size() > i) { PdfPCell celda7 = new PdfPCell(new Paragraph( "Recarga con Paypal al cliente " + transaccionesPaypal.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + transaccionesPaypal.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalPaypal += transaccionesPaypal.get(i).getMonto(); } else { if (transaccionesPaypal.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalPaypal, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } documento.add(tabla); documento.close(); abrirPDF(); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error al generar el pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); } } catch (SQLException ex) { System.out.println(ex.getMessage()); JOptionPane.showMessageDialog(null, "Error al conectar a la base de datos"); } }
From source file:jsimpresos.ConexionNotas.java
public void generarPdf(int idNota, String nombre, int cuenta) { Document documento = new Document(); Nota nota = this.getNotaPorId(idNota); FileOutputStream ficheroPdf;/*from w w w . j a v a2 s . c o m*/ try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); Image foto = Image.getInstance("c:/archivosPuntoDeVenta/logo.JPG"); foto.scaleToFit(80, 90); PdfPTable tabla = new PdfPTable(5); tabla.setWidths(new float[] { 13, 12, 25, 25, 25 }); tabla.setWidthPercentage(100); PdfPCell celda = new PdfPCell(); celda.addElement(foto); celda.setBorder(Rectangle.NO_BORDER); celda.setRowspan(6); tabla.addCell(celda); PdfPCell celda2 = new PdfPCell( new Paragraph("NOTA DE PEDIDO", FontFactory.getFont("Arial", 15, Font.BOLD))); System.out.println(nota.getUsuario()); celda2.setColspan(3); celda2.setUseAscender(true); celda2.setBorder(Rectangle.NO_BORDER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); tabla.addCell(celda2); PdfPCell celdaFecha = new PdfPCell(new Paragraph("Fecha: " + nota.getFecha())); celdaFecha.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaFecha); PdfPCell celda3 = new PdfPCell(new Phrase("Calle del Rayo y 2 de Abril 31a. Col. centro, Parral, Chih.", FontFactory.getFont("Arial", 7, Font.BOLD, BaseColor.RED))); celda3.setColspan(2); celda3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Phrase("Tel. 5230073 y 6271034745", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.RED))); celda4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda4); Paragraph p = new Paragraph("No. " + nota.getIdNota(), FontFactory.getFont("Arial", 13, Font.BOLD, BaseColor.RED)); PdfPCell celda5 = new PdfPCell(); celda5.setUseAscender(true); celda5.setVerticalAlignment(Element.ALIGN_MIDDLE); celda5.setHorizontalAlignment(Element.ALIGN_MIDDLE); celda5.addElement(p); tabla.addCell(celda5); PdfPCell celdanueva = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva.setBorder(Rectangle.NO_BORDER); celdanueva.setColspan(4); tabla.addCell(celdanueva); PdfPCell celdanueva1 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva1); PdfPCell celdanueva2 = new PdfPCell( new Phrase("Datos del cliente", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva2.setBorder(Rectangle.NO_BORDER); celdanueva2.setColspan(3); tabla.addCell(celdanueva2); PdfPCell celdanueva3 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva3); if (nota.getCliente() == null) { PdfPCell celda6 = new PdfPCell( new Phrase("Cliente: " + nota.getNombres() + " " + nota.getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } else { PdfPCell celda6 = new PdfPCell(new Phrase( "Cliente: " + nota.getCliente().getNombres() + " " + nota.getCliente().getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getCliente().getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getCliente().getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } PdfPTable tabla2 = new PdfPTable(4); tabla2.setWidths(new float[] { 10, 70, 15, 15 }); tabla2.setWidthPercentage(99.5f); PdfPCell celda21 = new PdfPCell( new Phrase("Cantidad", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda21); PdfPCell celda22 = new PdfPCell( new Phrase("Artculo", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda22); PdfPCell celda23 = new PdfPCell( new Phrase("Precio unitario", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda23); PdfPCell celda24 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda24); double total = 0; for (int i = 0; i < 6; i++) { if (i < nota.getArticulos().size()) { PdfPCell celda25 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getCantidad() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda25); PdfPCell celda26 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getServicio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda26); PdfPCell celda27 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getPrecio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda27); PdfPCell celda28 = new PdfPCell(new Phrase( (nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio()) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda28); total += nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio(); } else { PdfPCell celda29 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); } } PdfPTable tabla3 = new PdfPTable(4); tabla3.setWidths(new float[] { 55, 25, 15, 15 }); tabla3.setWidthPercentage(99.5f); PdfPCell celda31 = new PdfPCell(new Phrase("Observaciones: " + nota.getObservaciones(), FontFactory.getFont("Arial", 9, BaseColor.BLACK))); celda31.setRowspan(4); tabla3.addCell(celda31); PdfPCell celda32 = new PdfPCell(new Phrase( "Suma recibida de abono : " + nota.getAbonos().get(nota.getAbonos().size() - 1).getMonto(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda32.setRowspan(4); tabla3.addCell(celda32); PdfPCell celda33 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda33); PdfPCell celda34 = new PdfPCell( new Phrase(total + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda34); PdfPCell celda35 = new PdfPCell( new Phrase("Total abonado", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda35); double totalAbonado = 0; for (int i = 0; i < nota.getAbonos().size(); i++) { totalAbonado += nota.getAbonos().get(i).getMonto(); } PdfPCell celda36 = new PdfPCell( new Phrase(totalAbonado + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda36); PdfPCell celda37 = new PdfPCell( new Phrase("Saldo actual", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda37); PdfPCell celda38 = new PdfPCell(new Phrase((total - totalAbonado) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda38); PdfPCell celda39 = new PdfPCell( new Phrase("Fecha entrega", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda39); PdfPCell celda40 = new PdfPCell(new Phrase(nota.getFechaEntrega(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda40); PdfPTable tabla4 = new PdfPTable(3); tabla4.setWidths(new float[] { 30, 30, 30 }); tabla4.setWidthPercentage(99.5f); PdfPCell celda41 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda41.setBorder(Rectangle.NO_BORDER); celda41.setColspan(3); tabla4.addCell(celda41); PdfPCell celda42 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda42.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda42); PdfPCell celda43 = new PdfPCell(new Phrase("Firma de conformidad del cliente: ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda43.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda43); PdfPCell celda44 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda44.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda44); tabla4.addCell(celda41); tabla4.addCell(celda41); tabla4.addCell(celda41); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.close(); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (FileNotFoundException ex) { // JOptionPane.showMessageDialog(null, "Error con el pdf"); // System.out.println(ex.getMessage()); cuenta++; generarPdf(idNota, "nota", cuenta); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); System.out.println(ex.getMessage()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error con el pdf"); } }
From source file:library.Report.java
public void createPdf(String filename) throws DocumentException, IOException { // step 1// www. j ava2 s .co m Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); document.addAuthor("Admin"); document.addTitle("Library report"); document.setPageSize(PageSize.A4); document.setMargins(36, 72, 108, 180); document.setMarginMirroring(true); document.open(); Font normal = new Font(Font.FontFamily.HELVETICA, 36f, Font.NORMAL, BaseColor.DARK_GRAY); Font normal1 = new Font(Font.FontFamily.HELVETICA, 18f, Font.NORMAL); Font normal2 = new Font(Font.FontFamily.HELVETICA, 12f, Font.NORMAL); document.add(new Paragraph("KNOWLEDGICA LIBRARY REPORT", normal)); document.add(new Phrase("\n")); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()); document.add(new Paragraph(timeStamp, normal1)); document.add(new Paragraph("Amount of books " + DF.getText() + "\nAmount of Amount of checked in books " + jTextField1.getText() + "\nAmount of checked out books " + jTextField3.getText() + "" + "\nNunber of users " + jTextField4.getText() + "\nNumber of admins " + jTextField5.getText() + "\nNumber of librarians " + jTextField6.getText() + "\nNumber of guest " + jTextField7.getText() + "\nMost logged user " + jTextField8.getText() + "\nAmount of males " + jTextField9.getText() + "\nAmount of female " + jTextField10.getText() + "", normal2)); document.close(); }
From source file:net.algem.enrolment.TrainingService.java
License:Open Source License
void preview(Properties props, String fileName, short templateKey, int idper) throws DocumentException, IOException { InputStream tpl = getClass().getResourceAsStream("/resources/doc/tpl/" + fileName + ".html"); String defPath = "/resources/doc/tpl/def/" + fileName + ".html"; if (tpl == null) { tpl = getClass().getResourceAsStream(defPath); }//from w w w . j a v a2s. com if (tpl == null) { MessagePopup.warning(null, MessageUtil.getMessage("html.template.not.found.warning", fileName + ".html")); return; } String content = FileUtil.scanContent(tpl, props); //tpl = new ByteArrayInputStream(content.getBytes()); tpl = new ByteArrayInputStream(content.getBytes("UTF-8")); ByteArrayOutputStream out = new ByteArrayOutputStream(); //step 1 Document doc = new Document(PageSize.A4); doc.setMargins(40, 40, 40, 40); //step 2 /*OutputStream printStream = new PrintStream(out, true, "UTF-8"); PdfWriter writer = PdfWirter.getInstance(doc, printStream);*/ PdfWriter writer = PdfWriter.getInstance(doc, out); //writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE); //writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.FIT); //writer.addViewerPreference(PdfName.DUPLEX, PdfName.DUPLEXFLIPLONGEDGE); doc.open(); // step 4 PdfHandler handler = new PdfHandler(templateIO); // IMPORTANT !! : set Charset here handler.createParser(doc, writer).parse(tpl, Charset.forName("UTF-8")); // step 5 doc.close(); handler.createPdf(fileName + "-" + idper + "_", out, templateKey); }