trucosjakartaee
search
⌘Ctrlk
trucosjakartaee
  • Introduction
  • Creditos
  • Jar to Exe
  • Primefaces security
  • Primefaces Responsive
  • Leer archivos en una linea de codigo
  • Logger Crear archivo JSOn
  • Cifrar Archivos y Licencias
  • JSON-P Leer arhivos
  • Apache Derby
  • Migrar a Java 11
  • jmoordbjsf
  • Reportes
    • OpenPDF
      • Enlaces
      • Introduccion
      • Reportes con ReportUtils.java
      • Reporte con ReportUtils y <jmoordbjsf:paginator>
      • Turoriales
      • Informe con 6 columnas
      • Tamaño de pagina
      • Centrar en el reporte
      • Margenes
      • Fuentes en las celdas
      • Formatear Fechas
      • Imagenes
      • grupos
      • subreportes
      • firmar pdf
      • Agregar autor al pdf
      • Reporte simple
    • iReport
    • Imprimir condicional
    • DynamicReports
    • iText
    • PDFBox
    • JaspertReport from code
    • Nerval Reports
    • DynamicJasper
    • Eclipse birt
  • Overview
    • jmoordb web
    • JavaEE
    • Java Server Faces
    • Formatos y Fechas
    • Fechas
    • Rangos de Fechas
    • Generales
    • Mongodb
    • Controller
    • Formularios
    • JmoordbLanguages
    • JmoordbResourcesFiles
    • list.xtml
    • Entity
    • Services
    • Blogs
    • Glassfish
    • PDF
    • Links
    • Ubuntu
    • Databases
    • Tutoriales JavaEE 8
    • Busquedas en List<> Embebidos y Referenciados
    • Search
    • Eventos
    • Microservicios
    • Java
    • Primefaces
    • Entity Configuración
    • Arquitectura
    • BitBucket/NetBeans
    • Controller
    • Componentes
    • Genericos implementar en un Controller
    • LambdaMetaFactory
    • Patrones
    • @Producer Reducir Repository
  • Cierre Mensual
    • Cierre mensual
  • fontAwesome Local
    • fontAwesome Local
  • Componentes
    • Componentes JSF
  • LambdaMetaFactory
    • LambdaMetaFactory
  • Patrones de Diseño
    • Patrones de Diseño
    • Builder
  • @Producer Reducir Repository
    • @Producer Reducir Repository
    • Validar en el inicio del controller con nuevo esquema
    • AdminFaces
    • Cargar archivo propiedades
    • Maven Crear arquetipo en base a un proyecto
    • PayaraMicro
    • Archivos de propiedades con adminfaces
  • Web Socket
    • WebSocket
    • Pagina de Inicio en Java EE
    • Control de Viajes
    • Vehiculos recomendados
  • DBUtils
  • Archivos Properties
  • MICROSERVICES
    • MICROSERVICES
gitbookPowered by GitBook
block-quoteOn this pagechevron-down
  1. Reporteschevron-right
  2. OpenPDF

Introduccion

Sitio principal

LogoGitHub - LibrePDF/OpenPDF: OpenPDF is an open-source Java library for creating, editing, rendering, and encrypting PDF documents, as well as generating PDFs from HTML. It is licensed under the LGPL and MPL.GitHubchevron-right

hashtag
Pagina

hashtag
imprimir()

hashtag
Reporte

PreviousEnlaceschevron-leftNextReportes con ReportUtils.javachevron-right

Last updated 6 years ago

  • Pagina
  • imprimir()
  • Reporte
<dependency>
        <groupId>com.github.librepdf</groupId>
        <artifactId>openpdf</artifactId>
        <version>1.3.8</version>
    </dependency>
<b:column medium-screen="25" >
<p:commandButton action="#{programacionVechicularController.imprimir()}" value="Reporte"
                        icon="icon-report" ajax="false">
</p:commandButton>
public void imprimir() {
             
             com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.LETTER);
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             try {
                   PdfWriter.getInstance(document, baos);
                  //METADATA
                 
                
                  document.open();
                 
                  document.add(new Paragraph(" PROGRAMACION DE FLOTA VEHICULAR \n"));
                 
                  DateFormat formatter= new SimpleDateFormat("dd/MM/yy '-' hh:mm:ss:");
                   Date currentDate = new Date();
                   String date = formatter.format(currentDate);
                  document.add(new Paragraph("Fecha Generado: "+date)); 
                  document.add(new Paragraph("\n"));
                 
                  PdfPTable table = new PdfPTable(6);
                 
                  table.setTotalWidth(new float[]{ 20,72, 110, 95, 170, 72 });
              table.setLockedWidth(true);
                 
             
               PdfPCell cell = new PdfPCell(new Paragraph("Listado de ALumnos" ,
                       FontFactory.getFont("arial",   // fuente
                         8,                            // tamaño
                     Font.BOLD)));
                  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                  
                        cell.setColspan(6);
                  table.addCell(cell);

                  cell = new PdfPCell(new Paragraph ("ID", FontFactory.getFont("arial",8,Font.BOLD )));
                   
                
                 
                  table.addCell("conductor");
                 
                  table.addCell("placa");
                 
                
                 
                  for (ProgramacionVehicular pv:programacionVehicular) {
                     
                        table.addCell(pv.getIdviaje().toString());
                        table.addCell(pv.getConductor());
                        table.addCell(pv.getPlaca());
                     
                  }
                  document.add(table);
            } catch (Exception ex) {
                  System.out.println("Error " + ex.getMessage());
            }
            document.close();
            FacesContext context = FacesContext.getCurrentInstance();
            Object response = context.getExternalContext().getResponse();
            if (response instanceof HttpServletResponse) {
                  HttpServletResponse hsr = (HttpServletResponse) response;
                  hsr.setContentType("application/pdf");
                  hsr.setHeader("Contentdisposition",  "attachment;filename=report.pdf");
          //        hsr.setHeader("Content-disposition", "attachment");
                  hsr.setContentLength(baos.size());
                  try {
                        ServletOutputStream out = hsr.getOutputStream();
                        baos.writeTo(out);
                        out.flush();
                  } catch (IOException ex) {
                        System.out.println("Error:  " + ex.getMessage());
                  }
                  context.responseComplete();
            }
       }