List of usage examples for com.itextpdf.text.pdf PdfWriter close
@Override public void close()
Document
was closed and that no other Elements
will be added. From source file:Servlets.ReportsServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . j a v a 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Paragraph pp; Paragraph palaglapgh, signParagraph, dateParagrapgh; Chunk chk; Paragraph underText; Chunk chuk1; Chunk chuk2; Paragraph regionText; String x; ResultSet dir; Paragraph regionTexts; String repLot; repLot = request.getParameter("report"); String repNum = request.getParameter("ITLot"); Paragraph newDate; response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); switch (repLot) { default: break; case "IT Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(20f, 20f, 10f, 10f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .25f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "TR Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); //doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .1f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "RP Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFreplants(repNum); try { if (dir.next()) { x = dir.getString(22); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(RPreport(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "Rehab Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(5f, 5f, 3f, 3f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum, bfBold12); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!! try { if (dir.next()) { x = dir.getString(21); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); //Copied CODES break; } } catch (DocumentException ex) { Logger.getLogger(ReportsServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:staff.cashier.CashierController.java
@FXML private void onClickGetPayment(ActionEvent e) throws SQLException, IOException, ClassNotFoundException, DocumentException, DecoderException { PendingBill currBill = cashierView.getSelectionModel().getSelectedItem(); System.out.println(currBill.getCusName() + " " + currBill.getOrderID() + " " + currBill.getBill()); int orderid = currBill.getOrderID(); int bill_status = 1; Statement st = conn.createStatement(); Statement st1 = conn.createStatement(); Statement st2 = conn.createStatement(); // set bill status 1 in order_info table. String query = "update order_info set bill_paid='" + bill_status + "' where order_id='" + currBill.getOrderID() + "'"; st.executeUpdate(query);//w w w.j av a 2s. c om // set cus_id=0 in corrosponding table. String query1 = "select * from order_info where order_id='" + currBill.getOrderID() + "'"; ResultSet rs = st1.executeQuery(query1); rs.next(); BigInteger cus_id = new BigInteger(Long.toString(rs.getLong("c_id"))); BigInteger new_cid = BigInteger.ZERO; String query2 = "update table_info set c_id='" + new_cid + "',order_taken=0 where c_id='" + cus_id + "'"; st2.executeUpdate(query2); //deleting the row ObservableList<PendingBill> billSelected, allBill; allBill = cashierView.getItems(); allBill.remove((currBill)); //Inserting into `bill` schema int counter = 0; //fetching the bill_id of the last order query = "select * from bill"; rs = st.executeQuery(query); while (rs.next()) { counter = rs.getInt("bill_id"); } counter++; String query3 = "insert into bill values(" + counter + "," + currBill.bill + ")"; st.executeUpdate(query3); //Updating the bill_generation schema String query4 = "insert into bill_generation values(" + currBill.orderID + ",'" + caid + "'," + counter + ")"; st.executeUpdate(query4); //GENERATING THE BILL IN PDF FORM String query5 = "select * from order_info where order_id=" + orderid + " "; ResultSet rs1 = st.executeQuery(query5); rs1.next(); String itemList = rs1.getString("list"); int tis = rs1.getInt("table_id"); float cc = rs1.getFloat("cost"); //String itemDetails=rs1.getString("item_qty"); int coupon = rs1.getInt("coupon_id"); float disc_p = 0; //FETCHING THE DISCOUNT PERCENT CORRESPONDING TO THAT COUPON if (coupon != 0) { Statement st4 = conn.createStatement(); String q4 = "select discount_percent from coupon where coupon_id=" + coupon; ResultSet rs4 = st4.executeQuery(q4); rs4.next(); disc_p = rs4.getFloat("discount_percent"); } //FETCHING CUSTOMER NAME String query6 = "select * from customer where c_id=" + cus_id + ""; ResultSet rs2 = st.executeQuery(query6); rs2.next(); String cusname = rs2.getString("c_name"); String email = rs2.getString("c_email"); String itemsInfo = ""; /*----------------DESERIALIZATION ByteArrayInputStream in = new ByteArrayInputStream(Hex.decodeHex(itemList.toCharArray())); String[] aa= (String[]) (new ObjectInputStream(in).readObject()); //System.out.println(Arrays.toString(); try{ for (String aa1 : aa) { if(aa1!=null){ int i; String tmp=""; for( i=0;i<(aa1.length()-1);i++) { tmp+=aa1.charAt(i); } int qty=Integer.parseInt(""+aa1.charAt(i)); itemsInfo+="Item name: "+tmp+" Qty:"+qty+"\n\n"; } } } catch(Exception ee){} -----------------------------------------*/ //EXTRACTING INFORMATION ABOUT ORDERED ITEMS String tmp = ""; for (int i = 0; i < (itemList.length() - 1); i++) { if (itemList.charAt(i + 1) == '-') { int qty = Integer.parseInt("" + itemList.charAt(i)); Statement st3 = conn.createStatement(); String q3 = "Select price from menu where d_name='" + tmp + "'"; ResultSet rs3 = st3.executeQuery(q3); rs3.next(); float p = rs3.getFloat("price"); itemsInfo += "Item name:" + tmp + " Qty:" + qty + " Price:+" + p + " Total:" + (qty * p) + "\n\n"; tmp = ""; i++; } else tmp += itemList.charAt(i); } itemsInfo += "Total Cost :" + cc + "\n\n"; if (coupon != 0) { float tprice = cc - ((disc_p * cc) / 100); itemsInfo += "You have been given a discount of " + disc_p + "%\n\nFinal Cost : Rs." + tprice + "\n\n"; } System.out.println("Item info:" + itemsInfo); //WRITING TO PDF Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("Order" + orderid + ".pdf")); doc.open(); doc.addTitle("CENTRICO RESTAURANT"); doc.addCreationDate(); doc.addSubject("BILL"); //System.out.println(itemDetails); doc.add(new Paragraph(" CENTRICO RESTAURANT\n\nORDER ID : " + orderid + "\n\nTABLE ID : " + tis + "\n\nCUSTOMER NAME : " + cusname + "\n\nEMAIL ID : " + email + "\n\n" + itemsInfo + "\n\n")); doc.close(); writer.close(); //SENDING THE BILL IN MAIL TO THE CUSTOMER GmailQuickstart a = new GmailQuickstart(); a.setCusemail(email); a.setCusmessage("Thankyou so much " + cusname + " for coming here.Please visit us again :) \n Please find your bill attached below\n"); a.setCussubject("Bill for order number " + orderid); a.setFileName("Order" + orderid + ".pdf"); Thread t = new Thread(a); t.start(); //alert Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information dialog"); alert.setHeaderText(null); alert.setContentText(" Payment has Received Successfully"); alert.showAndWait(); }
From source file:superlaskuttaja.logiikka.PdfExtractor.java
public void vieLaskuPdf(String laskunNumero) { try {/*ww w .j a v a 2s. c o m*/ String polku = ""; String viiteTarkisteella; ResultSet rs = lataaja.getDbc() .executeQuery("select distinct viiteTarkisteella\n" + "from Lasku, Pankkiviivakoodi\n" + "where laskunNumero = " + laskunNumero + "\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + ""); rs.first(); viiteTarkisteella = rs.getString(1); rs = lataaja.getDbc() .executeQuery("select pdfOletusvientipolku\n" + "from Asetukset\n" + "where asetuksetID = 1"); if (rs.first()) { if (rs.getString(1) != null) { polku = rs.getString(1); chooser.setCurrentDirectory(new File(polku)); } chooser.setSelectedFile(new File(viiteTarkisteella + ".pdf")); } int retrival = chooser.showSaveDialog(chooser); if (!polku.equals(chooser.getCurrentDirectory().getPath())) { lataaja.getDbc().executeUpdate("update Asetukset\n" + "set pdfOletusvientipolku = '" + chooser.getCurrentDirectory().getPath() + "'\n" + "where asetuksetID = 1"); } Document document = new Document(PageSize.A4, 40, 20, 30, 30); if (retrival == JFileChooser.APPROVE_OPTION) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(chooser.getSelectedFile())); muodostaDokumentti(document, laskunNumero, writer); writer.close(); } else { } } catch (SQLException sQLException) { sQLException.printStackTrace(); } catch (HeadlessException headlessException) { } catch (FileNotFoundException fileNotFoundException) { } catch (DocumentException documentException) { } catch (ParseException parseException) { } }
From source file:userInterface.SystemAdmin.PovertyAnalysisJPanel.java
private void downloadPDFJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadPDFJButtonActionPerformed Document document = new Document(); try {/*from ww w . j a v a 2s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf")); document.open(); Font helveticaBold = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.NORMAL, new GrayColor(1)); Font helveticaNormal = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new GrayColor(1)); Paragraph paragraphOne = new Paragraph("Safety Meter Report", helveticaBold); document.add(paragraphOne); document.add(new Paragraph(" ")); DefaultTableModel model = (DefaultTableModel) povertyJTable.getModel(); int numRows = model.getRowCount(); int numColum = model.getColumnCount(); int i, j = 0; for (i = 0; i < numRows; i++) { Paragraph info = new Paragraph("Network Name is " + model.getValueAt(i, 0), helveticaNormal); Paragraph sectionContent3 = new Paragraph( "Average Income of A Person is $" + model.getValueAt(i, 2), helveticaNormal); info.add(sectionContent3); Paragraph sectionContent1 = new Paragraph("Crime Rate is " + model.getValueAt(i, 6) + "%", helveticaNormal); info.add(sectionContent1); Paragraph sectionContent2 = new Paragraph("Poverty Rate is " + model.getValueAt(i, 4) + "%", helveticaNormal); info.add(sectionContent2); Paragraph sectionContent4 = new Paragraph( "Percentage of People Having FireArms " + model.getValueAt(i, 3) + "%", helveticaNormal); info.add(sectionContent4); document.add(info); Paragraph space = new Paragraph(" ", helveticaNormal); document.add(space); } //document.add(table); document.close(); writer.close(); JOptionPane.showMessageDialog(povertyJTable, "Please visit Downloads folder to view your report"); } catch (Exception e) { JOptionPane.showMessageDialog(povertyJTable, e); } }
From source file:Utility.PDFDemo.java
public void cretePDF(String name, String rpor) throws FileNotFoundException { try {/* ww w. j ava 2s.c om*/ //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); try { // //file path //String path = "docs/" + name; docwriter = PdfWriter.getInstance(doc, new FileOutputStream(rpor + ".pdf")); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(rpor); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks Paragraph pp = new Paragraph("Cocoa Health And Extension", forTitle); pp.setAlignment(Element.ALIGN_CENTER); Paragraph palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); Chunk chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position Paragraph underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); Chunk chuk1 = new Chunk("Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); Chunk chuk2 = new Chunk(name, bfBold12); Paragraph regionText = new Paragraph(rpor, bfBold12); regionText.setAlignment(Element.ALIGN_CENTER); String rporx = ""; // ResultSet dir = manager.PDFdemos(name); // try { // if (dir.next()) { // rporx = dir.getString(12); // // } // } catch (SQLException ex) { // Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); // } Paragraph regionTexts = new Paragraph(rporx, bfBold12); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports()); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion Paragraph newDate = new Paragraph(new Date().toString(), bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); //close the document doc.close(); //close the writer docwriter.close(); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Visao.Relatorio.GraficoPerCapta.java
public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException { Document document = null;//www . j a va 2 s. co m PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); //add image int width = 500; int height = 400; BufferedImage bufferedImage = chart.createBufferedImage(width, height); Image image = Image.getInstance(writer, bufferedImage, 1.0f); document.add(image); Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); String quebralinha = "\n\nPopulao dos Estados\n\n"; Paragraph preface = new Paragraph(quebralinha, boldFont); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); PdfPTable table = new PdfPTable(2); PdfPCell pdfWordCell = new PdfPCell(); PdfPCell pdfWordCell1 = new PdfPCell(); Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); Phrase secondLine = new Phrase("Populao", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); pdfWordCell.addElement(firstLine); pdfWordCell1.addElement(secondLine); table.addCell(pdfWordCell); table.addCell(pdfWordCell1); table.addCell("SP"); table.addCell(String.valueOf(44396484)); table.addCell("MG"); table.addCell(String.valueOf(20869101)); table.addCell("RJ"); table.addCell(String.valueOf(16550024)); table.addCell("BA"); table.addCell(String.valueOf(15203934)); table.addCell("RS"); table.addCell(String.valueOf(11247972)); table.addCell("PR"); table.addCell(String.valueOf(11163018)); table.addCell("PE"); table.addCell(String.valueOf(9345173)); table.addCell("CE"); table.addCell(String.valueOf(8904459)); table.addCell("PA"); table.addCell(String.valueOf(8175113)); table.addCell("MA"); table.addCell(String.valueOf(6904241)); table.addCell("SC"); table.addCell(String.valueOf(6819190)); table.addCell("GO"); table.addCell(String.valueOf(6610681)); table.addCell("PB"); table.addCell(String.valueOf(3972202)); table.addCell("AM"); table.addCell(String.valueOf(3938336)); table.addCell("ES"); table.addCell(String.valueOf(3929911)); table.addCell("RN"); table.addCell(String.valueOf(3442175)); table.addCell("AL"); table.addCell(String.valueOf(3340932)); table.addCell("MT"); table.addCell(String.valueOf(3270973)); table.addCell("PI"); table.addCell(String.valueOf(3204028)); table.addCell("DF"); table.addCell(String.valueOf(2914830)); table.addCell("MS"); table.addCell(String.valueOf(2651235)); table.addCell("SE"); table.addCell(String.valueOf(2242937)); table.addCell("RO"); table.addCell(String.valueOf(1768204)); table.addCell("TO"); table.addCell(String.valueOf(1515126)); table.addCell("AC"); table.addCell(String.valueOf(803513)); table.addCell("AP"); table.addCell(String.valueOf(766679)); table.addCell("RR"); table.addCell(String.valueOf(505665)); document.add(table); //release resources document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:Visao.Relatorio.Relatorio_Geral.java
public void create(OutputStream outputStream) throws DocumentException, IOException { Document document = null;/*from w ww. ja va2 s .c o m*/ PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); Paragraph paragraph = new Paragraph("\n\nRelatrio Geral\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); document.add(new Paragraph("Quantidade de Reclamaoes Cadastradas: " + quantidadeReclamacao + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Quantidade de Empresas Cadastradas: " + quantidadeEmpresa + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Quantidade de Regies Cadastradas: " + quantidadeRegiao + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Quantidade de UFs Cadastrados: " + quantidadeUF + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Quantidade de Cidades Cadastradas: " + quantidadeCidade + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Tempo Mdio de Resposta: " + decimalFormat.format(tempoMedio) + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Nota Mdia: " + decimalFormat.format(notamedia) + "\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph( "Quantidade de Reclamaes Resolvidas: " + resolvida + " - " + resolvidaPorcentagem + "%\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Quantidade de Reclamaes No Resolvidas: " + naoresolvida + " - " + naoresolvidaPorcentagem + "%\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.add(new Paragraph("Quantidade de Reclamaes No Avaliadas: " + naoavaliada + " - " + naoavaliadaPorcentagem + "%\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD))); document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesCidadeIntervalo.java
public void create(OutputStream outputStream) throws DocumentException, IOException { Document document = null;/*from ww w. ja v a2 s. c o m*/ PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); Paragraph paragraph = new Paragraph("\n\nReclamaes\n\nCidade: " + cidade, new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); Paragraph paragraph1 = new Paragraph("\nMs Abertura: " + mes + "\nAno Abertura: " + ano, new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); document.add(paragraph1); document.add(new Paragraph("\n\n\n")); PdfPTable table = new PdfPTable(3); PdfPCell pdfWordCell = new PdfPCell(); PdfPCell pdfWordCell1 = new PdfPCell(); PdfPCell pdfWordCell2 = new PdfPCell(); Phrase firstLine = new Phrase("Quantidade de reclamaes", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); Phrase secondLine = new Phrase("Nota mdia consumidor", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); Phrase thirdLine = new Phrase("Tempo mdio de resposta", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); pdfWordCell.addElement(firstLine); pdfWordCell1.addElement(secondLine); pdfWordCell2.addElement(thirdLine); table.addCell(pdfWordCell); table.addCell(pdfWordCell1); table.addCell(pdfWordCell2); table.addCell(String.valueOf(quantidade)); table.addCell(decimalFormat.format(notamedia)); table.addCell(decimalFormat.format(tempoResposta) + " dias"); document.add(table); document.add(new Paragraph("\n\n\nEmpresas Reclamadas\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD))); PdfPTable table1 = new PdfPTable(2); PdfPCell pdfWordCel3 = new PdfPCell(); PdfPCell pdfWordCel4 = new PdfPCell(); Phrase firstLine1 = new Phrase("Empresa", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); Phrase secondLine1 = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); pdfWordCel3.addElement(firstLine1); pdfWordCel4.addElement(secondLine1); table1.addCell(pdfWordCel3); table1.addCell(pdfWordCel4); String consulta = "Select e.nomefantasia, count(r.codigoreclamacao)" + " from Reclamacao r, Empresa e" + " where r.codempresa = e.codigoempresa and" + " r.cidade='" + cidade + "' and r.mesabertura=" + mes + " and r.anoabertura=" + ano + " group by e.nomefantasia" + " order by e.nomefantasia"; Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator(); while (i.hasNext()) { Object[] reclamacaoEmpresa = (Object[]) i.next(); table1.addCell(reclamacaoEmpresa[0].toString()); table1.addCell(reclamacaoEmpresa[1].toString()); } document.add(table1); document.add(new Paragraph("\n\n\nAssuntos Reclamados\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD))); PdfPTable table2 = new PdfPTable(2); PdfPCell pdfWordCel5 = new PdfPCell(); PdfPCell pdfWordCel6 = new PdfPCell(); Phrase firstLine5 = new Phrase("Assunto", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); pdfWordCel5.addElement(firstLine5); pdfWordCel6.addElement(secondLine1); table2.addCell(pdfWordCel5); table2.addCell(pdfWordCel6); String consulta1 = "select assunto, count(codigoreclamacao)" + " from Reclamacao where cidade='" + cidade + "'" + " and mesabertura=" + mes + " and anoabertura=" + ano + " group by assunto " + " order by assunto"; Iterator ii = dao.getSessao().createSQLQuery(consulta1).list().iterator(); while (ii.hasNext()) { Object[] reclamacaoAssunto = (Object[]) ii.next(); table2.addCell(reclamacaoAssunto[0].toString()); table2.addCell(reclamacaoAssunto[1].toString()); } document.add(table2); document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesSexo.java
public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException { Document document = null;/*from ww w .ja v a 2 s.com*/ PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); //add image int width = 400; int height = 300; BufferedImage bufferedImage = chart.createBufferedImage(width, height); Image image = Image.getInstance(writer, bufferedImage, 1.0f); document.add(image); String saida = "\n\n" + controleRelatorio.numeroReclamacoesSexo(); document.add(new Paragraph(saida)); //release resources document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesUF.java
public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException { Document document = null;//from w w w . j a va 2s.com PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); //add image int width = 500; int height = 400; BufferedImage bufferedImage = chart.createBufferedImage(width, height); Image image = Image.getInstance(writer, bufferedImage, 1.0f); document.add(image); Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); String quebralinha = "\n\nQuantidade de reclamaes por UF\n\n"; Paragraph preface = new Paragraph(quebralinha, boldFont); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); PdfPTable table = new PdfPTable(2); PdfPCell pdfWordCell = new PdfPCell(); PdfPCell pdfWordCell1 = new PdfPCell(); Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); Phrase secondLine = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); pdfWordCell.addElement(firstLine); pdfWordCell1.addElement(secondLine); table.addCell(pdfWordCell); table.addCell(pdfWordCell1); String consulta = "Select uf, count(codigoreclamacao) from " + "Reclamacao group by (uf) order by count(codigoreclamacao) desc"; Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator(); while (i.hasNext()) { Object[] reclamacao = (Object[]) i.next(); table.addCell(reclamacao[0].toString()); table.addCell(reclamacao[1].toString()); } document.add(table); //release resources document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }