List of usage examples for com.lowagie.text Document Document
public Document()
Document
-object. From source file:binky.reportrunner.engine.renderers.exporters.PDFExporter.java
License:Open Source License
@Override public void export(ResultSet resultSet, String label, OutputStream outputStream) throws ExportException { try {/*from w ww. j a v a 2s. c o m*/ Document document = new Document(); PdfWriter.getInstance(document, outputStream); // open the document object document.open(); ResultSetMetaData metaData = resultSet.getMetaData(); PdfPTable table = new PdfPTable(metaData.getColumnCount()); for (int i = 1; i <= metaData.getColumnCount(); i++) { Paragraph para = new Paragraph(metaData.getColumnName(i), new Font(Font.HELVETICA, 10, Font.BOLD)); PdfPCell cell = new PdfPCell(para); table.addCell(cell); } while (resultSet.next()) { for (int i = 1; i <= metaData.getColumnCount(); i++) { Paragraph para = new Paragraph("" + resultSet.getObject(i), new Font(Font.HELVETICA, 10, Font.NORMAL)); PdfPCell cell = new PdfPCell(para); table.addCell(cell); } } document.add(table); document.close(); } catch (DocumentException e) { throw new ExportException(e.getMessage(), e); } catch (SQLException e) { throw new ExportException(e.getMessage(), e); } }
From source file:br.com.moises.servlet.RelatorioPessoa.java
private void mostrarRelatorio(byte[] arquivo, HttpServletResponse response) { /**/*from w w w. ja v a 2s.co m*/ * A simple Hello World Servlet. * @see HttpServlet#doGet( * HttpServletRequest request, HttpServletResponse response) */ response.setContentType("application/pdf"); try { // step 1 Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, response.getOutputStream()); } catch (IOException ex) { Logger.getLogger(RelatorioPessoa.class.getName()).log(Level.SEVERE, null, ex); } // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); document.add(new Paragraph(new Date().toString())); // step 5 document.close(); } catch (DocumentException de) { try { throw new IOException(de.getMessage()); } catch (IOException ex) { Logger.getLogger(RelatorioPessoa.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:br.edu.ifrs.restinga.modulorh.controle.SetorController.java
@RequestMapping(value = "/setor/gerarPDF") public String gerar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DocumentException { response.setContentType("application/pdf"); try {// w w w.j a v a2 s. c om Document document = new Document(); PdfWriter.getInstance(document, response.getOutputStream()); Image image = Image.getInstance("http://www.planalto.gov.br/cciVil_03/decreto/Quadros/anteri1.gif"); image.setAlignment(Image.ALIGN_CENTER); document.open(); document.add(image); document.add(new Paragraph("Ministrio da Educao")); document.add( new Paragraph("Instituto Federal de Educao, Cincia e Tecnologia do Rio Grande do Sul ")); document.add(new Paragraph("Campus Restinga")); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } return "forward:/setor/gerar"; }
From source file:br.edu.ifrs.restinga.sgru.modelo.ControladorVenda.java
/** * Realiza a venda de um ticket para um cliente * * @param documento/*from www . j a v a 2 s . c o m*/ * @throws br.edu.ifrs.restinga.sgru.excessao.TicketInvalidoException */ //public void realizarVendaTicket(Object documento) throws TicketInvalidoException { public void realizarVendaTicket() throws TicketInvalidoException { if (this.quantidade <= 0) { throw new TicketInvalidoException("Venda de Quantidade invalida!"); } Document pdfTicket = new Document(); File temp; try { temp = File.createTempFile("imp_ticket", ".pdf"); PdfWriter.getInstance(pdfTicket, new FileOutputStream(temp)); pdfTicket.open(); pdfTicket.setPageSize(PageSize.A4); Table tabela = new Table(1); tabela.setWidth(100); for (int i = 0; i < this.quantidade; i++) { VendaTicketsRecargas vendaTicketsRecarga = new VendaTicketsRecargas(); vendaTicketsRecarga.setCaixaRU(this.caixaRU); vendaTicketsRecarga.realizarVendaTicket(); Cell celula = new Cell(); celula.setHorizontalAlignment(Element.ALIGN_CENTER); celula.add(new Paragraph("SISTEMA DE GERENCIAMENTO DE RESTAURANTE UNIVERSIT?RIO")); Paragraph parag = new Paragraph(); parag.getFont().setSize(18); parag.add("TICKET"); celula.add(parag); // Gerando o codigo convetido do ticket String conversor = ""; for (char con : String.format("%07d", vendaTicketsRecarga.getTicket().getId()).toCharArray()) { conversor = con + conversor; } parag = new Paragraph(); parag.getFont().setSize(20); parag.add(String.valueOf(Integer.valueOf(conversor, 16))); celula.add(parag); NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("pt", "BR")); format.setMaximumFractionDigits(2); celula.add(new Paragraph("VALOR " + format.format(vendaTicketsRecarga.getTicket().getValor()))); celula.add(new Paragraph(vendaTicketsRecarga.getTicket().getDataCriado().getTime().toString())); celula.add(new Paragraph(" _ ")); tabela.addCell(celula); this.caixaRU.atualizarLstVendaTicketsRecargas(vendaTicketsRecarga); } pdfTicket.add(tabela); } catch (DocumentException | IOException de) { throw new TicketInvalidoException(de.getMessage()); } finally { pdfTicket.close(); } // Abrindo o pdf no pc try { Desktop.getDesktop().open(temp); temp.deleteOnExit(); } catch (IOException ex) { throw new TicketInvalidoException(ex.getMessage()); } }
From source file:ca.nines.ise.writer.RTFWriter.java
License:Open Source License
public RTFWriter(PrintStream out) throws ParserConfigurationException, UnsupportedEncodingException { super(out);/* ww w .ja v a 2 s . c o m*/ doc = new Document(); writer = RtfWriter2.getInstance(doc, out); writer.getDocumentSettings().setOutputDebugLineBreaks(true); normal = new RtfParagraphStyle("ISE Normal", "Times New Roman", 12, Font.NORMAL, Color.BLACK); normal.setAlignment(Element.ALIGN_UNDEFINED); writer.getDocumentSettings().registerParagraphStyle(normal); ld = new RtfParagraphStyle("ISE h2", "ISE Normal"); ld.setFontName("Helvetica"); ld.setSize(16); ld.setStyle(Font.BOLD); writer.getDocumentSettings().registerParagraphStyle(ld); exit = new RtfParagraphStyle("ISE exit", "ISE Normal"); exit.setAlignment(Element.ALIGN_RIGHT); exit.setStyle(Font.ITALIC); writer.getDocumentSettings().registerParagraphStyle(exit); p1 = new RtfParagraphStyle("ISE p1", "ISE Normal"); p1.setFirstLineIndent(-19); p1.setIndentLeft(19); p1.setIndentRight(49); writer.getDocumentSettings().registerParagraphStyle(p1); prose = new RtfParagraphStyle("ISE Prose", "ISE Normal"); prose.setFirstLineIndent(-19); prose.setIndentLeft(19); prose.setIndentRight(49); writer.getDocumentSettings().registerParagraphStyle(prose); p2 = new RtfParagraphStyle("ISE p2", "ISE Normal"); p2.setFirstLineIndent(-19); p2.setIndentLeft(38); p2.setIndentRight(49); writer.getDocumentSettings().registerParagraphStyle(p2); fnStyle = new RtfParagraphStyle("ISE Footnote", "ISE Normal"); fnStyle.setFontName("Times New Roman"); fnStyle.setFirstLineIndent(-19); fnStyle.setIndentLeft(19); fnStyle.setIndentRight(0); fnStyle.setSize(10); writer.getDocumentSettings().registerParagraphStyle(fnStyle); }
From source file:candelaria.presentacion.beans.DetalleFacturaControlador.java
public void imprimirFac() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {// w w w. j av a 2 s . co m //Generamos el archivo PDF String directorioArchivos; ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); directorioArchivos = ctx.getRealPath("/") + "reports"; String name = directorioArchivos + "/document-factura.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(name)); //PdfWriter writer = PdfWriter.getInstance(document, //new FileOutputStream("C:")); Paragraph paragraph = new Paragraph(); Paragraph paragraph1 = new Paragraph(); PdfPTable table = new PdfPTable(4); PdfPTable table1 = new PdfPTable(2); PdfPTable table2 = new PdfPTable(1); PdfPTable table3 = new PdfPTable(2); PdfPTable table5 = new PdfPTable(4); PdfPTable tablaF = new PdfPTable(1); PdfPTable tablaF1 = new PdfPTable(3); PdfPTable tablaF2 = new PdfPTable(3); paragraph.add("\n\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("YUQUI OLGA"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("\n"); paragraph.add("Dir. La Candelaria Barrio Nuevo"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("\n"); paragraph.add("Telf: 3014019"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("\n"); paragraph.add("Penipe - Ecuador"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("\n"); paragraph.add("\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("AUTORIZACION SRI __________ - RUC.: 0600750897001"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("\n"); paragraph.add("FACTURA: " + facturaSel.getId_factura()); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph.add("\n\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph1.add("\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); document.open(); //primera linea PdfPCell cell5 = new PdfPCell(new Paragraph("Fecha: " + fecha_cambiada)); //PdfPCell cell6 = new PdfPCell(new Paragraph("Factura #: " + facturaSel.getId_factura())); PdfPCell cell7 = new PdfPCell(new Paragraph("Cedula: " + facturaSel.getId_cliente().getRuc_cliente())); //segunda linea PdfPCell cell8 = new PdfPCell( new Paragraph("Nombre Cliente: " + facturaSel.getId_cliente().getNombres_cliente() + facturaSel.getId_cliente().getApellidos_cliente())); //tercera fila PdfPCell cell9 = new PdfPCell( new Paragraph("Direccin: " + facturaSel.getId_cliente().getDireccion_cliente())); PdfPCell cell10 = new PdfPCell( new Paragraph("Tlefono: " + facturaSel.getId_cliente().getTelefono_cliente())); PdfPCell cellf1 = new PdfPCell(new Paragraph("SubTotal " + totalHoja)); PdfPCell cellf2 = new PdfPCell(new Paragraph("Impuesto Iva " + impuestoFactura)); PdfPCell cellf21 = new PdfPCell(new Paragraph("___________________")); PdfPCell cellf22 = new PdfPCell(new Paragraph("___________________")); PdfPCell cellf3 = new PdfPCell(new Paragraph("TOTAL " + totalFactura)); PdfPCell cellf31 = new PdfPCell(new Paragraph("FIRMA AUTORIZADA")); PdfPCell cellf32 = new PdfPCell(new Paragraph("FIRMA CLIENTE")); PdfPCell cell11 = new PdfPCell(new Paragraph("Cantidad")); PdfPCell cell12 = new PdfPCell(new Paragraph("Descripcin")); PdfPCell cell13 = new PdfPCell(new Paragraph("V. Unitario")); PdfPCell cell14 = new PdfPCell(new Paragraph("V. Total")); cell5.setHorizontalAlignment(Element.ALIGN_LEFT); //cell6.setHorizontalAlignment(Element.ALIGN_CENTER); cell7.setHorizontalAlignment(Element.ALIGN_RIGHT); cellf1.setHorizontalAlignment(Element.ALIGN_RIGHT); cellf2.setHorizontalAlignment(Element.ALIGN_RIGHT); cellf3.setHorizontalAlignment(Element.ALIGN_RIGHT); cellf21.setHorizontalAlignment(Element.ALIGN_CENTER); cellf31.setHorizontalAlignment(Element.ALIGN_CENTER); cellf22.setHorizontalAlignment(Element.ALIGN_CENTER); cellf32.setHorizontalAlignment(Element.ALIGN_CENTER); cell8.setHorizontalAlignment(Element.ALIGN_LEFT); cell9.setHorizontalAlignment(Element.ALIGN_LEFT); cell10.setHorizontalAlignment(Element.ALIGN_RIGHT); cellf21.setBorder(Rectangle.NO_BORDER); cellf31.setBorder(Rectangle.NO_BORDER); cellf22.setBorder(Rectangle.NO_BORDER); cellf32.setBorder(Rectangle.NO_BORDER); cell5.setBorder(Rectangle.NO_BORDER); //cell6.setBorder(Rectangle.NO_BORDER); cell7.setBorder(Rectangle.NO_BORDER); cell8.setBorder(Rectangle.NO_BORDER); cell9.setBorder(Rectangle.NO_BORDER); cell10.setBorder(Rectangle.NO_BORDER); //cell7.setBorder(Rectangle.NO_BORDER); //cell8.setBorder(Rectangle.NO_BORDER); cell11.setBorder(Rectangle.NO_BORDER); cell12.setBorder(Rectangle.NO_BORDER); cell13.setBorder(Rectangle.NO_BORDER); cell14.setBorder(Rectangle.NO_BORDER); cellf1.setBorder(Rectangle.NO_BORDER); cellf2.setBorder(Rectangle.NO_BORDER); cellf3.setBorder(Rectangle.NO_BORDER); cell11.setHorizontalAlignment(Element.ALIGN_LEFT); cell12.setHorizontalAlignment(Element.ALIGN_LEFT); cell13.setHorizontalAlignment(Element.ALIGN_RIGHT); cell14.setHorizontalAlignment(Element.ALIGN_RIGHT); table1.addCell(cell5); //table1.addCell(cell6); table1.addCell(cell7); //aadir segunda fila table2.addCell(cell8); //aadir tercera fila table3.addCell(cell9); table3.addCell(cell10); //aadir cuarta fila table5.addCell(cell11); table5.addCell(cell12); table5.addCell(cell13); table5.addCell(cell14); tablaF.addCell(cellf1); tablaF1.addCell(cellf21); tablaF1.addCell(cellf22); tablaF1.addCell(cellf2); tablaF2.addCell(cellf31); tablaF2.addCell(cellf32); tablaF2.addCell(cellf3); for (int x = 0; x < lstDetalleFactura.size(); x++) { PdfPCell cell1 = new PdfPCell(new Paragraph("" + lstDetalleFactura.get(x).getCantidad())); PdfPCell cell2 = new PdfPCell(new Paragraph( "" + lstDetalleFactura.get(x).getId_producto().getId_categoria().getNombre_producto())); PdfPCell cell3 = new PdfPCell(new Paragraph( "" + lstDetalleFactura.get(x).getId_producto().getId_categoria().getPrecio_producto())); PdfPCell cell4 = new PdfPCell(new Paragraph("" + lstDetalleFactura.get(x).getValor_total())); /* Chunk chunk = new Chunk( "\n" + lstDetalles.get(x).getCantidadDet() + " " + lstDetalles.get(x).getIdSer().getNombreSer() + " " + lstDetalles.get(x).getIdSer().getPrecioSer() + " " + lstDetalles.get(x).getPrecio());*/ cell1.setBorder(Rectangle.NO_BORDER); cell2.setBorder(Rectangle.NO_BORDER); cell3.setBorder(Rectangle.NO_BORDER); cell4.setBorder(Rectangle.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); cell3.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell1.setMinimumHeight(10f); cell2.setMinimumHeight(5f); table.setTotalWidth(100f); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); //aadir primera fila table.setSpacingBefore(30f); table.setSpacingAfter(50f); //paragraph4.add(chunk); //paragraph4.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL); } document.add(paragraph); document.add(table1); document.add(table2); document.add(table3); document.add(paragraph1); document.add(table5); document.add(table); document.add(tablaF); document.add(tablaF1); document.add(tablaF2); //document.setFooter(event); document.close(); //---------------------------- //Abrimos el archivo PDF FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline=filename=" + name); try { response.getOutputStream().write(Util.getBytesFromFile(new File(name))); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:checker.ReportWriter.java
License:Open Source License
private void writePdfReport(ArrayList<String> text, String fileName) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open();//from w w w . j a v a2s.c om document.addTitle(getTitle()); Paragraph paragraph = new Paragraph(); for (String line : text) { if (line.equals("")) { paragraph.add(Chunk.NEWLINE); } else { paragraph.add(line); paragraph.add(Chunk.NEWLINE); } } document.add(paragraph); /*List list = new List(false); for (String line : text) { if (line.equals("")) { document.add(list); list = new List(false); } else { list.add(new ListItem(line)); } }*/ //document.add(list); document.close(); }
From source file:clases.unirPdf.java
public static void concatPDFs(List<InputStream> streamOfPDFFiles, OutputStream outputStream, boolean paginate) { Document document = new Document(); try {// w ww. j a v a 2 s . co m List<InputStream> pdfs = streamOfPDFFiles; List<PdfReader> readers = new ArrayList<PdfReader>(); int totalPages = 0; Iterator<InputStream> iteratorPDFs = pdfs.iterator(); while (iteratorPDFs.hasNext()) { InputStream pdf = iteratorPDFs.next(); PdfReader pdfReader = new PdfReader(pdf); readers.add(pdfReader); totalPages += pdfReader.getNumberOfPages(); } PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfImportedPage page; int currentPageNumber = 0; int pageOfCurrentReaderPDF = 0; Iterator<PdfReader> iteratorPDFReader = readers.iterator(); while (iteratorPDFReader.hasNext()) { PdfReader pdfReader = iteratorPDFReader.next(); while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) { Rectangle rectangle = pdfReader.getPageSizeWithRotation(1); document.setPageSize(rectangle); document.newPage(); pageOfCurrentReaderPDF++; currentPageNumber++; page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF); switch (rectangle.getRotation()) { case 0: cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0); break; case 90: cb.addTemplate(page, 0, -1f, 1f, 0, 0, pdfReader.getPageSizeWithRotation(1).getHeight()); break; case 180: cb.addTemplate(page, -1f, 0, 0, -1f, 0, 0); break; case 270: cb.addTemplate(page, 0, 1.0F, -1.0F, 0, pdfReader.getPageSizeWithRotation(1).getWidth(), 0); break; default: break; } if (paginate) { cb.beginText(); cb.getPdfDocument().getPageSize(); cb.endText(); } } pageOfCurrentReaderPDF = 0; } outputStream.flush(); document.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (document.isOpen()) document.close(); try { if (outputStream != null) outputStream.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
From source file:classroom.filmfestival_a.Movies01.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from w w w. j a v a2 s .c om Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); for (FilmTitle movie : results) { document.add(new Paragraph(movie.getTitle())); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_a.Movies02.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/* w w w . ja v a2 s . c o m*/ Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); for (FilmTitle movie : results) { document.add(new Paragraph(movie.getTitle())); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } document.add(list); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }