List of usage examples for com.itextpdf.text Document close
boolean close
To view the source code for com.itextpdf.text Document close.
Click Source Link
From source file:bicimotos3hermanos.MainFrom.java
public void toPFD(String out, String in) { try {// ww w.j a v a 2 s.co m //Create Document Object Document convertJpgToPdf = new Document(); //Create PdfWriter for Document to hold physical file PdfWriter.getInstance(convertJpgToPdf, new FileOutputStream(out));//"c:\\java\\ConvertImagetoPDF.pdf" convertJpgToPdf.open(); //Get the input image to Convert to PDF Image convertJpg = Image.getInstance(in); convertJpg.setAbsolutePosition(0f, 260f);//posicion en x,y convertJpg.scalePercent(72, 85);//porcentaje en escala //Add image to Document convertJpgToPdf.add(convertJpg); //Close Document convertJpgToPdf.close(); System.out.println("Successfully Converted JPG to PDF in iText"); } catch (Exception i1) { i1.printStackTrace(); } }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;/*from w w w.ja v a2 s . c om*/ try { Stage gg = ((Stage) imv.getParent().getScene().getWindow()); fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf"); fi.deleteOnExit(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fi)); Rectangle r = new RectangleReadOnly(207, 575); document.setPageSize(r); document.setMargins(15, 15, 0, 0); document.open(); Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL); Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL); String[] ll = Database.getCurrentSettings(); String ss = "-----------------------------------------------------\n"; ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n"; String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM" : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : ""); ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH)) + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at " + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + " " + kk + "\n"; ss += "Table No. " + c.getText() + " Bill No. " + a.getText() + "\n"; ss += "-----------------------------------------------------\n"; Paragraph para = new Paragraph(ss, fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); float[] columnWidths = { 3f, 1f }; table.setWidths(columnWidths); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); ObservableList ob = map.get(Integer.parseInt(gg.getTitle())); for (int i = 0; i < ob.size(); i++) { Item2 ii = (Item2) ob.get(i); String s1 = ii.getQuantity() + " x " + ii.getName(); String s2 = "Rs. " + ii.getTotal(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(columnWidths); defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); String s1 = "Total:"; String s2 = "Rs. " + h.getText(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) { s1 = "Discount:"; s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText())); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[7].equals("1")) { s1 = ll[3]; s2 = "Rs. " + k.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[8].equals("1")) { s1 = ll[4]; s2 = "Rs. " + l.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } s1 = "Grand Total:"; s2 = "Rs. " + m.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); para = new Paragraph( "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n", fontbold2); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); document.close(); } catch (Exception mm) { } return fi; }
From source file:bladwin.web.reg.regPDF.java
public void genPed(String loc, regMgr regMgr, dbMgrInterface db) { Document document = null; //String loc = "C:/_bisc/_javaApps/jlData/jvp/CellWidths.pdf"; //regMgr.getCustomerRegBean().setPdf(loc); try {// w w w .j a v a2 s. co m document = new Document(PageSize.A4, 30, 30, 30, 30); PdfWriter.getInstance(document, new FileOutputStream(loc)); document.open(); customerRegBean r = regMgr.getCustomerRegBean(); customerBean c = regMgr.getCustomerBean(); customerBean a = new custObj().getcustomerBean(r.getRegCustId(), db); mgnLookupBean bean = new mgnLookupObj().getLookupBean(-947, db); Paragraph pg; pg = new Paragraph(r.getLookupDesc()); pg.setAlignment(Paragraph.ALIGN_CENTER); pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)); document.add(getHeader(r.getLookupDesc())); document.add(getHeader("BALDWIN BLAZERS TRACK CLUB")); document.add(getHeader("REGISTRATION")); pg = new Paragraph("\n\r"); document.add(pg); // ------------------------------------------------------- document.add(genAthleteInfo(r, a)); pg = new Paragraph("\n\r"); document.add(pg); document.add(genParentInfo(c)); pg = new Paragraph("\n\r"); document.add(pg); document.add(genSport(r)); pg = new Paragraph("\n\r"); document.add(pg); pg = new Paragraph("PARENTS SIGNATURE"); document.add(pg); pg = new Paragraph("\n\r"); document.add(pg); pg = new Paragraph("\n\r"); document.add(pg); pg = new Paragraph("_____________________________________________________________________"); document.add(pg); pg = new Paragraph("\n\r"); document.add(pg); document.add(getHeader(r.getFeeDesc() + "\n\r" + bean.getSubjectBody())); // ---------------------------------------------------------------------------- } catch (DocumentException ex) { logger.error("DocumentException", ex); } catch (FileNotFoundException ex) { logger.error("FileNotFoundException", ex); } finally { try { if (document != null) document.close(); //pdfFileOpen(loc); } catch (Exception e) { logger.error("FileNotFoundException", e); } } }
From source file:bodyfitness.relatorios.Relatorio.java
public void GeraRelatorioAdimplente(String caminho) { Document documento = new Document(); try {/*w ww . j av a2 s. com*/ PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/Adimplentes.pdf")); documento.open(); ClienteDAO dao = new ClienteDAO(); List<Cliente> clientes = dao.consultarAdimplentes(); PdfPTable tabela = new PdfPTable(2); tabela.addCell("ID"); tabela.addCell("Nome"); Paragraph p = new Paragraph(" Relatrio - Clientes Adimplentes\n\n\n"); documento.add(p); for (Cliente c : clientes) { tabela.addCell(c.getId().toString()); tabela.addCell(c.getNome()); } documento.add(tabela); documento.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } }
From source file:bodyfitness.relatorios.Relatorio.java
public void GeraRelatorioInadimplente(String caminho) { Document documento = new Document(); try {/* w w w . ja va 2 s . c o m*/ PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/Adimplentes.pdf")); documento.open(); ClienteDAO dao = new ClienteDAO(); List<Cliente> clientes = dao.consultarInadimplentes(); PdfPTable tabela = new PdfPTable(2); tabela.addCell("ID"); tabela.addCell("Nome"); Paragraph p = new Paragraph(" Relatrio - Clientes Inadimplentes\n\n\n"); documento.add(p); for (Cliente c : clientes) { tabela.addCell(c.getId().toString()); tabela.addCell(c.getNome()); } documento.add(tabela); documento.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } }
From source file:bodyfitness.relatorios.Relatorio.java
public void GeraRelatorioMaquinaSManutencao(String caminho) { Document documento = new Document(); try {/*w w w . ja va2 s . c om*/ PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/MaquinaSManutencao.pdf")); documento.open(); EquipamentoDAO dao = new EquipamentoDAO(); List<Equipamento> equips = dao.consultarSemManutancao(); PdfPTable tabela = new PdfPTable(3); tabela.addCell("ID"); tabela.addCell("Nome"); tabela.addCell("D. Ultima Mantencao"); SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); Paragraph p = new Paragraph(" Relatrio - Clientes Mquinas Sem Manuteno\n\n\n"); documento.add(p); for (Equipamento e : equips) { tabela.addCell(e.getId().toString()); tabela.addCell(e.getNome()); tabela.addCell(formato.format(e.getDataDaUltimaManutencao())); } documento.add(tabela); documento.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } }
From source file:bodyfitness.relatorios.Relatorio.java
public void GeraRelatorioTreino(String caminho, Long id) { ClienteDAO cdao = new ClienteDAO(); Cliente cliente = cdao.consultarPorId(id); Document documento = new Document(); Paragraph p = new Paragraph("Nome: " + cliente.getNome() + "\n" + "Id: " + cliente.getId().toString() + "\n" + "Idade: " + cliente.getIdade().toString() + "\n\n"); PdfPTable tabela = new PdfPTable(3); tabela.addCell("Maquina"); tabela.addCell("Sries"); tabela.addCell("Repeties"); try {//from ww w. ja v a2 s .c o m PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/MaquinaSManutencao.pdf")); Treino t = cliente.getTreino(); for (int i = 0; i < t.getSeries().size(); i++) { tabela.addCell(t.getSeries().get(i).getEquipamento().getNome()); tabela.addCell(String.valueOf(t.getSeries().get(i).getQuantidadeDeSeries())); tabela.addCell(String.valueOf(t.getSeries().get(i).getRepeticoes())); } documento.add(p); documento.add(tabela); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro em relatrio de treino:\n" + e.getMessage()); } finally { documento.close(); } }
From source file:bodyfitness.relatorios.Relatorio.java
public void GeraRelatorioCondFisico(String caminho, Long id) { Document documento = new Document(); ClienteDAO cdao = new ClienteDAO(); Cliente c = cdao.consultarPorId(id); Paragraph p = new Paragraph("Nome: " + c.getNome() + "\n" + "Id: " + c.getId().toString() + "\n" + "Idade: " + c.getIdade().toString() + "\n\n"); try {/*from www . ja v a2s . c om*/ PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/CondFisico.pdf")); documento.open(); PdfPTable tabela = new PdfPTable(2); tabela.addCell("Aspecto"); tabela.addCell("Valor"); //SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); CondicionamentoFisico cf = c.getCondicionamentoFisico(); tabela.addCell("IMC"); tabela.addCell(cf.getComposicaoCorporal().getImc().toString()); tabela.addCell("Massa Gorda"); tabela.addCell(cf.getComposicaoCorporal().getMassaGorda().toString()); tabela.addCell("Massa Magra"); tabela.addCell(cf.getComposicaoCorporal().getMassaMagra().toString()); tabela.addCell("Percentual atual de gordura"); tabela.addCell(cf.getComposicaoCorporal().getPercentualGorduraAtual().toString()); tabela.addCell("Percentual ideal de gordura"); tabela.addCell(cf.getComposicaoCorporal().getPercentualGorduraIdeal().toString()); tabela.addCell("Abdominal"); tabela.addCell(cf.getDobrasCutaneas().getAbdominal().toString()); tabela.addCell("Axilar Media"); tabela.addCell(cf.getDobrasCutaneas().getAxilarMedia().toString()); tabela.addCell("Bicipital"); tabela.addCell(cf.getDobrasCutaneas().getBicipital().toString()); tabela.addCell("Coxa"); tabela.addCell(cf.getDobrasCutaneas().getCoxa().toString()); tabela.addCell("Panturrilha"); tabela.addCell(cf.getDobrasCutaneas().getPanturrilha().toString()); tabela.addCell("Peitoral"); tabela.addCell(cf.getDobrasCutaneas().getPeitoral().toString()); tabela.addCell("Subescapular"); tabela.addCell(cf.getDobrasCutaneas().getSubescapular().toString()); tabela.addCell("Supra iliaca"); tabela.addCell(cf.getDobrasCutaneas().getSupraIliaca().toString()); tabela.addCell("Tricipital"); tabela.addCell(cf.getDobrasCutaneas().getTricipital().toString()); tabela.addCell("Antebrao Direito"); tabela.addCell(cf.getMembrosInferiores().getAnteBracoDireito().toString()); tabela.addCell("Brao Contrado Direito"); tabela.addCell(cf.getMembrosInferiores().getBracoContraidoDireito().toString()); tabela.addCell("Brao Relaxado Direito"); tabela.addCell(cf.getMembrosInferiores().getBracoRelaxadoDireito().toString()); tabela.addCell("Brao Relaxado Esquerdo"); tabela.addCell(cf.getMembrosInferiores().getBracoRelaxadoEsquerdo().toString()); tabela.addCell("Coxa Esquerda"); tabela.addCell(cf.getMembrosInferiores().getCoxaEsquerdo().toString()); tabela.addCell("Panturrilha Direita"); tabela.addCell(cf.getMembrosInferiores().getPanturrilhaDireito().toString()); tabela.addCell("Abdome"); tabela.addCell(cf.getMembrosSuperiores().getAbdome().toString()); tabela.addCell("Cintura"); tabela.addCell(cf.getMembrosSuperiores().getCintura().toString()); tabela.addCell("Ombro"); tabela.addCell(cf.getMembrosSuperiores().getOmbro().toString()); tabela.addCell("Pescoo"); tabela.addCell(cf.getMembrosSuperiores().getPescoco().toString()); tabela.addCell("Quadril"); tabela.addCell(cf.getMembrosSuperiores().getQuadril().toString()); tabela.addCell("Torx"); tabela.addCell(cf.getMembrosSuperiores().getToraxRelaxado().toString()); documento.add(p); documento.add(tabela); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } finally { documento.close(); } }
From source file:bookshopautomationsoftware.GenerateReceipt.java
public GenerateReceipt() { try {/* w w w . j a v a 2s . c o m*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:bookshopautomationsoftware.GenerateReceipt.java
public static void main(String[] args) { try {//from ww w .ja v a 2s . c o m Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }