List of usage examples for com.itextpdf.text Chunk NEWLINE
Chunk NEWLINE
To view the source code for com.itextpdf.text Chunk NEWLINE.
Click Source Link
From source file:GUI_StafKlinik.Panel_Penggajian.java
private Paragraph getPreface(String status) { lk = new Laporan_Keuangan(); Paragraph preface = new Paragraph(); Calendar cal = new GregorianCalendar(); String tanggal = "0"; if (cal.get(Calendar.DATE) < 0) { tanggal = "0" + cal.get(Calendar.DATE); } else {/* w ww.ja v a 2 s.c o m*/ tanggal = "" + cal.get(Calendar.DATE); } int bulan = (cal.get(Calendar.MONTH)) + 1; ; int tahun = cal.get(Calendar.YEAR); String id1 = lk.getId(); String id2 = p.getIdPegawai(); String id = id = id1 + id2; preface.setAlignment(Element.ALIGN_CENTER); Chunk chunk = new Chunk("Slip Gaji", font2); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("SI Klinik", font2); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("Jalan Pahlawan 45 Surabaya", font1); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("Telepon : 031 7564231", font1); preface.add(Chunk.NEWLINE); preface.add(chunk); preface.add(Chunk.NEWLINE); preface.add(Chunk.NEWLINE); preface.setAlignment(Element.ALIGN_RIGHT); chunk = new Chunk("Tanggal " + tanggal + "/" + bulan + "/" + tahun, font1); preface.add(Chunk.NEWLINE); preface.add(chunk); chunk = new Chunk("No. Referensi :" + id, font1); preface.add(Chunk.NEWLINE); preface.add(chunk); return preface; }
From source file:IAS.Class.BackIssueLabels.java
public Paragraph prepareBILLabelPDFContent(subInfo sLabelInfo, String bilLabel) { Paragraph info = null;/*from w w w .jav a 2s .co m*/ info = new Paragraph(); info.setLeading(lfixedLeading, lmultipliedLeadingPlus); info.setAlignment(textAlignment); Font font; font = new Font(sfontType, sfontSizeHeader - 1, sfontStyle, BaseColor.BLACK); if (!bilLabel.isEmpty() && !sLabelInfo.getsubscriberNumber().isEmpty()) { String header = sLabelInfo.getsubscriberNumber() + " " + bilLabel; info.add(new Chunk(header, font)); info.add(Chunk.NEWLINE); } font = new Font(sfontType, sfontSize, sfontStyle, BaseColor.BLACK); String firstLine = sLabelInfo.getsubscriberName(); // + " " + sLabelInfo.getjournalCode(); //if(!noHeader){ //if(sLabelInfo.getcopies() > 1){ // firstLine = firstLine + " " + sLabelInfo.getcopies(); //} //firstLine = firstLine + " " + sLabelInfo.getsubtypecode(); //if(sLabelInfo.equals("Paid")) { // firstLine = firstLine + " " + sLabelInfo.getstartDate()+ // " " + "to" + // " " + sLabelInfo.getendDate(); //} if (!firstLine.isEmpty()) { info.add(new Chunk(firstLine, font)); info.add(Chunk.NEWLINE); } //} //info.add(new Chunk(sLabelInfo.getsubscriberName(), font)); //info.add(Chunk.NEWLINE); if (!sLabelInfo.getdepartment().isEmpty()) { info.add(new Chunk(sLabelInfo.getdepartment(), font)); info.add(Chunk.NEWLINE); } if (!sLabelInfo.getinstitution().isEmpty()) { info.add(new Chunk(sLabelInfo.getinstitution(), font)); info.add(Chunk.NEWLINE); } if (!sLabelInfo.getaddress().isEmpty()) { info.add(new Chunk(sLabelInfo.getaddress(), font)); info.add(Chunk.NEWLINE); } font = new Font(sfontType, sfontSize, Font.BOLD); /* String lastLine = sLabelInfo.getcity() + " " + sLabelInfo.getpincode() + " " + sLabelInfo.getstate() + " "; if(!sLabelInfo.getcountry().equals("India")){ lastLine = lastLine + sLabelInfo.getcountry(); } */ String lastLine = ""; if (!sLabelInfo.getcity().isEmpty()) { lastLine = lastLine + sLabelInfo.getcity(); } if (sLabelInfo.getcity().isEmpty()) { lastLine = lastLine + sLabelInfo.getpincode(); } else { lastLine = lastLine + " " + sLabelInfo.getpincode(); } if (sLabelInfo.getpincode().isEmpty()) { lastLine = lastLine + sLabelInfo.getstate(); } else { lastLine = lastLine + " " + sLabelInfo.getstate(); } String country = ""; if (!sLabelInfo.getcountry().equals("India")) { country = sLabelInfo.getcountry(); } if (sLabelInfo.getstate().isEmpty()) { lastLine = lastLine + country; } else { lastLine = lastLine + " " + country; } if (!lastLine.isEmpty()) { lastLine = lastLine.trim(); // Remove the leading spaces //lastLine.replaceAll("^\\s+", ""); info.add(new Chunk(lastLine, font)); } return info; }
From source file:ictproject.ReportGenerator.java
public void writer(String selected) { // if (!folderForPDF.exists()) { // if (folderForPDF.mkdir()) { // System.out.println("Directory is created!"); // } else { // System.out.println("Failed to create directory!"); // }// w ww.j ava 2 s . co m // } Document document = new Document(PageSize.A4); try { String path = "E:/" + selected + ".pdf"; com.itextpdf.text.pdf.PdfWriter.getInstance(document, new FileOutputStream(path)); document.open(); Paragraph para = getParagraph(selected, "gulmi"); document.add(para); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(getParagraph(selected, "janajatiAnusar")); document.add(janajatiAnusar(selected)); document.add(getParagraph(selected, "pani ko sroth")); document.add(getPaniKoSroth(selected)); document.newPage(); document.add(getParagraph(selected, "name")); document.add(getParagraph(selected, "actual budget")); document.add(actualBudget(selected, "actualBudget")); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(getParagraph(selected, "expected budget")); document.add(actualBudget(selected, "expectedBudget")); document.setPageSize(PageSize.A4.rotate()); document.newPage(); document.add(getParagraph(selected, "name")); document.add(getParagraph(selected, "sauchalayKoAwasta")); document.add(sauchalayKoAwasta(selected)); document.newPage(); document.add(getParagraph(selected, "name")); document.add(getParagraph(selected, "pani janya rog ko bibaran")); document.add(rogKoBibaran(selected)); document.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("error" + e.getMessage()); ErrorPopup errorPopup = new ErrorPopup(e.getMessage()); errorPopup.setVisible(true); errorPopup.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } }
From source file:ictproject.ReportGenerator.java
private Paragraph getParagraph(String name, String type) { Paragraph paragraph = new Paragraph(); paragraph.setSpacingAfter(10);/* ww w.jav a2 s .c o m*/ switch (type) { case "pani ko sroth": { Paragraph para1 = new Paragraph("@= ljBfdfg kfgLsf >f]tx?sf] cj:yfM", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); paragraph.add(para1); break; } case "pani janya rog ko bibaran": { Paragraph para1 = new Paragraph("%= kfgLhGo /f]ux?sf] ljj/0f M", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para3 = new Paragraph( "uflj;:t/Lo kfgLhGo /f]ux?sf] ljj/0f :jf:Yo rf}sLaf6 jf dlxnf ;jo+;]ljsf af6 lng]", fontNormal); paragraph.add(para1); break; } case "actual budget": { Paragraph para1 = new Paragraph( "# -s_ ut tLg jif{sf nflu uflj;n] vfg]kfgL tyf ;/;kmfO If]qdf 5'6fPsf] jh]6 ljj/0fM", fontNormal); // Paragraph para3=new Paragraph("uflj;sf] hDdf ;Defljt nufgL ? ",fontNormal); // Paragraph para4=new Paragraph(getDistinctResult(name, "gabisaKoLagani", "actualBudget")); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para5 = new Paragraph(); para5.add(new Chunk("uflj;sf] hDdf ;Defljt nufgL ? ", fontNormal)); para5.add(getDistinctResult(name, "gabisaKoLagani", "actualBudget")); paragraph.add(para1); paragraph.add(para5); break; } case "expected budget": { Paragraph para1 = new Paragraph( "# -v_ cfufdL # jif{sf nflu uflj;sf] vfg]kfgL tyf ;/;kmfO If]qdf x'g ;Sg] ;Defljt ah]6M", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para5 = new Paragraph(); para5.add(new Chunk("uflj;sf] hDdf ;Defljt nufgL ? ", fontNormal)); para5.add(getDistinctResult(name, "gabisaKoLagani", "expectedBudget")); paragraph.add(para1); paragraph.add(para5); break; } case "janajatiAnusar": { Paragraph para2 = new Paragraph("uflj;sf] gfdMM" + converter(name), fontNormal); para2.setIndentationLeft(50); Paragraph para1 = new Paragraph("!= hfthftL cg';f/sf] 3/w'/L ljj/0fM", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); paragraph.add(para2); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); paragraph.add(para1); break; } case "sauchalayKoAwasta": { Paragraph para1 = new Paragraph("$= zf}rfnosf] cj:yf M", fontNormal);//. ? ",fontNormal); para1.setAlignment(Element.ALIGN_CENTER); paragraph.add(para1); break; } case "gulmi": { Paragraph para = new Paragraph(); Paragraph para1 = new Paragraph("lhNnf ljsf; ;ldltsf] sfof{no", fontNormal); para1.setAlignment(Element.ALIGN_CENTER); Paragraph para3 = new Paragraph("u'NdL", fontNormal); para3.setAlignment(Element.ALIGN_CENTER); Paragraph para4 = new Paragraph("vfg]kfgL tyf ;/;kmfO OsfO{", fontNormal); para4.setAlignment(Element.ALIGN_CENTER); para.add(para1); para.add(para3); para.add(para4); return para; } case "name": { Paragraph para = new Paragraph(converter(name), fontNormal); para.setAlignment(Element.ALIGN_CENTER); return para; } } return paragraph; }
From source file:Inventario.Inventario2.java
public void createDocument(String filename, String extension) throws DocumentException, FileNotFoundException { try {//www. j a v a 2 s.c om Document document = new Document(PageSize.LETTER, 50, 50, 85, 50); document.addAuthor("Inventario"); document.addTitle("Reporte de Inventario Compra-Venta"); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setInitialLeading(16); Rectangle rct = new Rectangle(80, 104, 500, 688); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); Paragraph parrafo2 = new Paragraph("Reportes de Inventario", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.GRAY)); parrafo2.setAlignment(0); document.add(parrafo2); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:MailSender.PDF.java
public void createInvoice(ArrayList<Guest> guestarray, Reservation res, String roomType, int roomPrice) throws DocumentException, IOException { filePath = "Invoice" + guestarray.get(0).getReservationNo() + ".pdf"; // step 1//w ww . j a va 2 s.c o m String firstName = guestarray.get(0).getGuestFirstName(); String lastName = guestarray.get(0).getGuestFamilyName(); int deposit = roomPrice / 2; DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy"); Document document = new Document(); System.out.println("document"); // step 2 FileOutputStream fos = new FileOutputStream(filePath); PdfWriter.getInstance(document, fos); System.out.println("fos"); // step 3 document.open(); // step 4 Font font = FontFactory.getFont("Times-Roman", 18); Font fontbold = FontFactory.getFont("Times-Roman", 34, Font.BOLD); document.add(new Paragraph("Invoice", fontbold)); document.add(new Paragraph(" Casablanca Holiday Centre", font)); document.add(new Paragraph(" " + c.getTime(), font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Dear " + firstName + " " + lastName + ",", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("thank you for your reservation.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("++++++Reservation details+++++++", font)); document.add(new Paragraph( "Name: " + guestarray.get(0).getGuestFirstName() + " " + guestarray.get(0).getGuestFamilyName(), font)); document.add(new Paragraph("From: " + dateFormat.format(res.getFromDate()), font)); document.add(new Paragraph("To: " + dateFormat.format(res.getEndDate()), font)); document.add(new Paragraph("Room type: " + roomType, font)); document.add(new Paragraph("++++++++++++++++++++++++++++++++", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Please place the deposit in our follwing bank account in 5 days.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Deposit ammount: " + deposit + " USD", font)); document.add(new Paragraph("Bank account: xxxx xxxx xxxx", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Please read our cancel rule mentioned in the next page", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Regards,", font)); document.add(new Paragraph("CasaBlanca Hotel Resort", font)); document.add(new Paragraph(Chunk.NEXTPAGE)); document.add(new Paragraph("The deposit and rules of cancellations", fontbold)); document.add(new Paragraph(Chunk.NEWLINE)); document.add( new Paragraph("The deposit must be paid at the latest 5 days after receiving the invoice.", font)); document.add(new Paragraph( "The deposit is half the bill. If deposit is not received by the centre within this deadline the booking will be cancelled.", font)); document.add(new Paragraph( "In case of cancellation your deposit will be refunded after deducting the cancellation fees as follows.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("2 weeks before the date of arrival: the deposit will be refunded", font)); document.add(new Paragraph("1 week before the date of arrival: the deposit will be refunded", font)); document.add(new Paragraph("Less than a week no deposit is refunded.", font)); // step 5 document.close(); System.out.println("closed"); }
From source file:MailSender.PDF.java
public void createConfirmation(ArrayList<Guest> guestarray, Reservation res, String roomType) throws DocumentException, IOException { filePath = "Confirmation" + guestarray.get(0).getReservationNo() + ".pdf"; // step 1/*from w w w. j a v a 2s .co m*/ String firstName = guestarray.get(0).getGuestFirstName(); String lastName = guestarray.get(0).getGuestFamilyName(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy"); Document document = new Document(); System.out.println("document"); // step 2 FileOutputStream fos = new FileOutputStream(filePath); PdfWriter.getInstance(document, fos); System.out.println("fos"); // step 3 document.open(); // step 4 Font font = FontFactory.getFont("Times-Roman", 14); Font fontbold = FontFactory.getFont("Times-Roman", 30, Font.BOLD); document.add(new Paragraph("Confirmation", fontbold)); document.add(new Paragraph( " Casablanca Holiday Centre", font)); document.add(new Paragraph( " " + dateFormat.format(c.getTime()), font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Dear " + firstName + " " + lastName + ",", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("thank you for your reservation.", font)); //document.add(new Paragraph("Please print out and bring this confirmation.", font)); //document.add(new Paragraph("You will need password shown in guest details below for booking sport facilities.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("++++++Reservation details+++++++", font)); document.add(new Paragraph("From: " + dateFormat.format(res.getFromDate()), font)); document.add(new Paragraph("To: " + dateFormat.format(res.getEndDate()), font)); document.add(new Paragraph("Room type: " + roomType, font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("++++++Guest details+++++++", font)); document.add(new Paragraph(toStringForPDF(guestarray), font)); document.add(new Paragraph("+++++++++++++++++++++++++++++++++", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("We are looking forward to seeing you.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Regards,", font)); document.add(new Paragraph("CasaBlanca Hotel Resort", font)); // step 5 document.close(); System.out.println("closed"); }
From source file:managedBeans.FichaBean.java
public void printFicha() { try {/*from w w w . j av a2 s . c o m*/ ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest) context.getRequest(); Aluno aluno = (Aluno) request.getSession().getAttribute("user"); Ficha fichaEscolhida = getFichaFromString(); List<Exercicios> exercicios = FichaDAO.getAllExercicios(fichaEscolhida); String filePath = System.getProperty("user.home") + "\\Desktop\\ficha" + aluno.getNome() + " " + fichaEscolhida.getDescricao() + ".pdf"; try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); pdfWriter.addTitlePage(document, fichaEscolhida.getDescricao(), aluno.getNome()); document.add(Chunk.NEWLINE); pdfWriter.createTableExercicios(document, exercicios); document.close(); File file = new File(filePath); HttpServletResponse response = (HttpServletResponse) context.getResponse(); response.reset(); response.setHeader("Content-Disposition", "attachment;filename=Ficha.pdf"); response.setContentLength((int) file.length()); ServletOutputStream out = null; try { FileInputStream input = new FileInputStream(file); byte[] buffer = new byte[1024]; out = response.getOutputStream(); int i = 0; while ((i = input.read(buffer)) != -1) { out.write(buffer); out.flush(); } FacesContext.getCurrentInstance().getResponseComplete(); } catch (IOException err) { err.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException err) { err.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { } }
From source file:managedBeans.ListarAlunosBean.java
public void printToPDF() { ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest) context.getRequest(); Professor professor = (Professor) request.getSession().getAttribute("user"); String filePath = System.getProperty("user.home") + "\\Desktop\\ficha" + professor.getNome() + ".pdf"; try {//w w w. j av a 2s . c o m Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); pdfWriter.addTitlePageProfessor(document, "Lista de alunos do professor " + professor.getNome(), professor.getNome()); document.add(Chunk.NEWLINE); pdfWriter.createTableAlunos(document, listaAlunos); document.close(); File file = new File(filePath); HttpServletResponse response = (HttpServletResponse) context.getResponse(); response.reset(); response.setHeader("Content-Disposition", "attachment;filename=Alunos.pdf"); response.setContentLength((int) file.length()); ServletOutputStream out = null; try { FileInputStream input = new FileInputStream(file); byte[] buffer = new byte[1024]; out = response.getOutputStream(); int i = 0; while ((i = input.read(buffer)) != -1) { out.write(buffer); out.flush(); } FacesContext.getCurrentInstance().getResponseComplete(); } catch (IOException err) { err.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException err) { err.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:managedBeans.ProfessorFichaBean.java
public void printFicha(String fichaSelecionada, String alunoSelecionado) { /*if(fichaSelecionada==null|| alunoSelecionado==null || fichaSelecionada.equals("Selecione a ficha") || alunoSelecionado.equals("Selecione um aluno")){ AlertClass.redirecionaMsg("Erro, selecione uma ficha vlida!", "../faces/professorVerFicha.xhtml"); }*//*from w w w . j av a 2s .c o m*/ try { ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest) context.getRequest(); Professor professor = (Professor) request.getSession().getAttribute("user"); Aluno aluno = getAlunoFromString(alunoSelecionado); Ficha fichaEscolhida = getFichaFromString(fichaSelecionada); System.out.println("Ficha " + fichaEscolhida + "Aluno " + aluno); List<Exercicios> exercicios = FichaDAO.getAllExercicios(fichaEscolhida); String filePath = System.getProperty("user.home") + "\\Desktop\\ficha" + professor.getNome() + " " + fichaEscolhida.getDescricao() + ".pdf"; try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); pdfWriter.addTitlePage(document, fichaEscolhida.getDescricao(), profUser.getNome()); document.add(Chunk.NEWLINE); pdfWriter.createTableExercicios(document, exercicios); document.close(); File file = new File(filePath); HttpServletResponse response = (HttpServletResponse) context.getResponse(); response.reset(); response.setHeader("Content-Disposition", "attachment;filename=Ficha.pdf"); response.setContentLength((int) file.length()); ServletOutputStream out = null; try { FileInputStream input = new FileInputStream(file); byte[] buffer = new byte[1024]; out = response.getOutputStream(); int i = 0; while ((i = input.read(buffer)) != -1) { out.write(buffer); out.flush(); } FacesContext.getCurrentInstance().getResponseComplete(); } catch (IOException err) { err.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException err) { err.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } setAlunoSelecionado(null); setFichaSelecionada(null); }