List of usage examples for com.itextpdf.text Document open
boolean open
To view the source code for com.itextpdf.text Document open.
Click Source Link
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Livros public void pdfL() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null; OutputStream os = null;//ww w .j av a2s .com try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("TabelaL.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaL = new PdfPTable(new float[] { 0.1f, 0.7f, 0.7f, 0.1f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Livros")); header.setColspan(4); tabelaL.addCell(header); tabelaL.addCell("ID"); tabelaL.addCell("Ttulo"); tabelaL.addCell("Autor"); tabelaL.addCell("Qtde."); Statement st = conn.conectar1().createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM `Livro`;"); while (rs.next()) { Livro l = new Livro(0, "", "", 0, 0); l.setIdlivro(rs.getInt("idlivro")); l.setTiLivro(rs.getString("nomeLivro")); l.setNoAutor(rs.getString("nomeAutor")); l.setQtdeLivro(rs.getInt("qtdelivro")); tabelaL.addCell(String.valueOf(l.getIdlivro())); tabelaL.addCell(l.getTiLivro()); tabelaL.addCell(l.getNoAutor()); tabelaL.addCell(String.valueOf(l.getQtdeLivro())); } doc.add(tabelaL); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Reservas public void pdfR() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null; OutputStream os = null;//from w ww. j a v a 2s. c om try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("Tabela de Reservas.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaR = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.7f, 0.7f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Reservas")); header.setColspan(5); tabelaR.addCell(header); tabelaR.addCell("ID"); tabelaR.addCell("Ttulo do Livro"); tabelaR.addCell("Aluno"); tabelaR.addCell("Data de Saida"); tabelaR.addCell("Data de Entrega"); Statement stR = conn.conectar1().createStatement(); ResultSet rsr = stR.executeQuery( "SELECT Itens.id_Itens as \"Item\", Itens.id_reserva AS \"Reserva\", Aluno.nomeAluno " + "as \"Aluno\", Itens.id_Livro as \"idLivro\", Livro.nomeLivro AS \"NomeLivro\", Reserva.dataRetirada AS \"DataSaida\", Reserva.dataEntrega as \"DataEntrega\"" + "FROM Itens JOIN Reserva ON id_reserva = Reserva.idReserva\n" + "JOIN Aluno ON Reserva.idAluno = Aluno.idAluno\n" + "JOIN Livro ON Livro.idLivro = Itens.id_Livro;"); while (rsr.next()) { Reserva r = new Reserva(0, 0, "", 0, "", "", ""); r.setIdItem(rsr.getInt("Item")); r.setIdReserva(rsr.getInt("Reserva")); r.setNoAluno(rsr.getString("Aluno")); r.setIdLivro(rsr.getInt("idLivro")); r.setNoLivro(rsr.getString("NomeLivro")); r.setDaSaida(rsr.getString("DataSaida")); r.setDaEntrada(rsr.getString("DataEntrega")); tabelaR.addCell(String.valueOf(r.getIdReserva())); tabelaR.addCell(r.getNoLivro()); tabelaR.addCell(r.getNoAluno()); tabelaR.addCell(r.getDaSaida()); tabelaR.addCell(r.getDaEntrada()); } doc.add(tabelaR); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
/** * createPdf es una funcin estatica que funciona como plantilla para generar * reportes dinamicos, segn la necesidad del usuario. * @param path La direccin del archivo donde se guardar el pdf * @param titulo El Ttulo que llevar el pdf * @param encabezado Un texto que se mostrar bajo el ttulo * @param tabla La tabla de resultados que mostrar el pdf *//*from w w w .j a va2s. c o m*/ static public void createPdf(String path, String titulo, String encabezado, PdfPTable tabla) { Document document = new Document(); // step 2 try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(14); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora del Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); document.add(new Paragraph(encabezado + (tabla.getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tabla); // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createArrayListPdf(String path, String titulo, String encabezado, ArrayList<PdfPTable> tablas) { Document document = new Document(); ArrayList<String> NombreTablas = new DaoReportesEstadisticas().getNombreTablas(); //step 2//from ww w. j ava 2s .c o m try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); for (int i = 0; i < tablas.size(); i++) { document.add(new Paragraph(NombreTablas.get(i))); document.add(new Paragraph(encabezado + (tablas.get(i).getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tablas.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createDinamicPdf(String path, String titulo, String encabezado, ArrayList<Element> contenido) { Document document = new Document(); //step 2// w w w .j av a 2s. c om try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados"); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); // document.add(Introduccion); document.add(new Paragraph("\r\n")); for (int i = 0; i < contenido.size(); i++) { document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass()) ? (PdfPTable) contenido.get(i) : contenido.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:bicimotos3hermanos.MainFrom.java
public void toPFD(String out, String in) { try {/*from w w w.j av a 2s .c o 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;//ww w .j a v a 2 s .c o m 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 {/*from w ww . j ava2 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 {/*from w ww . ja va2 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 {/*ww w .j a v a2 s . c om*/ 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); } }