List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:VisitorsArchiveFrame.java
private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed model = (DefaultTableModel) visitorsloginfotable.getModel(); Document document = new Document(); try {// w w w . j a va 2 s . c o m PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\VisitorsArchive.pdf")); document.open(); PdfPTable tab = new PdfPTable(model.getColumnCount()); for (int i = 0; i < model.getColumnCount(); i++) { tab.addCell(model.getColumnName(i)); } for (int i = 0; i < model.getRowCount(); i++) { for (int j = 0; j < model.getColumnCount(); j++) { if (model.getValueAt(i, j) != null) { tab.addCell(model.getValueAt(i, j).toString()); } else { tab.addCell("-"); } } } document.add(tab); JOptionPane.showMessageDialog(null, "Data saved at " + path + "'\\PDF\\VisitorsArchive.pdf' successfully", "Message", JOptionPane.INFORMATION_MESSAGE); document.close(); } catch (FileNotFoundException | DocumentException ex) { // Logger.getLogger(VisitorsArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:PrintProjects.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from ww w . j av a2 s . c o m*/ response.setContentType("Invoice.pdf"); //Get the output stream for writing PDF object OutputStream out = response.getOutputStream(); SystemDao dao = new SystemDao(); String username_dbase = getServletContext().getInitParameter("username"); String dbasepsw = getServletContext().getInitParameter("password"); String dbase = getServletContext().getInitParameter("jdbcConnection"); dao.open(username_dbase, dbasepsw, dbase); Document document = new Document(); /* Basic PDF Creation inside servlet */ ArrayList<User> users = dao.gettAllUsers(); //tithes ArrayList<Donation> list = dao.getAllDonations(); ArrayList<String> projects = dao.getProjects(); PdfWriter.getInstance(document, out); document.open(); document.addAuthor("LightHouse Chapel International"); document.addCreationDate(); document.addCreator("lci.com"); document.add(new Paragraph("============ PROJECTS ===========")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" NAME " + " " + " NUMBER ")); for (int x = 0; x < projects.size(); ++x) { String[] data = projects.get(x).split("@"); document.add(new Paragraph(" " + data[1] + " " + data[0])); } document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Total Donations : " + projects.size())); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.close(); } catch (Exception ex) { response.sendRedirect("systemError.jsp"); } }
From source file:NPRImpl.java
@Override public boolean saveReservationToPdf(ReservationImpl reservationImpl) throws RemoteException { try {//from ww w .java 2 s.com BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } // TODO add your handling code here: Document doc = new Document(); FileOutputStream fos = new FileOutputStream(path + "\\reservation\\" + reservationImpl.getlName().trim() + ", " + reservationImpl.getfName().trim() + "ReservationForm.pdf"); PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("ReservationForm.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getDatePaid().trim(), 435, 655, 0); if (reservationImpl.getmName().trim().isEmpty()) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getlName().trim() + ", " + reservationImpl.getfName(), 265, 625, 0); } else { content.showTextAligned( PdfContentByte.ALIGN_LEFT, reservationImpl.getlName().trim() + ", " + reservationImpl.getfName() + " " + reservationImpl.getmName().charAt(0) + ".", 265, 625, 0); } content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getAddress().trim(), 265, 600, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getZipCode().trim(), 265, 580, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getmNumber().trim(), 265, 565, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getEmail().trim(), 265, 550, 0); content.setFontAndSize(bf, 12); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Room No.:" + reservationImpl.getRoom().trim(), 125, 370, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getRoomType().trim(), 325, 370, 0); // content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getsTerm().trim(), 125, 310, 0); if (reservationImpl.getsTerm() != null) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getsTerm().trim(), 125, 310, 0); if (!reservationImpl.getAyTo().trim().isEmpty() & !reservationImpl.getAyFrom().trim().isEmpty()) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getAyFrom().trim() + " - " + reservationImpl.getAyTo().trim(), 325, 310, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, " - ", 435, 310, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, " - ", 325, 310, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, " - ", 435, 310, 0); } } else { if (reservationImpl.getOthers().trim().isEmpty()) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, " - ", 325, 310, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, " - ", 435, 310, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, " - ", 325, 310, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getOthers().trim(), 435, 310, 0); } } content.showTextAligned(PdfContentByte.ALIGN_LEFT, reservationImpl.getDatePaid().trim(), 265, 210, 0); content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); pdfWriter.close(); } catch (DocumentException | FileNotFoundException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } return true; }
From source file:NPRImpl.java
@Override public boolean saveRegistrationToPdf(RegistrationImpl registrationImpl, ResidentImpl residentImpl) throws RemoteException { try {/* w ww. j a v a 2 s .co m*/ BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } String gend = ""; Document doc = new Document(); FileOutputStream fos = new FileOutputStream(path + "\\registration\\" + residentImpl.getLName().trim() + ", " + residentImpl.getFName().trim() + "RegistrationResidentForm.pdf"); PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("RegistrationResidentForm.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); if (residentImpl.getPicture() != null) { Image image1 = Image.getInstance(residentImpl.getPicture()); image1.scaleAbsolute(95, 105); image1.setAbsolutePosition(465f, 635f); content.addImage(image1); } //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); //last name content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getLName().trim(), 175, 610, 0); //first name content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getFName().trim(), 325, 610, 0); //middle name content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getMName().trim(), 470, 610, 0); //college content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getCollege().trim(), 180, 582, 0); //Course and year content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getCourse().trim() + " - " + registrationImpl.getYear().trim(), 180, 568, 0); //department content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getDepartment().trim(), 400, 582, 0); //Sex content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getGender().trim(), 400, 568, 0); //Home address content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getAddress().trim(), 110, 540, 0); //resident mobile no1 content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMobile_number().trim(), 187, 485, 0); //resident mobile no2 content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMobile_number2().trim(), 187, 470, 0); //student email content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getEmail().trim(), 397, 485, 0); //fathers name content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherName().trim(), 110, 443, 0); //fathers area code content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherAreaCode().trim(), 300, 443, 0); //father landline content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherPhone().trim(), 355, 443, 0); //father mobile content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherMobile().trim(), 490, 443, 0); //father email content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherEmail().trim(), 110, 430, 0); //mother name content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherName().trim(), 110, 402, 0); //mother area code content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherAreaCode().trim(), 300, 402, 0); //mother landline content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherPhone().trim(), 355, 402, 0); //mother mobile content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherMobile().trim(), 490, 402, 0); //mother email content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherEmail().trim(), 110, 387, 0); //guardian name content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianName().trim(), 170, 335, 0); //guardian contact number content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianMobile().trim(), 470, 335, 0); //guardian address content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianAddress().trim(), 125, 322, 0); //guardian relation content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianRelation().trim(), 170, 307, 0); content.setFontAndSize(bf, 12); //room details content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Room No.: " + registrationImpl.getRoom_number().trim() + " - " + registrationImpl.getRoom_type().trim(), 355, 235, 0); content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); pdfWriter.close(); } catch (DocumentException | FileNotFoundException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } return true; }
From source file:NPRImpl.java
@Override public boolean saveFurnitureToPdf(ArrayList<String> info, ArrayList<FurnitureImpl> furnitureImpl) throws RemoteException { try {//from w w w . j a v a2 s. c o m // TODO add your handling code here: Document doc = new Document(); BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } FileOutputStream fos = new FileOutputStream(path + "\\furniture\\" + info.get(0) + "InventoryForm.pdf"); PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("InventoryForm.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); float added = 0; float rowSize = 175; float columnSize = 560; for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); //room number content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0).trim(), 185, 650, 0); //room type content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2).trim(), 185, 635, 0); //resident content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1).trim(), 185, 620, 0); for (FurnitureImpl f : furnitureImpl) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, f.getItem_name().trim(), rowSize - 60, columnSize + added, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, f.getControl_number().trim(), rowSize + 30, columnSize + added, 0); added -= 15; } content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); pdfWriter.close(); } catch (FileNotFoundException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (DocumentException | IOException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } return true; }
From source file:NPRImpl.java
@Override public boolean saveGadgetToPdf(ArrayList<String> info, ArrayList<GadgetImpl> gadgetImpl) throws RemoteException { try {/*from w w w. j ava 2s.com*/ // TODO add your handling code here: BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } Document doc = new Document(); FileOutputStream fos = new FileOutputStream( path + "\\gadget\\" + info.get(0).trim() + "GadgetForm.pdf"); PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("GadgetForm.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); float rowSize = 175; float columnSize = 495; float added = 0; for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); //room number content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1).trim(), 240, 630, 0); //room type content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2).trim(), 240, 615, 0); //resident content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0).trim(), 240, 600, 0); for (GadgetImpl g : gadgetImpl) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, g.getItem_name().trim(), rowSize - 60, columnSize + added, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, g.getDescription().trim(), rowSize + 65, columnSize + added, 0); added -= 15; } content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); pdfWriter.close(); } catch (DocumentException | FileNotFoundException | IllegalPdfSyntaxException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } return true; }
From source file:NPRImpl.java
@Override public boolean saveTransientBillingToPdf(String transientIdnum, String amountPaid, String admin, String controlN, String mode, String remarks) throws RemoteException { try {//from w w w . j av a2s . com // TODO add your handling code here: BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } PreparedStatement preparedStatement = connection .prepareStatement("SELECT * FROM transient WHERE transientIdnum = ?"); preparedStatement.setInt(1, Integer.parseInt(transientIdnum.trim())); ResultSet rs = preparedStatement.executeQuery(); rs.next(); Document doc = new Document(); FileOutputStream fos = new FileOutputStream( path + "\\transientBilling\\" + rs.getString("transientFname") + " " + rs.getString("transientLname") + "CheckoutDetails.pdf"); PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("Payment Remittance.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 11); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Control Number: " + controlN, 300, 260, 0); if (mode.equals("cash")) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 346, 218, 0); } else if (mode.equals("cheque")) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 347, 198, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 347, 178, 0); } content.showTextAligned(PdfContentByte.ALIGN_LEFT, remarks, 330, 140, 0); //Date content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()), 460, 260, 0); //Resident name content.showTextAligned(PdfContentByte.ALIGN_LEFT, rs.getString("transientFname") + " " + rs.getString("transientLname"), 90, 250, 0); //Purpose of payment content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Transient Checkout", 125, 223, 0); //Room Details content.showTextAligned(PdfContentByte.ALIGN_LEFT, rs.getString("transientReservedRoomNo"), 125, 183, 0); //Amount content.showTextAligned(PdfContentByte.ALIGN_LEFT, amountPaid, 125, 158, 0); //Received By admin name! content.showTextAligned(PdfContentByte.ALIGN_LEFT, admin, 125, 105, 0); content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); return true; } catch (DocumentException | SQLException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (FileNotFoundException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } }
From source file:NPRImpl.java
@Override public boolean savePaymentRemittanceToPDF(ArrayList<String> info) throws RemoteException { try {/*w w w. ja v a 2 s . c o m*/ // TODO add your handling code here: BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } Document doc = new Document(); FileOutputStream fos = new FileOutputStream( path + "\\residentBilling\\" + info.get(0) + "Payment Remittance.pdf"); PdfWriter.getInstance(doc, fos); PreparedStatement preparedStatement = connection.prepareStatement( "SELECT * FROM billing WHERE residentIdnum = ? AND billingStatus LIKE 'unpaid'"); preparedStatement.setInt(1, Integer.parseInt(info.get(7))); ResultSet rs = preparedStatement.executeQuery(); rs.next(); PdfReader pdfReader = new PdfReader("Payment Remittance.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 11); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Control Number: " + info.get(4), 300, 260, 0); if (info.get(5).equals("cash")) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 346, 218, 0); } else if (info.get(5).equals("cheque")) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 347, 198, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 347, 178, 0); } content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(6), 330, 140, 0); //Date content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()), 460, 260, 0); //Resident name content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0), 90, 250, 0); //Purpose of payment content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Resident Monthly Billing", 90, 223, 0); //Room Details content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1), 125, 183, 0); //Amount content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2), 125, 158, 0); //Received By admin name! content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(3), 125, 105, 0); content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); return true; } catch (DocumentException | SQLException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (FileNotFoundException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex); label.setText(ex.getMessage()); return false; } }
From source file:PrefichaPDF.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* w w w. ja v a 2 s . com*/ response.setContentType("application/pdf"); String curp = new String(request.getParameter("curp").getBytes("ISO-8859-1"), "UTF-8"); ConexionOracle conexionOracle = new ConexionOracle(); String sql = "select * from PERSONALDATA_ASP_TAB where curp=" + "'" + curp + "'"; System.out.println(sql); System.out.println("Esta es la curp: " + curp); conexionOracle.conectar(); Connection conn = conexionOracle.getConnection(); // driver@machineName:port:SID , userid, password Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery(sql); while (rset.next()) { fichabd = rset.getString("id_aspirante"); periodobd = rset.getString("periodo_solicitud"); prefichabd = rset.getString("preficha"); nombrebd = rset.getString("nombre"); String appat = rset.getString("apellido_pat"); String apmat = rset.getString("apellido_mat"); apellidosbd = appat + " " + apmat; curpbd = rset.getString("curp"); carrerabd = rset.getString("carrera"); modalidadbd = rset.getString("modalidad"); } try { Document preficha = new Document(); PdfWriter writer = PdfWriter.getInstance(preficha, response.getOutputStream()); preficha.open(); //encabezado //encabezado //encabezado //encabezado // documento.add(vacio); // documento.add(vacio); // documento.add(vacio); Paragraph depto = new Paragraph("Departamento de servicios escolares", FontFactory.getFont("arial", 20, Font.BOLD)); depto.setAlignment(Element.ALIGN_CENTER); preficha.add(depto); Paragraph vacio = new Paragraph(" ", FontFactory.getFont("arial", 10, Font.BOLD)); vacio.setAlignment(Element.ALIGN_CENTER); preficha.add(vacio); preficha.add(vacio); // preficha.add(vacio); //cuerpo //cuerpo //cuerpo //cuerpo //cuerpo Paragraph periodo_text = new Paragraph("Convocatoria de nuevo ingreso periodo: " + periodobd, FontFactory.getFont("arial", 10, Font.BOLD)); periodo_text.setAlignment(Element.ALIGN_CENTER); preficha.add(periodo_text); preficha.add(vacio); preficha.add(vacio); Paragraph fotografia = new Paragraph("Fotografa", FontFactory.getFont("arial", 10, Font.BOLD)); fotografia.setAlignment(Element.ALIGN_CENTER); preficha.add(fotografia); PdfContentByte rectangulo_general = writer.getDirectContentUnder(); rectangulo_general.rectangle(50, 48, 500, 710); rectangulo_general.fill(); drawRectangleSC(rectangulo_general, 50, 48, 500, 710); PdfContentByte rectangulo_periodo = writer.getDirectContentUnder(); rectangulo_periodo.rectangle(125, 725, 350, 20); rectangulo_periodo.fill(); drawRectangleSC(rectangulo_periodo, 125, 725, 350, 20); String url_logo = "/Imagenes/itt_logo_opt.jpg"; String absolute_url_logo = getServletContext().getRealPath(url_logo); Image itt_logo = Image.getInstance(absolute_url_logo); String url_logo_bnmx = "/Imagenes/bnmx_color_opt.jpg"; String absolute_url_logo_bnmx = getServletContext().getRealPath(url_logo_bnmx); Image bnmx_logo = Image.getInstance(absolute_url_logo_bnmx); Image Logo_itt = Image.getInstance(itt_logo); Logo_itt.setAbsolutePosition(140f, 640f); preficha.add(Logo_itt); Image Logo_banco = Image.getInstance(bnmx_logo); Logo_banco.setAbsolutePosition(380f, 340f); preficha.add(Logo_banco); PdfContentByte espacio_imagen = writer.getDirectContentUnder(); espacio_imagen.rectangle(255, 635, 85, 80); espacio_imagen.fill(); drawRectangleSC(espacio_imagen, 255, 635, 85, 80); // preficha.add(vacio); preficha.add(vacio); PdfContentByte fechaimpr = writer.getDirectContentUnder(); fechaimpr.rectangle(416, 635, 100, 35); fechaimpr.fill(); drawRectangleSC(fechaimpr, 416, 635, 100, 35); // drawRectangle(fechaimpr, 85, 530, 430, 25); Paragraph fechapdf = new Paragraph("\tFecha de impresin ", FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD)); fechapdf.setAlignment(Element.ALIGN_RIGHT); preficha.add(fechapdf); Paragraph fechapdf_fec = new Paragraph("\t" + fecha_hoy() + " ", FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD)); fechapdf_fec.setAlignment(Element.ALIGN_RIGHT); preficha.add(fechapdf_fec); preficha.add(vacio); Paragraph no_preficha = new Paragraph("Preficha N: " + prefichabd, FontFactory.getFont("arial", 20, Font.BOLD)); no_preficha.setAlignment(Element.ALIGN_CENTER); preficha.add(no_preficha); preficha.add(vacio); // preficha.add(vacio); PdfContentByte rectangulo_preficha_no = writer.getDirectContentUnder(); rectangulo_preficha_no.rectangle(85, 590, 430, 25); rectangulo_preficha_no.fill(); drawRectangleSC(rectangulo_preficha_no, 85, 590, 430, 25); PdfContentByte rectangulo_datos = writer.getDirectContentUnder(); rectangulo_datos.rectangle(85, 500, 430, 80); // rectangulo_datos.rec rectangulo_datos.fill(); drawRectangleSC(rectangulo_datos, 85, 500, 430, 80); ////////////////////////////// Paragraph nombre = new Paragraph( " Nombre: " + nombrebd, FontFactory.getFont("arial", 10, Font.BOLD)); nombre.setAlignment(Element.ALIGN_LEFT); preficha.add(nombre); // preficha.add(vacio); Paragraph apellidos = new Paragraph( " " + apellidosbd, FontFactory.getFont("arial", 10, Font.BOLD)); apellidos.setAlignment(Element.ALIGN_LEFT); preficha.add(apellidos); // preficha.add(vacio); Paragraph CURP = new Paragraph( " CURP: " + curpbd, FontFactory.getFont("arial", 10, Font.BOLD)); CURP.setAlignment(Element.ALIGN_LEFT); preficha.add(CURP); // preficha.add(vacio); Paragraph carrera = new Paragraph( " Carrera Solicitada: " + carrerabd, FontFactory.getFont("arial", 10, Font.BOLD)); carrera.setAlignment(Element.ALIGN_LEFT); preficha.add(carrera); // preficha.add(vacio); Paragraph modalidad = new Paragraph( " Modalidad: " + modalidadbd, FontFactory.getFont("arial", 10, Font.BOLD)); modalidad.setAlignment(Element.ALIGN_LEFT); preficha.add(modalidad); preficha.add(vacio); // preficha.add(vacio); Paragraph formatoBanamex = new Paragraph("FORMATO UNIVERSAL PARA DEPSITOS EN SUCURSALES BANAMEX", FontFactory.getFont("arial", 10, Font.BOLD)); formatoBanamex.setAlignment(Element.ALIGN_CENTER); preficha.add(formatoBanamex); PdfContentByte rectanguloDepositoB = writer.getDirectContentUnder(); rectanguloDepositoB.rectangle(85, 470, 430, 20); rectanguloDepositoB.fill(); drawRectangle(rectanguloDepositoB, 85, 470, 430, 20); PdfContentByte rectanguloPago = writer.getDirectContentUnder(); rectanguloPago.rectangle(85, 280, 430, 190); rectanguloPago.fill(); drawRectangleSC(rectanguloPago, 85, 280, 430, 190); preficha.add(vacio); PdfContentByte rectanguloConcepto = writer.getDirectContentUnder(); rectanguloConcepto.rectangle(150, 425, 295, 35); // rectangulo_datos.rec rectanguloConcepto.fill(); drawRectangleSC(rectanguloConcepto, 150, 425, 295, 35); Paragraph formatoConceptoPre = new Paragraph("CONCEPTO: PAGO DE DERECHO A EXAMEN DE ADMISIN", FontFactory.getFont("arial", 10, Font.BOLD)); formatoConceptoPre.setAlignment(Element.ALIGN_CENTER); preficha.add(formatoConceptoPre); Paragraph fechaEmision = new Paragraph("FECHA DE EMISIN: 18/12/2014", FontFactory.getFont("arial", 10, Font.BOLD)); fechaEmision.setAlignment(Element.ALIGN_CENTER); preficha.add(fechaEmision); preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); preficha.add(vacio); Paragraph importe = new Paragraph("IMPORTE A PAGAR: $1,500.", FontFactory.getFont("arial", 15, Font.BOLD)); importe.setAlignment(Element.ALIGN_CENTER); preficha.add(importe); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); String ref = "44353452342353464765634523434"; Paragraph referencia = new Paragraph( " REFERENCIA (B): " + ref, FontFactory.getFont("arial", 10, Font.BOLD)); referencia.setAlignment(Element.ALIGN_LEFT); preficha.add(referencia); preficha.add(vacio); // Paragraph descrConcepto = new Paragraph("DESCRIPCIN DEL CONCEPTO: CUOTA POR CONCEPTO DE PREINCRIPCIN.", FontFactory.getFont("arial", 10, Font.BOLD)); // descrConcepto.setAlignment(Element.ALIGN_CENTER); // preficha.add(descrConcepto); preficha.add(vacio); preficha.add(vacio); preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); // preficha.add(vacio); Paragraph atencion = new Paragraph("Atencin", FontFactory.getFont("arial", 15, Font.BOLD)); atencion.setAlignment(Element.ALIGN_CENTER); preficha.add(atencion); PdfContentByte rectangulo_atencion = writer.getDirectContentUnder(); rectangulo_atencion.rectangle(245, 229, 100, 25); rectangulo_atencion.fill(); drawRectangle(rectangulo_atencion, 245, 229, 100, 25); PdfContentByte rectangulo_info = writer.getDirectContentUnder(); rectangulo_info.rectangle(85, 94, 430, 100); rectangulo_info.fill(); drawRectangle(rectangulo_info, 85, 94, 430, 120); preficha.add(vacio); preficha.add(vacio); Paragraph informacion = new Paragraph( " Para continuar con el proceso de preinscripcin debers:\n" + " - Realizar el pago para tu examen de admisin con la \"REFERENCIA\" que aparece\n" + " en este documento en cualquier sucursal BANAMEX.\n" + " - Recibir la notificacin en tu correo electrnico y estar al pendiente de \n" + " las notificaciones que sern enviadas al mismo de que el pago ya fue procesado \n" + " para completar tu proceso de preinscripcin.\n", FontFactory.getFont("arial", 10, Font.BOLD)); informacion.setAlignment(Element.ALIGN_LEFT); preficha.add(informacion); // pie // pie // pie // pie // pie preficha.add(vacio); preficha.add(vacio); preficha.addTitle("Preficha"); preficha.addSubject("Instituto Tecnolgico de Toluca"); preficha.addKeywords("Instituto Tecnolgico de Toluca"); preficha.addAuthor("Departamento de Servicios escolares"); preficha.addCreator("Departamento de Servicios escolares"); preficha.close(); preficha.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } } catch (SQLException ex) { Logger.getLogger(PrefichaPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Billing.java
public boolean savePaymentRemittanceToPDF(ArrayList<String> info) { try {//w ww .jav a 2s .c om // TODO add your handling code here: BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } Document doc = new Document(); FileOutputStream fos = new FileOutputStream( path + "\\residentBilling\\" + info.get(0) + "Payment Remittance.pdf"); PdfWriter.getInstance(doc, fos); PreparedStatement preparedStatement = connection.prepareStatement( "SELECT * FROM billing WHERE residentIdnum = ? AND billingStatus LIKE 'unpaid'"); preparedStatement.setInt(1, Integer.parseInt(info.get(7))); ResultSet rs = preparedStatement.executeQuery(); rs.next(); PdfReader pdfReader = new PdfReader("Payment Remittance.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 11); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Control Number: " + info.get(4), 300, 260, 0); if (info.get(5).equals("cash")) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 346, 218, 0); } else if (info.get(5).equals("cheque")) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 347, 198, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 347, 178, 0); } content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(6), 330, 140, 0); //Date content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MM/dd/yyyy") .format(dateLabel.getDateFormat().parse(dateLabel.getText())), 460, 260, 0); //Resident name content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0), 90, 250, 0); //Purpose of payment content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Resident Monthly Billing", 90, 223, 0); //Room Details content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1), 125, 183, 0); //Amount content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2), 125, 158, 0); //Received By admin name! content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(3), 125, 105, 0); content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); return true; } catch (DocumentException | SQLException | ParseException ex) { // Logger.getLogger(Billing.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); return false; } catch (FileNotFoundException ex) { // Logger.getLogger(Billing.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(Billing.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); return false; } }