List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
From source file:sandbox.columntext.DropTablePart.java
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();//from w ww. j a va2 s.c o m Rectangle column = new Rectangle(36, 36, 559, 806); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(column); for (int i = 0; i < 4;) { PdfPTable table = new PdfPTable(new float[] { 0.25f, 0.25f, 0.25f, 0.25f }); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Phrase("inner table " + (++i))); cell.setColspan(4); table.addCell(cell); for (int j = 0; j < 18; j++) { table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); } ct.addElement(table); if (ColumnText.hasMoreText(ct.go())) { document.newPage(); ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(column); } } document.close(); }
From source file:server.kartu.tik.iText.java
public String createPDF(String tanggal, ArrayList kegiatan, String divisi) { ArrayList<Kegiatan> list = new ArrayList<>(kegiatan); String output = System.getProperty("user.dir") + "\\src\\data\\pdf\\" + tanggal + " " + getNamalengkap() + "-" + getTglnoktp() + ".pdf"; String namaDivisi = ""; switch (divisi) { case "1": namaDivisi = "Ekonomi"; break;//from w w w . j a v a2s. co m case "2": namaDivisi = "Politik"; break; case "3": namaDivisi = "Sosial Budaya"; break; case "4": namaDivisi = "Keamanan"; break; } Document document = new Document(PageSize.A4); try { PdfWriter.getInstance(document, new FileOutputStream(output)); document.open(); //------------------------------------------------------------------------------------- TITLE PdfPTable title = new PdfPTable(1); title.setWidthPercentage(100); Font f = new Font(FontFamily.HELVETICA, 14, Font.NORMAL, GrayColor.GRAYWHITE); PdfPCell celltitle = new PdfPCell(new Phrase("KARTU TIK (" + namaDivisi + ")", f)); celltitle.setMinimumHeight(20); celltitle.setBackgroundColor(GrayColor.GRAYBLACK); celltitle.setHorizontalAlignment(Element.ALIGN_CENTER); celltitle.setColspan(3); title.addCell(celltitle); document.add(title); //-------------------------------------------------------------------------------------- END //------------------------------------------------------------------------------------- NAMA + ALIAS float[] columnWidths = { 8, 2 }; PdfPTable tabel1 = new PdfPTable(columnWidths); tabel1.setWidthPercentage(100); PdfPTable innerTable1 = new PdfPTable(1); innerTable1.setWidthPercentage(100); PdfPTable innerTable2 = new PdfPTable(1); innerTable2.setWidthPercentage(100); PdfPCell cell; innerTable1.addCell( "1. a. Nama Lengkap : " + getNamalengkap() + " \n\n b. Alias : " + getAlias() + " \n\n"); innerTable1.addCell("2. Kebangsaan \n a. Tgl. No. KTP : " + getTglnoktp() + " \n\n b. Tgl. No. Pasport : " + getTglnopasport() + "\n\n"); innerTable1.addCell("3. Agama : " + getAgama()); cell = new PdfPCell(innerTable1); cell.setMinimumHeight(135); tabel1.addCell(cell); if (getUrlfoto().equalsIgnoreCase("") || getUrlfoto().isEmpty() || getUrlfoto() == null) { } else { Image image = Image.getInstance(getUrlfoto()); cell = new PdfPCell(image, false); if (image.getWidth() < 90) { cell.setPaddingLeft(8); } else { cell.setPaddingLeft(3); } } cell.setMinimumHeight(135); tabel1.addCell(cell); cell = new PdfPCell(); cell.setColspan(14); tabel1.addCell(cell); document.add(tabel1); //------------------------------------------------------------------------------------- NAMA + ALIAS END //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT PdfPTable tabel4 = new PdfPTable(1); tabel4.setWidthPercentage(100); Paragraph pTglLahirnTempat = new Paragraph(); pTglLahirnTempat.add("4. a. Tgl. Lahir/ Umur : " + getTgllahir()); pTglLahirnTempat.add("\n\n b. Tempat Lahir : " + getTempatlahir()); pTglLahirnTempat.setLeading(0, 1); PdfPCell cTglLahirnTempat = new PdfPCell(); cTglLahirnTempat.setMinimumHeight(45); cTglLahirnTempat.addElement(pTglLahirnTempat); tabel4.addCell(cTglLahirnTempat); document.add(tabel4); //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT END //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN PdfPTable tabel5 = new PdfPTable(1); tabel5.setWidthPercentage(100); Paragraph pAlamat = new Paragraph(); pAlamat.add("5. Alamat : "); pAlamat.add(alamat); pAlamat.setLeading(0, 1); PdfPCell cAlamat = new PdfPCell(); cAlamat.setMinimumHeight(18); cAlamat.addElement(pAlamat); tabel5.addCell(cAlamat); document.add(tabel5); PdfPTable tabel51 = new PdfPTable(1); tabel51.setWidthPercentage(100); Paragraph pAlamatUbah = new Paragraph(); pAlamatUbah.add("6. Perubahan Alamat :"); pAlamatUbah.add("\n\n 1. "); pAlamatUbah.add("\n\n 2. "); pAlamatUbah.add("\n\n 3. "); pAlamatUbah.add("\n\n"); pAlamatUbah.setLeading(0, 1); PdfPCell cAlamatUbah = new PdfPCell(); cAlamatUbah.addElement(pAlamatUbah); tabel51.addCell(cAlamatUbah); document.add(tabel51); //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN END //------------------------------------------------------------------------------------- KEDUDUKAN KELUARGA PdfPTable tabel6 = new PdfPTable(1); tabel6.setWidthPercentage(100); Paragraph pKedudukanKeluarga = new Paragraph(); pKedudukanKeluarga.add("7. Kedudukan dalam Keluarga : "); pKedudukanKeluarga.setLeading(0, 1); PdfPCell cKedudukanKeluarga = new PdfPCell(); cKedudukanKeluarga.setMinimumHeight(20); cKedudukanKeluarga.addElement(pKedudukanKeluarga); tabel6.addCell(cKedudukanKeluarga); document.add(tabel6); PdfPTable tabel61 = new PdfPTable(1); tabel61.setWidthPercentage(100); Paragraph pNamaBapakIbu = new Paragraph(); pNamaBapakIbu.add("8. a. Nama Bapak : "); pNamaBapakIbu.add("\n\n Nama Ibu : "); pNamaBapakIbu.add("\n\n b. Alamat : "); pNamaBapakIbu.setLeading(0, 1); PdfPCell cNamaBapakIbu = new PdfPCell(); cNamaBapakIbu.setMinimumHeight(70); cNamaBapakIbu.addElement(pNamaBapakIbu); tabel61.addCell(cNamaBapakIbu); document.add(tabel61); //------------------------------------------------------------------------------------- KEDUDUKAN END //------------------------------------------------------------------------------------- PEKERJAAN PdfPTable tabel7 = new PdfPTable(2); tabel7.setWidthPercentage(100); Paragraph pPekerjaan = new Paragraph(); pPekerjaan.add("9. a. Pekerjaan : " + getPekerjaan()); pPekerjaan.setLeading(0, 1); PdfPCell cPekerjaan = new PdfPCell(); cPekerjaan.setMinimumHeight(20); cPekerjaan.addElement(pPekerjaan); tabel7.addCell(cPekerjaan); Paragraph pJabatan = new Paragraph(); pJabatan.add(" b. Jabatan : " + getJabatan()); pJabatan.setLeading(0, 1); PdfPCell cJabatan = new PdfPCell(); cJabatan.setMinimumHeight(20); cJabatan.addElement(pJabatan); tabel7.addCell(cJabatan); document.add(tabel7); //------------------------------------------------------------------------------------- PEKERJAAN END //------------------------------------------------------------------------------------- INSTANSI DLL PdfPTable tabel8 = new PdfPTable(1); tabel8.setWidthPercentage(100); Paragraph pInstansi = new Paragraph(); pInstansi.add(" c. Instansi/Lembaga/Kantor : " + getInstansilembagakantor()); pInstansi.setLeading(0, 1); PdfPCell cInstansi = new PdfPCell(); cInstansi.setMinimumHeight(20); cInstansi.addElement(pInstansi); tabel8.addCell(cInstansi); document.add(tabel8); //------------------------------------------------------------------------------------- INSTANSI DLL END //------------------------------------------------------------------------------------- NAMA ISTRI float[] colomn = { 7, 1, 2 }; PdfPTable tabel9 = new PdfPTable(colomn); tabel9.setWidthPercentage(100); Paragraph pNamaIstriBapakIbu = new Paragraph(); pNamaIstriBapakIbu.add("10."); pNamaIstriBapakIbu.add("\n a. Nama Istri : "); pNamaIstriBapakIbu.add("\n\n b. Nama Bapak Istri : "); pNamaIstriBapakIbu.add("\n\n c. Nama Ibu Istri : "); pNamaIstriBapakIbu.add("\n\n d. Alamat : "); pNamaIstriBapakIbu.setLeading(0, 1); PdfPCell cNamaIstriBapakIbu = new PdfPCell(); cNamaIstriBapakIbu.setMinimumHeight(110); cNamaIstriBapakIbu.addElement(pNamaIstriBapakIbu); tabel9.addCell(cNamaIstriBapakIbu); Paragraph pUmurIstriBapakIbu = new Paragraph(); pUmurIstriBapakIbu.add(" Umur :"); pUmurIstriBapakIbu.setLeading(0, 1); PdfPCell cUmurIstriBapakIbu = new PdfPCell(); cUmurIstriBapakIbu.setMinimumHeight(110); cUmurIstriBapakIbu.addElement(pUmurIstriBapakIbu); tabel9.addCell(cUmurIstriBapakIbu); Paragraph pPekerjaanIstriBapakIbu = new Paragraph(); pPekerjaanIstriBapakIbu.add(" Pekerjaan :"); pPekerjaanIstriBapakIbu.setLeading(0, 1); PdfPCell cPekerjaanIstriBapakIbu = new PdfPCell(); cPekerjaanIstriBapakIbu.setMinimumHeight(110); cPekerjaanIstriBapakIbu.addElement(pPekerjaanIstriBapakIbu); tabel9.addCell(cPekerjaanIstriBapakIbu); document.add(tabel9); //------------------------------------------------------------------------------------- NAMA ISTRI END //------------------------------------------------------------------------------------- SANAK SAUDARA PdfPTable tabel10 = new PdfPTable(colomn); tabel10.setWidthPercentage(100); Paragraph pSanakSaudara = new Paragraph(); pSanakSaudara.add("11. Nama Sanak/Saudara yang menjadi Tanggungan : \n 1.\n 2."); pSanakSaudara.setLeading(0, 1); PdfPCell cSanakSaudara = new PdfPCell(); cSanakSaudara.addElement(pSanakSaudara); tabel10.addCell(cSanakSaudara); Paragraph pSanakSaudara1 = new Paragraph(); pSanakSaudara1.add(""); pSanakSaudara1.setLeading(0, 1); PdfPCell cSanakSaudara1 = new PdfPCell(); cSanakSaudara1.addElement(pSanakSaudara1); tabel10.addCell(cSanakSaudara1); Paragraph pSanakSaudara2 = new Paragraph(); pSanakSaudara2.add(""); pSanakSaudara2.setLeading(0, 1); PdfPCell cSanakSaudara2 = new PdfPCell(); cSanakSaudara2.addElement(pSanakSaudara2); tabel10.addCell(cSanakSaudara2); document.add(tabel10); //------------------------------------------------------------------------------------- SANAK SAUDARA END //------------------------------------------------------------------------------------- ANAK2 PdfPTable tabel11 = new PdfPTable(colomn); tabel11.setWidthPercentage(100); Paragraph pAnak2 = new Paragraph(); pAnak2.add("12. Anak-anak : "); pAnak2.add("\n\n 1. "); pAnak2.add("\n\n 2. "); pAnak2.add("\n\n 3. "); pAnak2.add("\n\n 4. "); pAnak2.add("\n\n 5. "); pAnak2.add("\n\n 6. "); pAnak2.add("\n"); pAnak2.setLeading(0, 1); PdfPCell cAnak2 = new PdfPCell(); cAnak2.setMinimumHeight(165); cAnak2.addElement(pAnak2); tabel11.addCell(cAnak2); Paragraph pUmurAnak2 = new Paragraph(); pUmurAnak2.add(" Umur : "); pUmurAnak2.setLeading(0, 1); PdfPCell cUmurAnak2 = new PdfPCell(); cUmurAnak2.setMinimumHeight(165); cUmurAnak2.addElement(pUmurAnak2); tabel11.addCell(cUmurAnak2); Paragraph pPekarjaanAnak2 = new Paragraph(); pPekarjaanAnak2.add(" Pekerjaan : "); pPekarjaanAnak2.setLeading(0, 1); PdfPCell cPekerjaanAnak2 = new PdfPCell(); cPekerjaanAnak2.setMinimumHeight(165); cPekerjaanAnak2.addElement(pPekarjaanAnak2); tabel11.addCell(cPekerjaanAnak2); document.add(tabel11); //------------------------------------------------------------------------------------- ANAK2 END //------------------------------------------------------------------------------------- CIRI-CIRI PdfPTable tabel12 = new PdfPTable(1); tabel12.setWidthPercentage(100); Paragraph pCiri2 = new Paragraph(); pCiri2.add("13. Ciri-ciri badan : "); pCiri2.add("\n\n 1. Rambut : " + getRambut()); for (int i = 0; i < (35 - getRambut().length()); i++) { pCiri2.add(" "); } pCiri2.add("2. Muka : " + getMuka()); for (int i = 0; i < (35 - getMuka().length()); i++) { pCiri2.add(" "); } pCiri2.add("3. Kulit : " + getKulit()); pCiri2.setLeading(0, 1); PdfPCell cCiri2 = new PdfPCell(); cCiri2.setMinimumHeight(45); cCiri2.addElement(pCiri2); tabel12.addCell(cCiri2); document.add(tabel12); //------------------------------------------------------------------------------------- CIRI-CIRI END //------------------------------------------------------------------------------------- LANJUTAN CIRI2 PdfPTable tabel13 = new PdfPTable(1); tabel13.setWidthPercentage(100); Paragraph pCiri2Lanjutan = new Paragraph(); for (int i = 0; i < 20; i++) { pCiri2Lanjutan.add(" "); } pCiri2Lanjutan.add("4. Tinggi : " + getTinggi()); for (int i = 0; i < (35 - getTinggi().length()); i++) { pCiri2Lanjutan.add(" "); } pCiri2Lanjutan.add("5. Tanda Istimewa : " + getTandaistimewa()); pCiri2Lanjutan.setLeading(0, 1); PdfPCell cCiri2Lanjutan = new PdfPCell(); cCiri2Lanjutan.setMinimumHeight(20); cCiri2Lanjutan.addElement(pCiri2Lanjutan); tabel13.addCell(cCiri2Lanjutan); document.add(tabel13); //------------------------------------------------------------------------------------- LANJUTAN CIRI2 //------------------------------------------------------------------------------------- RUMUS SIDIK JARI PdfPTable tabel14 = new PdfPTable(1); tabel14.setWidthPercentage(100); Paragraph pSidikJari = new Paragraph(); pSidikJari.add("14. Rumus Sidik Jari : " + getRumussidikjari()); pSidikJari.setLeading(0, 1); PdfPCell cSidikJari = new PdfPCell(); cSidikJari.setMinimumHeight(20); cSidikJari.addElement(pSidikJari); tabel14.addCell(cSidikJari); document.add(tabel14); //------------------------------------------------------------------------------------- RUMUS SIDIK JARI END //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH float[] colom = { 8, 2 }; PdfPTable tabel15 = new PdfPTable(colom); tabel15.setWidthPercentage(100); Paragraph pRiwayatSekolah = new Paragraph(); pRiwayatSekolah.add("15. Riwayat Sekolah : "); pRiwayatSekolah.add("\n\n 1. "); pRiwayatSekolah.add("\n\n 2. "); pRiwayatSekolah.add("\n\n 3. "); pRiwayatSekolah.add("\n\n 4. "); pRiwayatSekolah.add("\n\n 5. "); pRiwayatSekolah.add("\n\n 6. "); pRiwayatSekolah.setLeading(0, 1); PdfPCell cRiwayatSekolah = new PdfPCell(); cRiwayatSekolah.setMinimumHeight(165); cRiwayatSekolah.addElement(pRiwayatSekolah); tabel15.addCell(cRiwayatSekolah); Paragraph pTahunLulus = new Paragraph(); pTahunLulus.add("Tahun Lulus"); pTahunLulus.setLeading(0, 1); PdfPCell cTahunLulus = new PdfPCell(); cTahunLulus.setMinimumHeight(165); cTahunLulus.addElement(pTahunLulus); tabel15.addCell(cTahunLulus); document.add(tabel15); //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH END //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI PdfPTable tabel16 = new PdfPTable(1); tabel16.setWidthPercentage(100); Paragraph pKesenenanganKegemaranHobi = new Paragraph(); pKesenenanganKegemaranHobi.add("16. Kesenangan/Kegemaran/Hobi : " + getHobi()); pKesenenanganKegemaranHobi.setLeading(0, 1); PdfPCell cKesenenanganKegemaranHobi = new PdfPCell(); cKesenenanganKegemaranHobi.setMinimumHeight(20); cKesenenanganKegemaranHobi.addElement(pKesenenanganKegemaranHobi); tabel16.addCell(cKesenenanganKegemaranHobi); document.add(tabel16); //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI END //------------------------------------------------------------------------------------- CATATAN KRIMINAL PdfPTable tabel17 = new PdfPTable(1); tabel17.setWidthPercentage(100); Paragraph pCatatanKriminal = new Paragraph(); pCatatanKriminal.add("17. Catatan kriminal yang ada : "); pCatatanKriminal.add("\n\n 1. " + getCatatankriminal1()); pCatatanKriminal.add("\n\n 2. " + getCatatankriminal2()); pCatatanKriminal.add("\n\n 3. " + getCatatankriminal3()); pCatatanKriminal.setLeading(0, 1); PdfPCell cCatatanKriminal = new PdfPCell(); cCatatanKriminal.setMinimumHeight(95); cCatatanKriminal.addElement(pCatatanKriminal); tabel17.addCell(cCatatanKriminal); document.add(tabel17); //------------------------------------------------------------------------------------- CATATAN KRIMINAL END //------------------------------------------------------------------------------------- KETERANGAN DLL PdfPTable tabel18 = new PdfPTable(1); tabel18.setWidthPercentage(100); Paragraph pDataKeteranganLain2 = new Paragraph(); pDataKeteranganLain2.add("18. Data Keterangan dan lain2 : "); pDataKeteranganLain2.add("\n\n\n"); pDataKeteranganLain2.setLeading(0, 1); PdfPCell cDataKeteranganLain2 = new PdfPCell(); cDataKeteranganLain2.addElement(pDataKeteranganLain2); if (list.size() > 0) { float[] kolomkegiatan = { 8, 2 }; PdfPTable nestedTable = new PdfPTable(kolomkegiatan); nestedTable.addCell(new Paragraph("Kegiatan")); nestedTable.addCell(new Paragraph("Tanggal")); for (int i = 0; i < list.size(); i++) { nestedTable.addCell(new Paragraph(list.get(i).getNamakegiatan())); nestedTable.addCell(new Paragraph(list.get(i).getTanggal())); } cDataKeteranganLain2.addElement(nestedTable); cDataKeteranganLain2.setPaddingBottom(20f); tabel18.addCell(cDataKeteranganLain2); } document.add(tabel18); //------------------------------------------------------------------------------------- KETERANGAN DLL END document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return output; }
From source file:servlet.PdfGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w .ja v a 2 s . c om*/ * * @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 { Document report = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(report, baos); DBManager manager = (DBManager) getServletContext().getAttribute("dbmanager"); Group groupToReport = manager.getGroup(Integer.parseInt(request.getParameter("id"))); LinkedList<User> groupUsers = manager.getUsersForGroupAndVisible(groupToReport.getId()); Timestamp lastPosted = manager.getLatestPost(groupToReport); int numberOfPosts = manager.getGroupPosts(groupToReport).size(); String context = request.getServletContext().getRealPath("/"); Iterator<User> groupIterator = groupUsers.iterator(); report.open(); // INSERTING DOCUMENT CONTENT AREA Font title = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 24); Font text = FontFactory.getFont(FontFactory.HELVETICA, 12); Paragraph documentHead = new Paragraph(groupToReport.getName(), title); Paragraph newLine = new Paragraph(Chunk.NEWLINE); Paragraph latestPost = new Paragraph("Latest post inserted on: " + lastPosted, text); Paragraph postsNumberToReport = new Paragraph("Number of posts: " + numberOfPosts, text); //LAYOUT AND FINAL PARAGRAPH EDITING AREA report.add(documentHead); report.add(newLine); report.add(postsNumberToReport); report.add(newLine); report.add(latestPost); report.add(newLine); PdfPTable usersTable = new PdfPTable(5); // LOOP FOR SETTING TABLE while (groupIterator.hasNext()) { User u = groupIterator.next(); String userName = u.getName(); PdfPCell avatarCell = new PdfPCell(Image.getInstance(context + u.getAvatar(request))); avatarCell.setBorder(0); avatarCell.setPaddingBottom(10); avatarCell.setColspan(1); PdfPCell userNameCell = new PdfPCell(new Phrase(userName)); userNameCell.setColspan(4); userNameCell.setBorder(0); userNameCell.setPaddingBottom(10); userNameCell.setPaddingLeft(10); usersTable.addCell(avatarCell); usersTable.addCell(userNameCell); } usersTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); report.add(usersTable); report.close(); // SETTING SOME RESPONSE HEADER response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // SETTING THE CONTENT TYPE response.setContentType("application/pdf"); // THE CONTENTLENGHT response.setContentLength(baos.size()); System.out.println("ci sono"); try (OutputStream os = response.getOutputStream()) { baos.writeTo(os); os.flush(); os.close(); } catch (Exception e) { throw new IOException(e.getMessage()); } } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:Servlets.GenerarPinesGrupo.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] idEstudiante = req.getParameterValues("imprimir"); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {//from w ww. j ava 2 s.c o m try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); for (int i = 0; i < idEstudiante.length; i++) { int idEst = Integer.parseInt(idEstudiante[i]); Pin estudiante = controlador.pinEstudiante(idEst); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell( new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); } documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:Servlets.GenerarPinEstudiante.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int idEstudiante = Integer.parseInt(req.getParameter("idEst")); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {//from w ww .jav a 2 s. com try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); Pin estudiante = controlador.pinEstudiante(idEstudiante); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell(new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:Servlets.PDF.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {//from w w w. j a v a 2 s .c o m //obtengo datos de cliente, reserva y total String rreserva = request.getParameter("reserva"); String rcliente = request.getParameter("cliente"); String rtotal = request.getParameter("total"); //String rtipo = request.getParameter("esProv"); // Obtener datos de cliente e items de reserva DtUsuario dtu = getDtUsuario(rcliente); String nombre = dtu.getNombre(); String apellido = dtu.getApellido(); String servicios = ""; String promos = ""; java.util.List<DtItemReserva> dtItems = listarItems(Integer.parseInt(rreserva)).getItems(); Iterator<DtItemReserva> iter = dtItems.iterator(); DtItemReserva dtItem; // Crear y abrir documento String HomeDeUSuario = System.getProperty("user.home"); String ruta = HomeDeUSuario + "/Factura Reserva " + rreserva + ".pdf"; FileOutputStream archivo = new FileOutputStream(ruta); PdfWriter writer = PdfWriter.getInstance(document, archivo); document.open(); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); String fecha = dateFormat.format(date); // Agregar marcador inicial // Crear y agregar prrafo simple Paragraph paragraph1 = new Paragraph(); Image imagen = Image.getInstance("http://localhost:8084/Help4TravelingWeb/img/logo-icon2.png"); imagen.scaleAbsolute(200f, 200f); imagen.setAbsolutePosition(10, 650); imagen.setSpacingAfter(20); paragraph1.add(imagen); document.add(paragraph1); //fecha Paragraph fecha1 = new Paragraph(fecha); //encabezado Paragraph futuros = new Paragraph("Futuros Tecnologos SRL"); Paragraph rut = new Paragraph("RUT 123456789012"); Paragraph direccion = new Paragraph(" Av. Gral. Rivera 3629"); Paragraph telefono = new Paragraph(" Tel: 555-5412"); Paragraph nombre_empresa = new Paragraph(" Help4Travelling"); //datos cliente String nombrecliente = nombre.toUpperCase() + " " + apellido.toUpperCase(); String direccioncliente = " "; String rutcliente = "consumidor final".toUpperCase(); Paragraph cliente = new Paragraph("Cliente: " + nombrecliente); Paragraph dircliente = new Paragraph("Direccion: " + direccioncliente); Paragraph rutcli = new Paragraph("RUT: " + rutcliente); //datos boleta String factura = rreserva; Paragraph tipodoc = new Paragraph("Contado"); Paragraph Nfac = new Paragraph(" N " + factura); //alineaciones //fecha fecha1.setAlignment(Element.ALIGN_RIGHT); //encabezado futuros.setAlignment(Element.ALIGN_CENTER); rut.setAlignment(Element.ALIGN_CENTER); direccion.setAlignment(Element.ALIGN_CENTER); telefono.setAlignment(Element.ALIGN_CENTER); //nombre empresa nombre_empresa.setAlignment(Element.ALIGN_LEFT); nombre_empresa.setSpacingBefore(10); nombre_empresa.setSpacingAfter(30); //datos de boleta tipodoc.setAlignment(Element.ALIGN_RIGHT); Nfac.setAlignment(Element.ALIGN_RIGHT); document.add(fecha1); document.add(futuros); document.add(rut); document.add(direccion); document.add(telefono); document.add(nombre_empresa); document.add(tipodoc); document.add(Nfac); document.add(cliente); document.add(dircliente); document.add(rutcli); PdfPTable tabla = new PdfPTable(4); tabla.setSpacingBefore(25); tabla.setSpacingAfter(25); //creo encabezado de tabla PdfPCell codigo = new PdfPCell(new Phrase("Proveedor".toUpperCase())); PdfPCell descripcion = new PdfPCell(new Phrase("descripcion".toUpperCase())); PdfPCell ecantidad = new PdfPCell(new Phrase("cantidad".toUpperCase())); PdfPCell eprecio = new PdfPCell(new Phrase("precio".toUpperCase())); tabla.setHeaderRows(1); tabla.setWidthPercentage(100f); //alineamos las frases del cabezal codigo.setHorizontalAlignment(Element.ALIGN_CENTER); descripcion.setHorizontalAlignment(Element.ALIGN_CENTER); ecantidad.setHorizontalAlignment(Element.ALIGN_CENTER); eprecio.setHorizontalAlignment(Element.ALIGN_CENTER); //agrego cabezal de tabla tabla.addCell(codigo); tabla.addCell(descripcion); tabla.addCell(ecantidad); tabla.addCell(eprecio); //obtengo datos de la reserva para imprimir las distintas rows while (iter.hasNext()) { dtItem = iter.next(); Integer cantidad = dtItem.getCantidad(); String oferta = dtItem.getOferta().getNombre(); String precio; String proveedor; if (existeServicio(oferta)) { proveedor = getNkProveedorServicio(oferta); DtServicio dts = getDtServicio(oferta, proveedor); precio = String.valueOf(dts.getPrecio()); } else { proveedor = getNkProveedorPromocion(oferta); DtPromocion dtp = getDTPromocion(oferta, proveedor); precio = dtp.getDescuento(); } /* String item = "<li>Nombre: <em>" + oferta + "</em>" + " - Cantidad: <em>" + cantidad + "</em>" + " - $:<em>" + precio + "</em>" + " - Proveedor: <em>" + proveedor + "</em></li>";*/ //creo encabezado de tabla PdfPCell iproveedor = new PdfPCell(new Phrase(proveedor.toUpperCase())); PdfPCell icantidad = new PdfPCell(new Phrase(cantidad.toString())); PdfPCell iprecio = new PdfPCell(new Phrase(precio.toUpperCase())); tabla.setHeaderRows(1); //alineamos las frases del cabezal iproveedor.setHorizontalAlignment(Element.ALIGN_CENTER); icantidad.setHorizontalAlignment(Element.ALIGN_CENTER); iprecio.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(iproveedor); if (existeServicio(oferta)) { PdfPCell idescripcion = new PdfPCell(new Phrase("servicio: " + oferta)); idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(idescripcion); } else { PdfPCell idescripcion = new PdfPCell(new Phrase("Promo: " + oferta)); idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(idescripcion); } tabla.addCell(icantidad); tabla.addCell(iprecio); } /* // las distintas rows de los articulos tabla.addCell(proveedor); tabla.addCell(oferta); tabla.addCell(cantidad); tabla.addCell(precio); */ //el ulimo de la tabla que da el total PdfPCell celdaFinal = new PdfPCell(new Paragraph("")); PdfPCell celdaTotal = new PdfPCell(new Paragraph("total:")); PdfPCell celdaPrecioTotal = new PdfPCell(new Paragraph(rtotal)); // Indicamos cuantas columnas ocupa la celda celdaFinal.setColspan(2); celdaTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); celdaPrecioTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celdaFinal); tabla.addCell(celdaTotal); tabla.addCell(celdaPrecioTotal); document.add(tabla); document.close(); if (request.getParameter("dispositivo").equals("true")) response.sendRedirect("Movil.Reservas.jsp"); else response.sendRedirect("Usuario.jsp"); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:servlets.POPDF.java
private void buildpdf(PurchaseOrderDTO dto, HttpServletResponse response) { Font catFont = new Font(Font.FontFamily.HELVETICA, 24, Font.BOLD); Font subFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); Font smallBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); String IMG = getServletContext().getRealPath("/img/logo.png"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(); VendorDTO venDTO = venModel.getVendor(dto.getVendorno(), ds); DecimalFormat decimal = new DecimalFormat("#0.00"); ArrayList<ProductDTO> products = prodModel.getProdsForVendor(dto.getVendorno(), ds); ArrayList<POLineItemDTO> poLineItems = dto.getItems(); try {/* w ww . j ava2 s .c o m*/ PdfWriter.getInstance(document, baos); document.open(); Paragraph preface = new Paragraph(); // We add one empty line Image image1 = Image.getInstance(IMG); image1.setAbsolutePosition(55f, 760f); preface.add(image1); preface.setAlignment(Element.ALIGN_RIGHT); // Lets write a big header Paragraph mainHead = new Paragraph(String.format("%55s", "Purchase Order"), catFont); preface.add(mainHead); preface.setAlignment(Element.ALIGN_LEFT); preface.add(new Paragraph(String.format("%82s", "PO#: " + dto.getPONumber()), subFont)); addEmptyLine(preface, 3); preface.add(new Paragraph(String.format("%10s", "Vendor: ", smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getName(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getAddress1(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getCity(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getProvince(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getPostalCode(), smallBold))); addEmptyLine(preface, 1); // 3 column table PdfPTable table = new PdfPTable(5); PdfPCell cell = new PdfPCell(new Paragraph("Product Code", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Product Description", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Quantity Sold", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Price", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Ext Price", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); for (POLineItemDTO item : poLineItems) { cell = new PdfPCell(new Phrase(item.getproductcode())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); for (ProductDTO prod : products) { if (prod.getProductcode().equals(item.getproductcode())) { cell = new PdfPCell(new Phrase(prod.getProductname())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } cell = new PdfPCell(new Phrase(Integer.toString(item.getQuantity()))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); double extPrice = 0.0; for (ProductDTO prod : products) { if (prod.getProductcode().equals(item.getproductcode())) { cell = new PdfPCell(new Phrase(Double.toString(prod.getCostprice()))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); extPrice = prod.getCostprice() * item.getQuantity(); } } String extPriceStr = decimal.format(extPrice); cell = new PdfPCell(new Phrase(extPriceStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } //end for double sub = dto.getAmount(); double tax = dto.getAmount() * 0.13; double total = dto.getAmount() * 1.13; String taxStr = decimal.format(tax); String totalStr = decimal.format(total); String subStr = decimal.format(sub); cell = new PdfPCell(new Phrase("Total:")); cell.setColspan(4); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase(subStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase("Tax:")); cell.setColspan(4); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase(taxStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell = new PdfPCell(new Phrase("Order Total:")); cell.setColspan(4); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(BaseColor.YELLOW); table.addCell(cell); preface.add(table); addEmptyLine(preface, 3); preface.setAlignment(Element.ALIGN_CENTER); preface.add(new Paragraph(String.format("%60s", "Generated on: " + dto.getPODate()), subFont)); document.add(preface); document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (Exception e) { System.out.println("Error " + e.getMessage()); } }
From source file:servlets.POServlet.java
private PdfPCell GenerateBorderlessCell(String title, int colspan, int alignment) { PdfPCell cell = new PdfPCell(new Phrase(title)); cell.setColspan(colspan); cell.setBorder(0);//w w w . j a v a2 s .co m cell.setHorizontalAlignment(alignment); return cell; }
From source file:Servlets.ReportsServlet.java
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align);/*from w w w . ja va2 s .c o m*/ //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); //Set padding cell.setPadding(3f); //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table table.addCell(cell); }
From source file:Servlets.ReportsServlet.java
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font, float bord[]) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align);/* www . ja v a 2s. c om*/ //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); //Set padding cell.setPadding(3f); //Setting cell Borders // cell.setBorderWidth(3f); // sets border width to 3 units cell.setBorderWidthLeft(bord[0]); cell.setBorderWidthRight(bord[1]); cell.setBorderWidthTop(bord[2]); cell.setBorderWidthBottom(bord[3]); //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table table.addCell(cell); }