List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:GUI_StafKlinik.Panel_Penggajian.java
private Paragraph getPreface(String status) { lk = new Laporan_Keuangan(); Paragraph preface = new Paragraph(); Calendar cal = new GregorianCalendar(); String tanggal = "0"; if (cal.get(Calendar.DATE) < 0) { tanggal = "0" + cal.get(Calendar.DATE); } else {/* w w w. j a va 2 s . co m*/ tanggal = "" + cal.get(Calendar.DATE); } int bulan = (cal.get(Calendar.MONTH)) + 1; ; int tahun = cal.get(Calendar.YEAR); String id1 = lk.getId(); String id2 = p.getIdPegawai(); String id = id = id1 + id2; preface.setAlignment(Element.ALIGN_CENTER); Chunk chunk = new Chunk("Slip Gaji", font2); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("SI Klinik", font2); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("Jalan Pahlawan 45 Surabaya", font1); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("Telepon : 031 7564231", font1); preface.add(Chunk.NEWLINE); preface.add(chunk); preface.add(Chunk.NEWLINE); preface.add(Chunk.NEWLINE); preface.setAlignment(Element.ALIGN_RIGHT); chunk = new Chunk("Tanggal " + tanggal + "/" + bulan + "/" + tahun, font1); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("No. Referensi :" + id, font1); preface.add(Chunk.NEWLINE); preface.add(chunk); return preface; }
From source file:hci_project.management.java
public static void Make3Array(int Questionnumper, int Modelnumper, int Examtype, String Examname, String SubjName, String filename, ExamInfo examinfo, String loca) { try {/*from w w w . j ava 2 s . co m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("data//Data.xml"); String[] arr; int r = 0, wq = 0; String[] arr1; ArrayList<Question> easy = new ArrayList(); ArrayList<Question> medium = new ArrayList(); ArrayList<Question> hard = new ArrayList(); Question v; NodeList listS = doc.getElementsByTagName("Subject"); Element dsl = null; for (int y = 0; y < listS.getLength(); y++) { dsl = (Element) listS.item(y); if (dsl.getAttribute("ID").equals(SubjName)) { break; } } NodeList list = dsl.getElementsByTagName("Question"); for (int i = 0; i < list.getLength(); i++) { v = new Question(); r = 0; wq = 0; arr = new String[5]; arr1 = new String[5]; Element Q = (Element) list.item(i); v.setSubjctID(Q.getParentNode().getAttributes().getNamedItem("ID").getNodeValue()); v.setId(Integer.parseInt(Q.getAttribute("id"))); v.setQlevel(Integer.parseInt(Q.getAttribute("lvl"))); v.setQbody(Q.getElementsByTagName("Qbody").item(0).getTextContent()); NodeList listanswer = Q.getElementsByTagName("Answer"); for (int an = 0; an < listanswer.getLength(); an++) { Element answe = (Element) listanswer.item(an); if (answe.getAttribute("check").equals("1")) { arr[r] = answe.getTextContent(); r++; } arr1[wq] = answe.getTextContent(); wq++; } v.setAnswers(arr); v.setMSQ(arr1); switch (Q.getAttribute("lvl")) { case "1": easy.add(v); break; case "2": medium.add(v); break; default: hard.add(v); break; } } int numeasy, nummediam, numhard; if (Examtype == 1) { numeasy = Questionnumper / 2; nummediam = Questionnumper / 3; numhard = Questionnumper - (numeasy + nummediam); } else if (Examtype == 2) { numeasy = Questionnumper / 3; nummediam = Questionnumper / 2; numhard = Questionnumper - (numeasy + nummediam); } else { numhard = Questionnumper / 2; nummediam = Questionnumper / 3; numeasy = Questionnumper - (numhard + nummediam); } int[] En = Randome(numeasy, easy.size()); int[] Mn = Randome(nummediam, medium.size()); int[] Hn = Randome(numhard, hard.size()); ArrayList<Question> Exam = new ArrayList<>(); for (int i : En) /*easy Question*/ { Exam.add((Question) easy.get(i - 1)); } for (int i : Mn) /*easy Question*/ { Exam.add((Question) medium.get(i - 1)); } for (int i : Hn) /*easy Question*/ { Exam.add((Question) hard.get(i - 1)); } int num = 0, modleid = 0; Document ansxml = builder.newDocument(); Element Answer = ansxml.createElement("Answer"); Answer.setAttribute("num", Integer.toString(num)); Answer.setAttribute("NumberOfQuestions", Integer.toString(Questionnumper)); ansxml.appendChild(Answer); int mod = 65; Document StudentAnsdoc = builder.newDocument(); Element Examstudent = StudentAnsdoc.createElement("Examstudent"); String StudenFile = "data/" + filename + "_StudentAnswer.xml"; Examstudent.setAttribute("FileOfCorect", StudenFile); Examstudent.setAttribute("QuestionNumper", Integer.toString(Questionnumper)); StudentAnsdoc.appendChild(Examstudent); Document path = builder.parse("data/paths.xml"); NodeList sub = path.getElementsByTagName("subject"); Element subj = null; for (int k = 0; k < sub.getLength(); k++) { subj = (Element) sub.item(k); if (subj.getAttribute("ID").equalsIgnoreCase(SubjName)) { Attr attr = subj.getAttributeNode("num"); attr.setValue(Integer.toString(Integer.parseInt(subj.getAttribute("num")) + 1)); break; } } Element ee = path.createElement("Exam"); ee.setAttribute("Examname", filename); ee.setAttribute("ExamData", examinfo.getDate()); ee.setAttribute("ExamTime", examinfo.getTime()); ee.setAttribute("ExamLvl", examinfo.getExamlvl()); ee.setAttribute("ExamPlace", examinfo.getExamPlace()); ee.setAttribute("ExamModels", examinfo.getExammodel()); ee.setAttribute("ExamStudentGrade", "data/" + examinfo.getExammodel() + "_StudentAnswer.xml"); ee.setAttribute("QuestionNum", Integer.toString(Questionnumper)); ee.setAttribute("Correct", ("data/" + filename + "Answer.xml")); subj.appendChild(ee); File tt = new File("latex"); File templet = new File("latex/form.tex"); File fil;//= new File(Examname); JLRConverter convert = new JLRConverter(tt); JLRGenerator generator = new JLRGenerator(); ArrayList<ArrayList<String>> exam; ArrayList<String> subexam; for (int f = 0; f < Modelnumper; f++) { int[] ExamN = Randome(Exam.size(), Exam.size()); ArrayList<Question> newExam = new ArrayList<>(); Element e = StudentAnsdoc.createElement("model"); e.setAttribute("ID", Character.toString((char) mod)); e.setAttribute("num", "0"); Examstudent.appendChild(e); for (int b : ExamN) { newExam.add(Exam.get(b - 1)); } Element ea = path.createElement("model"); ea.setAttribute("id", Character.toString((char) mod)); ee.appendChild(ea); //com.itextpdf.text.Document pdf = new com.itextpdf.text.Document(); com.itextpdf.text.Document pdfAns = new com.itextpdf.text.Document(); String model = Examname; String modelAns = Examname + "Answer.pdf"; FileOutputStream filepdf; FileOutputStream filepdfAns; File file; int i = 1; String removing = filename; while (true) { file = new File(modelAns); if (!file.exists()) { // filepdf = new FileOutputStream(model); filepdfAns = new FileOutputStream(modelAns); break; } else { removing = filename + "(" + i + ")"; model = Examname + "(" + i + ")"; modelAns = Examname + "Answer(" + i + ").pdf"; i++; } } String ou = "latex/" + removing + ".tex"; File output = new File(ou); //com.itextpdf.text.pdf.PdfWriter.getInstance(pdf,filepdf); com.itextpdf.text.pdf.PdfWriter.getInstance(pdfAns, filepdfAns); //pdf.open(); pdfAns.open(); //com.itextpdf.text.Paragraph prag ; com.itextpdf.text.Paragraph pragAns; convert.replace("model", (char) mod); convert.replace("subject", examinfo.getExamname()); convert.replace("date", examinfo.getDate()); convert.replace("time", examinfo.getTime()); convert.replace("place", examinfo.getExamPlace()); Paragraph prag = new Paragraph(); /* prag.add("____________________________"+"Exam Model : ("+(char)mod+")"+"____________________________________\n"+ " Exam Date : "+examinfo.getDate()+" "+"Exam Time : "+examinfo.getTime()+"\n"+ " Subject : "+examinfo.getExamname()+" "+"Place : "+examinfo.getExamPlace()+"\n"+ " Student Name : "+" "+"Student ID : "+"\n"); prag.add("______________________________________________________________________________\n"); pdf.add(prag);*/ prag = new Paragraph(); prag.add("____________________________" + "Answer Model : (" + (char) mod + ")" + "_________________________________\n" + " Exam Date : " + examinfo.getDate() + " " + "Exam Time : " + examinfo.getTime() + "\n" + " Subject : " + examinfo.getExamname() + " " + "Place : " + examinfo.getExamPlace() + "\n"); prag.add("______________________________________________________________________________\n"); pdfAns.add(prag); mod++; int k = 1; num++; Attr attr = Answer.getAttributeNode("num"); attr.setValue(Integer.toString(num)); Element Model = ansxml.createElement("model"); modleid++; Model.setAttribute("id", Integer.toString(modleid)); Answer.appendChild(Model); exam = new ArrayList<>(); for (Question x : newExam) { /* prag = new Paragraph(); prag.add(k +") "+x.getQbody()+"\n"+"a. "+x.getMSQ()[0]+" b. "+x.getMSQ()[1]+" c. "+x.getMSQ()[2]+" d. "+x.getMSQ()[3]+" e. "+x.getMSQ()[4]+"\n\n"); pdf.add(prag);*/ Element eea = path.createElement("Question"); eea.setAttribute("lvl", Integer.toString(x.getQlevel())); eea.setAttribute("id", Integer.toString(x.getId())); ea.appendChild(eea); /*Start Question body Tag*/ Element Qbody = path.createElement("Qbody"); Qbody.setTextContent(x.getQbody()); eea.appendChild(Qbody); /*End Question Tag*/ subexam = new ArrayList<>(); subexam.add(x.getQbody()); /*Loop to set Answers Tag*/ for (int j = 0; j < 5; j++) { Element answer = path.createElement("Answer"); answer.setTextContent(x.getMSQ()[j]); /*to check if Answer is Wright or not */ subexam.add(x.getMSQ()[j]); if (x.getMSQ()[j].equals(x.getAnswers()[0]) || x.getMSQ()[j].equals(x.getAnswers()[1]) || x.getMSQ()[j].equals(x.getAnswers()[2])) { answer.setAttribute("check", "1"); } else { answer.setAttribute("check", "0"); /*fuke u*/ } answer.setAttribute("class", Integer.toString(j + 1)); eea.appendChild(answer); } /*End Answers loop*/ pragAns = new Paragraph(); String a1 = x.getAnswers()[0], a2 = x.getAnswers()[1], a3 = x.getAnswers()[2]; if (a2 == null) { a2 = " "; } if (a3 == null) { a3 = " "; } pragAns.add(k + ") a." + a1 + " b." + a2 + " c." + a3 + "\n\n"); pdfAns.add(pragAns); k++; Element Quest = ansxml.createElement("Question"); Quest.setAttribute("Qid", Integer.toString(x.getId())); Quest.setAttribute("Sid", x.getSubjctID()); Model.appendChild(Quest); for (int t = 0; t < 3; t++) { Element Ans = ansxml.createElement("Ans"); Ans.setTextContent(x.getAnswers()[t]); Quest.appendChild(Ans); } exam.add(subexam); } // pdf.close(); convert.replace("question", exam); pdfAns.close(); convert.parse(templet, output); generator.generate(output, tt, tt); fil = new File("latex/" + removing + ".pdf"); fil.renameTo(new File(loca + "/" + removing + ".pdf")); fil = new File("latex/" + removing + ".aux"); fil.delete(); fil = new File("latex/" + removing + ".log"); fil.delete(); fil = new File("latex/" + removing + ".tex"); fil.delete(); } fil = new File("latex/home"); delete(fil); TransformerFactory transform = TransformerFactory.newInstance(); Transformer trans = transform.newTransformer(); trans.transform(new DOMSource(ansxml), new StreamResult("data/" + filename + "Answer" + ".xml")); trans.transform(new DOMSource(doc), new StreamResult("data//Data.xml")); trans.transform(new DOMSource(StudentAnsdoc), new StreamResult(StudenFile)); trans.transform(new DOMSource(path), new StreamResult("data/paths.xml")); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:IAS.Class.BackIssueLabels.java
public Paragraph prepareBILLabelPDFContent(subInfo sLabelInfo, String bilLabel) { Paragraph info = null; info = new Paragraph(); info.setLeading(lfixedLeading, lmultipliedLeadingPlus); info.setAlignment(textAlignment);//from w w w .j av a2 s . c om Font font; font = new Font(sfontType, sfontSizeHeader - 1, sfontStyle, BaseColor.BLACK); if (!bilLabel.isEmpty() && !sLabelInfo.getsubscriberNumber().isEmpty()) { String header = sLabelInfo.getsubscriberNumber() + " " + bilLabel; info.add(new Chunk(header, font)); info.add(Chunk.NEWLINE); } font = new Font(sfontType, sfontSize, sfontStyle, BaseColor.BLACK); String firstLine = sLabelInfo.getsubscriberName(); // + " " + sLabelInfo.getjournalCode(); //if(!noHeader){ //if(sLabelInfo.getcopies() > 1){ // firstLine = firstLine + " " + sLabelInfo.getcopies(); //} //firstLine = firstLine + " " + sLabelInfo.getsubtypecode(); //if(sLabelInfo.equals("Paid")) { // firstLine = firstLine + " " + sLabelInfo.getstartDate()+ // " " + "to" + // " " + sLabelInfo.getendDate(); //} if (!firstLine.isEmpty()) { info.add(new Chunk(firstLine, font)); info.add(Chunk.NEWLINE); } //} //info.add(new Chunk(sLabelInfo.getsubscriberName(), font)); //info.add(Chunk.NEWLINE); if (!sLabelInfo.getdepartment().isEmpty()) { info.add(new Chunk(sLabelInfo.getdepartment(), font)); info.add(Chunk.NEWLINE); } if (!sLabelInfo.getinstitution().isEmpty()) { info.add(new Chunk(sLabelInfo.getinstitution(), font)); info.add(Chunk.NEWLINE); } if (!sLabelInfo.getaddress().isEmpty()) { info.add(new Chunk(sLabelInfo.getaddress(), font)); info.add(Chunk.NEWLINE); } font = new Font(sfontType, sfontSize, Font.BOLD); /* String lastLine = sLabelInfo.getcity() + " " + sLabelInfo.getpincode() + " " + sLabelInfo.getstate() + " "; if(!sLabelInfo.getcountry().equals("India")){ lastLine = lastLine + sLabelInfo.getcountry(); } */ String lastLine = ""; if (!sLabelInfo.getcity().isEmpty()) { lastLine = lastLine + sLabelInfo.getcity(); } if (sLabelInfo.getcity().isEmpty()) { lastLine = lastLine + sLabelInfo.getpincode(); } else { lastLine = lastLine + " " + sLabelInfo.getpincode(); } if (sLabelInfo.getpincode().isEmpty()) { lastLine = lastLine + sLabelInfo.getstate(); } else { lastLine = lastLine + " " + sLabelInfo.getstate(); } String country = ""; if (!sLabelInfo.getcountry().equals("India")) { country = sLabelInfo.getcountry(); } if (sLabelInfo.getstate().isEmpty()) { lastLine = lastLine + country; } else { lastLine = lastLine + " " + country; } if (!lastLine.isEmpty()) { lastLine = lastLine.trim(); // Remove the leading spaces //lastLine.replaceAll("^\\s+", ""); info.add(new Chunk(lastLine, font)); } return info; }
From source file:ics4u.ics4u_final_project.Recipe.java
License:Open Source License
private void addData(Document doc) { //create the format for the % Daily Value DecimalFormat onePer = new DecimalFormat("#,##0%"); try {/*from w w w. jav a 2s. c om*/ //add the title of the recipe doc.add(new Paragraph(title, TITLE_FONT)); //add each of the ingredients for (int i = 0; i < ingredients.size(); i++) { doc.add(new Paragraph(ingredients.get(i).getFormattedName(), LABEL_NORMAL)); } //add the instructions Paragraph p = new Paragraph(); if (!instructions.equals("")) { p = new Paragraph(new Phrase("Instructions:\n", LABEL_FONT)); doc.add(p); p = new Paragraph(); p.add(new Phrase(instructions + "\n", LABEL_NORMAL)); } else { p.add(new Phrase("\n")); } //create the nutrient value table PdfPTable label = new PdfPTable(10); label.setWidthPercentage(30); //Top PdfPCell c = new PdfPCell(new Phrase("Nutrition Facts", LABEL_FONT)); c.setColspan(10); c.setBorderWidthBottom(0); label.addCell(c); c = new PdfPCell(new Phrase("Per " + servingName, LABEL_BOLD)); c.setColspan(10); c.setBorderWidthTop(0); label.addCell(c); //Amount PdfPCell c2a = new PdfPCell(new Phrase("Amount", LABEL_SMALL)); c2a.setColspan(3); c2a.setBorderWidthRight(0); PdfPCell c2b = new PdfPCell(new Phrase("% Daily Value", LABEL_SMALL)); c2b.setColspan(10); c2b.setHorizontalAlignment(Element.ALIGN_RIGHT); c2b.setBorderWidthLeft(0); label.addCell(c2a); label.addCell(c2b); //Calories c = new PdfPCell(new Phrase("Calories " + (int) (nutrients[208] / servings), LABEL_BOLD)); c.setColspan(10); c.setBorderWidthTop(2); label.addCell(c); //Fat PdfPCell ca = new PdfPCell(new Phrase("Fat " + (int) (nutrients[204] / servings) + "g", LABEL_BOLD)); ca.setColspan(6); ca.setBorderWidthRight(0); PdfPCell cb = new PdfPCell(new Phrase(onePer.format((nutrients[204] / servings) / 60.0), LABEL_BOLD)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //fat 2 ca = new PdfPCell(new Phrase("Saturated " + ((int) (nutrients[606] / servings)) + "g\n\t+ Trans " + ((int) (nutrients[605] / servings)) + "g", LABEL_NORMAL)); ca.setColspan(6); ca.setIndent(16); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[606] / servings) / 20.0), LABEL_BOLD)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Cholesterol c = new PdfPCell(new Phrase("Cholesterol " + ((int) (nutrients[601] / servings)) + "mg", LABEL_BOLD)); c.setColspan(10); label.addCell(c); //Sodium ca = new PdfPCell(new Phrase("Sodium " + (int) (nutrients[307] / servings) + "mg", LABEL_BOLD)); ca.setColspan(6); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[307] / servings) / 2400.0), LABEL_BOLD)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Carbs ca = new PdfPCell(new Phrase("Carbohydrate " + (int) (nutrients[205] / servings) + "g", LABEL_BOLD)); ca.setColspan(7); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[205] / servings) / 300.0), LABEL_BOLD)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Fibre ca = new PdfPCell(new Phrase("Fibre " + (int) (nutrients[291] / servings) + "g", LABEL_NORMAL)); ca.setColspan(6); ca.setIndent(16); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[291] / servings) / 25.0), LABEL_BOLD)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Sugar ca = new PdfPCell(new Phrase("Sugars " + (int) (nutrients[269] / servings) + "g", LABEL_NORMAL)); ca.setColspan(10); ca.setIndent(16); label.addCell(ca); //Protein ca = new PdfPCell(new Phrase("Protein " + (int) (nutrients[203] / servings) + "g", LABEL_BOLD)); ca.setColspan(10); label.addCell(ca); //Vit A ca = new PdfPCell(new Phrase("Vitamin A", LABEL_NORMAL)); ca.setColspan(6); ca.setBorderWidthRight(0); ca.setBorderWidthTop(2); cb = new PdfPCell(cb = new PdfPCell(new Phrase( onePer.format( ((nutrients[319] + (nutrients[321] / 12) + (nutrients[834] / 24)) / servings) / 1000), LABEL_NORMAL))); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); cb.setBorderWidthTop(2); label.addCell(ca); label.addCell(cb); //Vit C ca = new PdfPCell(new Phrase("Vitamin C", LABEL_NORMAL)); ca.setColspan(6); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[401] / servings) / 60.0), LABEL_NORMAL)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Calcium ca = new PdfPCell(new Phrase("Calcium", LABEL_NORMAL)); ca.setColspan(6); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[301] / servings) / 1100.0), LABEL_NORMAL)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Iron ca = new PdfPCell(new Phrase("Iron", LABEL_NORMAL)); ca.setColspan(6); ca.setBorderWidthRight(0); cb = new PdfPCell(new Phrase(onePer.format((nutrients[303] / servings) / 14.0), LABEL_NORMAL)); cb.setColspan(10); cb.setHorizontalAlignment(Element.ALIGN_RIGHT); cb.setBorderWidthLeft(0); label.addCell(ca); label.addCell(cb); //Add to the table label.setHorizontalAlignment(Element.ALIGN_LEFT); p.add(label); //add to the document doc.add(p); } catch (DocumentException ex) { System.out.println("Error: " + ex.toString()); } }
From source file:ictproject.ReportGenerator.java
private Paragraph getParagraph(String name, String type) { Paragraph paragraph = new Paragraph(); paragraph.setSpacingAfter(10);/*from ww w . j ava 2 s .com*/ switch (type) { case "pani ko sroth": { Paragraph para1 = new Paragraph("@= ljBfdfg kfgLsf >f]tx?sf] cj:yfM", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); paragraph.add(para1); break; } case "pani janya rog ko bibaran": { Paragraph para1 = new Paragraph("%= kfgLhGo /f]ux?sf] ljj/0f M", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para3 = new Paragraph( "uflj;:t/Lo kfgLhGo /f]ux?sf] ljj/0f :jf:Yo rf}sLaf6 jf dlxnf ;jo+;]ljsf af6 lng]", fontNormal); paragraph.add(para1); break; } case "actual budget": { Paragraph para1 = new Paragraph( "# -s_ ut tLg jif{sf nflu uflj;n] vfg]kfgL tyf ;/;kmfO If]qdf 5'6fPsf] jh]6 ljj/0fM", fontNormal); // Paragraph para3=new Paragraph("uflj;sf] hDdf ;Defljt nufgL ? ",fontNormal); // Paragraph para4=new Paragraph(getDistinctResult(name, "gabisaKoLagani", "actualBudget")); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para5 = new Paragraph(); para5.add(new Chunk("uflj;sf] hDdf ;Defljt nufgL ? ", fontNormal)); para5.add(getDistinctResult(name, "gabisaKoLagani", "actualBudget")); paragraph.add(para1); paragraph.add(para5); break; } case "expected budget": { Paragraph para1 = new Paragraph( "# -v_ cfufdL # jif{sf nflu uflj;sf] vfg]kfgL tyf ;/;kmfO If]qdf x'g ;Sg] ;Defljt ah]6M", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para5 = new Paragraph(); para5.add(new Chunk("uflj;sf] hDdf ;Defljt nufgL ? ", fontNormal)); para5.add(getDistinctResult(name, "gabisaKoLagani", "expectedBudget")); paragraph.add(para1); paragraph.add(para5); break; } case "janajatiAnusar": { Paragraph para2 = new Paragraph("uflj;sf] gfdMM" + converter(name), fontNormal); para2.setIndentationLeft(50); Paragraph para1 = new Paragraph("!= hfthftL cg';f/sf] 3/w'/L ljj/0fM", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); paragraph.add(para2); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); paragraph.add(para1); break; } case "sauchalayKoAwasta": { Paragraph para1 = new Paragraph("$= zf}rfnosf] cj:yf M", fontNormal);//. ? ",fontNormal); para1.setAlignment(Element.ALIGN_CENTER); paragraph.add(para1); break; } case "gulmi": { Paragraph para = new Paragraph(); Paragraph para1 = new Paragraph("lhNnf ljsf; ;ldltsf] sfof{no", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para3 = new Paragraph("u'NdL", fontNormal); para3.setAlignment(Element.ALIGN_CENTER); Paragraph para4 = new Paragraph("vfg]kfgL tyf ;/;kmfO OsfO{", fontNormal); para4.setAlignment(Element.ALIGN_CENTER); para.add(para1); para.add(para3); para.add(para4); return para; } case "name": { Paragraph para = new Paragraph(converter(name), fontNormal); para.setAlignment(Element.ALIGN_CENTER); return para; } } return paragraph; }
From source file:ihm.panneaux.GenererPdf.java
private void initComponement() throws FileNotFoundException, DocumentException, IOException { String DEST = "devis/devis-" + devis.getNumero() + ".pdf"; OutputStream file = new FileOutputStream(new File(DEST)); com.itextpdf.text.Document document = new com.itextpdf.text.Document(); PdfWriter.getInstance((com.itextpdf.text.Document) document, file); // PAS TOUCHE PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST)); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent(); writer.setPageEvent(event);/*from w w w . j a v a2 s . c o m*/ document.open(); PdfContentByte canvas = writer.getDirectContent(); Image logo = Image.getInstance("images/logo.png"); logo.scaleAbsolute(200, 57); // INFO DEVIS Image devisImg = Image.getInstance("images/imgDevis.png"); devisImg.scaleAbsolute(110, 34); devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150), (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2); Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Phrase numeroInfo = new Phrase("Numro " + devis.getNumero(), fontImgDevis); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413, devisImg.getScaledHeight() + 710, 0); Phrase dateInfo = new Phrase("Le " + devis.getDate(), fontImgDevis); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420, devisImg.getScaledHeight() + 695, 0); Image devisImgBordure = Image.getInstance("images/bordureDevis.png"); devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660); devisImgBordure.scaleAbsolute(120, 122); // INFO ENTREPRISE Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD); Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210, devisImg.getScaledHeight() + 660, 0); Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149, devisImg.getScaledHeight() + 640, 0); Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113, devisImg.getScaledHeight() + 625, 0); Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png"); bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610); // INFO CLIENT Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL); Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient); Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient); Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(), fontClient); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 595, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 580, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 565, 0); document.add(logo); document.add(devisImg); document.add(devisImgBordure); document.add(bordureEntreprise); // AJOUT DES DONNEES DU TABLEAUX float[] columnWidths = { 14, 3, 4, 3, 4 }; Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); fontCategorie.setColor(BaseColor.GREEN); PdfPTable table = new PdfPTable(columnWidths); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.setTotalWidth(PageSize.A4.getWidth() - 15); table.setSpacingBefore(150); table.setLockedWidth(true); Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD); Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE); PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier)); cellChantier.setColspan(3); cellChantier.setBorder(Rectangle.NO_BORDER); table.addCell(cellChantier); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(new Phrase("Dsignation", Categorie)); PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie)); PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie)); PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie)); PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie)); unite.setHorizontalAlignment(Element.ALIGN_CENTER); quantite.setHorizontalAlignment(Element.ALIGN_CENTER); prixht.setHorizontalAlignment(Element.ALIGN_CENTER); pvtht.setHorizontalAlignment(Element.ALIGN_CENTER); unite.setBorder(Rectangle.NO_BORDER); quantite.setBorder(Rectangle.NO_BORDER); prixht.setBorder(Rectangle.NO_BORDER); pvtht.setBorder(Rectangle.NO_BORDER); table.addCell(unite); table.addCell(quantite); table.addCell(prixht); table.addCell(pvtht); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); double htTotalParcour = 0; double ttcTotalParcour = 0; if (this.EquipementDeChantier.isEmpty() == false) { table.addCell(new Phrase("Equipement De Chantier", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : EquipementDeChantier) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); /* BACKUP table.addCell(listeMaterielDevi.getMateriel().getNom()); table.addCell(listeMaterielDevi.getMateriel().getUnite()); table.addCell(Double.toString(listeMaterielDevi.getQuantite())); table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+""); table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+""); */ ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (Couverture.isEmpty() == false) { table.addCell(new Phrase("Couverture", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Couverture) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (CouvertureArdoise.isEmpty() == false) { table.addCell(new Phrase("Couverture Ardoise", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : CouvertureArdoise) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (CouvertureTuile.isEmpty() == false) { table.addCell(new Phrase("Couverture Tuile", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : CouvertureTuile) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Demoussage.isEmpty() == false) { table.addCell(new Phrase("Demoussage", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Demoussage) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Velux.isEmpty() == false) { table.addCell(new Phrase("Velux", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Velux) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Zinguerie.isEmpty() == false) { table.addCell(new Phrase("Zinguerie", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Zinguerie) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (Plancher.isEmpty() == false) { table.addCell(new Phrase("Plancher", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Plancher) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour; LineDash solid = new SolidLine(); PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc; table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); cell = new PdfPCell(new Phrase("")); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new CustomBorder(null, null, null, solid)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.addCell(new Phrase("")); table.addCell(new Phrase("")); cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL")); cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE); cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER); table.addCell(cellSOUSTOTAL); table.addCell(new Phrase("")); double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2); String httotal = String.valueOf(prixHT_2Chiffre); cellhttotal = new PdfPCell(new Phrase(httotal + "")); cellhttotal.setBorder(Rectangle.NO_BORDER); cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(cellhttotal); table.addCell(new Phrase("")); table.addCell(new Phrase("")); tva = new PdfPCell(new Phrase("TVA")); tva.setBorder(Rectangle.NO_BORDER); tva.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(tva); getTva = new PdfPCell(new Phrase(devis.getTva() + "%")); getTva.setBorder(Rectangle.NO_BORDER); getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(getTva); String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100); double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2); cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + "")); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setCellEvent(new CustomBorder(null, null, null, solid)); cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); table.addCell(""); table.addCell(""); totalttc = new PdfPCell(new Phrase("Total TTC")); totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE); totalttc.setBorder(PdfPCell.NO_BORDER); table.addCell(totalttc); table.addCell(""); double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2); String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre)); gettotalttc = new PdfPCell(new Phrase(ttctotal + "")); gettotalttc.setBorder(PdfPCell.NO_BORDER); gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(gettotalttc); table.setSpacingAfter(10); document.add(table); Pattern p = Pattern.compile("[.^\\.]+"); String texte = devis.getInformationComplementaire(); Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptBlue.setColor(BaseColor.BLUE); Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptRed.setColor(BaseColor.RED); Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptBlack.setColor(BaseColor.BLACK); Paragraph infoComp = new Paragraph(); Image BonPourAccord = null; BonPourAccord = Image.getInstance("images/BonPourAccord.png"); infoComp.setAlignment(Element.ALIGN_LEFT); BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT); String[] phrase = p.split(texte); for (int i = 0; i < phrase.length; i++) { if (i == 0 || i == 1) { infoComp.add(new Paragraph(phrase[i], infoComptBlue)); } if (i == 2 || i == 3 || i == 4 || i == 5) { infoComp.add(new Paragraph(phrase[i], infoComptRed)); } if (i > 5 && i <= 11) infoComp.add(new Paragraph(phrase[i], infoComptBlack)); if (i > 11) infoComp.add(new Paragraph(phrase[i], infoComptRed)); } /* A OPTIMISER */ float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex()); if (taille_tableau > 386) { document.newPage(); } document.add(BonPourAccord); document.add(infoComp); document.close(); EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis); this.CouvertureArdoise.clear(); this.CouvertureTuile.clear(); this.Demoussage.clear(); this.EquipementDeChantier.clear(); this.Velux.clear(); this.Zinguerie.clear(); this.Couverture.clear(); this.Plancher.clear(); }
From source file:info.toegepaste.www.service.ProjectServiceImpl.java
public void createPDFje(List<Score> scores) { try {/*from w w w.jav a 2 s . co m*/ Document document = new Document(); // Tijdelijk bestand aanmaken (PDF) File temp = File.createTempFile("resultaat", ".pdf"); //PDF openen en bewerken PdfWriter.getInstance(document, new FileOutputStream(temp.getAbsolutePath())); document.open(); // MetaData toevoegen document.addTitle("Resulaten"); document.addAuthor("Score Tracker"); document.addCreator("Score Tracker"); // Titel toevoegen Paragraph preface = new Paragraph(); preface.add(new Paragraph("Resultaten van de gekozen scores")); addEmptyLine(preface, 2); document.add(preface); // Tabel toevoegen met 5 kolommen PdfPTable table = new PdfPTable(5); PdfPCell c1 = new PdfPCell(new Phrase("Klas")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Student")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Vak")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Test")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Resultaat")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); table.setHeaderRows(1); //tabel opvullen met scores uit "List<Score> scores" for (Score score : scores) { table.addCell(score.getStudent().getKlas().getGroep()); table.addCell(score.getStudent().getNaam()); table.addCell(score.getTest().getVak().getNaam()); table.addCell(score.getTest().getNaam()); table.addCell(score.getPunt() + " / " + score.getTest().getMaxScore()); } // breedte van de kolommen float[] columnWidths = new float[] { 10f, 25f, 20f, 20f, 15f }; table.setWidths(columnWidths); document.add(table); document.close(); // PDF downloaden exportPdf(temp); } catch (Exception e) { e.printStackTrace(); } }
From source file:info.toegepaste.www.service.ProjectServiceImpl.java
public void createPDF(List<Score> scores) { try {//w w w . j a v a 2s . c o m Document document = new Document(); // Tijdelijk bestand aanmaken (PDF) File temp = File.createTempFile("resultaat", ".pdf"); //PDF openen en bewerken PdfWriter.getInstance(document, new FileOutputStream(temp.getAbsolutePath())); document.open(); // MetaData toevoegen document.addTitle("Resulaten"); document.addAuthor("Score Tracker"); document.addCreator("Score Tracker"); // Titel toevoegen Paragraph preface = new Paragraph(); preface.add(new Paragraph("Resultaten van de gekozen scores")); addEmptyLine(preface, 2); document.add(preface); // Tabel toevoegen PdfPTable table = new PdfPTable(4); PdfPCell c1 = new PdfPCell(new Phrase("Student")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Vak")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Test")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); c1 = new PdfPCell(new Phrase("Resultaat")); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); table.setHeaderRows(1); //tabel opvullen met scores uit "List<Score> scores" for (Score score : scores) { table.addCell(score.getStudent().getNaam()); table.addCell(score.getTest().getVak().getNaam()); table.addCell(score.getTest().getNaam()); table.addCell(score.getPunt() + " / " + score.getTest().getMaxScore()); } // breedte van de kolommen float[] columnWidths = new float[] { 10f, 25f, 20f, 20f, 15f }; table.setWidths(columnWidths); document.add(table); document.close(); // PDF downloaden exportPdf(temp); } catch (Exception e) { e.printStackTrace(); } }
From source file:kafe.BayarSemuaFrame.java
private static void addContent(Document document, String id_pesanan, String bayar, String kembali) throws DocumentException { Paragraph preface = new Paragraph(); preface.add(new Paragraph("============================================================================\n", smallBold));// www. ja va 2 s .c om addEmptyLine(preface, 1); preface.setTabSettings(new TabSettings(250f)); preface.add(Chunk.TABBING); preface.add(new Chunk("---------SEDAP MALAM---------", catFont)); addEmptyLine(preface, 1); preface.setTabSettings(new TabSettings(150f)); preface.add(Chunk.TABBING); preface.add(new Chunk("__________Jalan Informatika No.8__________", smallBold)); addEmptyLine(preface, 1); preface.add(new Paragraph("============================================================================\n", smallBold)); addEmptyLine(preface, 1); try { Class.forName(driver); Connection connection = DriverManager.getConnection(url, user, pass); Statement statement = connection.createStatement(); String sql = "select a.id_pesanan,d.nama_meja,b.waktu,c.nama_makanan,c.harga_makanan,a.jumlah_makanan,a.status from isi_pesanan a, pesanan b, makanan c, meja d where b.id_pesanan='" + id_pesanan + "' and a.id_pesanan=b.id_pesanan and a.id_makanan=c.id_makanan and b.meja=d.id_meja"; ResultSet rs = statement.executeQuery(sql); int i = 0; int harga_tot = 0; while (rs.next()) { int id = rs.getInt(1); String nama_meja = rs.getString(2); String firstName = rs.getString(3); String surname = rs.getString(4); if (i == 0) { preface.add(new Chunk("ID Pesanan: " + rs.getInt(1) + "\n", normalFont)); preface.add(new Chunk("Meja: " + rs.getString(2) + "\n", normalFont)); preface.add(new Chunk("Waktu Pesanan: " + rs.getString(3), normalFont)); addEmptyLine(preface, 1); preface.add(new Paragraph( "---------------------------------------------------------------------------------------------------------------------------------\n", smallBold)); addEmptyLine(preface, 1); preface.add(new Paragraph("Rincian Pesananan:", smallBold)); addEmptyLine(preface, 1); } preface.add(new Paragraph( rs.getString(4) + " @ " + rs.getString(6) + " = Rp. " + rs.getString(5) + "\n", normalFont)); harga_tot += Integer.parseInt(rs.getString(5)) * Integer.parseInt(rs.getString(6)); i++; } addEmptyLine(preface, 1); preface.add(new Paragraph( "---------------------------------------------------------------------------------------------------------------------------------\n", smallBold)); addEmptyLine(preface, 1); preface.add(new Paragraph("Harga Total: Rp. " + harga_tot, smallBold)); addEmptyLine(preface, 1); preface.add(new Paragraph("Bayar: Rp. " + bayar, normalFont)); addEmptyLine(preface, 1); preface.add(new Paragraph("Kembali: Rp. " + kembali, smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("============================== TERIMA KASIH ==============================", smallBold)); rs.close(); statement.close(); connection.close(); } catch (Exception DBException) { } document.add(preface); document.newPage(); }
From source file:klasy.PdfFiles.java
public static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line //addEmptyLine(preface, 1); // Lets write a big header preface.add(new Paragraph("Bilet nr " + b.getId(), catFont)); //addEmptyLine(preface, 3); preface.add(new Paragraph("Imie i nazwisko: " + b.getImie_pasazera() + ' ' + b.getNazwisko_pasazera(), smallBold));//ww w. ja va2s. co m preface.add(new Paragraph("Data lotu: " + b.getData_lotu(), smallBold)); preface.add(new Paragraph("Data wystawienia biletu: " + b.getData_wystawienia_biletu(), smallBold)); //preface.add(new Paragraph("Data lotu: " + b.getData_lotu(), // smallBold)); preface.add(new Paragraph("Cel podry: " + m.getNazwa(), smallBold)); preface.add(new Paragraph("Cena: " + m.getCena(), smallBold)); preface.add(new Paragraph("Model samolotu: " + s.getModel(), smallBold)); preface.add(new Paragraph("Nr lotu: " + s.getNr_samolotu(), smallBold)); addEmptyLine(preface, 30); preface.add(new Paragraph("Wygenerowano: " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); document.add(preface); }