trucosjakartaee
search
Ctrlk
  • Introduction
  • Creditos
  • Jar to Exe
  • Primefaces security
  • Primefaces Responsive
  • Leer archivos en una linea de codigo
  • Logger Crear archivo JSOn
  • Cifrar Archivos y Licenciaschevron-right
  • JSON-P Leer arhivos
  • Apache Derby
  • Migrar a Java 11
  • jmoordbjsfchevron-right
  • Reporteschevron-right
    • OpenPDFchevron-right
      • 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 webchevron-right
    • JavaEEchevron-right
    • Java Server Faceschevron-right
    • Formatos y Fechaschevron-right
    • Fechaschevron-right
    • Rangos de Fechaschevron-right
    • Generaleschevron-right
    • Mongodbchevron-right
    • Controllerchevron-right
    • Formularioschevron-right
    • JmoordbLanguages
    • JmoordbResourcesFileschevron-right
    • list.xtmlchevron-right
    • Entity
    • Services
    • Blogschevron-right
    • Glassfish
    • PDFchevron-right
    • Links
    • Ubuntuchevron-right
    • Databaseschevron-right
    • Tutoriales JavaEE 8
    • Busquedas en List<> Embebidos y Referenciadoschevron-right
    • Search
    • Eventoschevron-right
    • Microservicioschevron-right
    • Javachevron-right
    • Primefaceschevron-right
    • Entity Configuración
    • Arquitecturachevron-right
    • BitBucket/NetBeanschevron-right
    • Controllerchevron-right
    • Componenteschevron-right
    • Genericos implementar en un Controller
    • LambdaMetaFactory
    • Patrones
    • @Producer Reducir Repository
  • Cierre Mensual
    • Cierre mensual
  • fontAwesome Local
    • fontAwesome Local
  • Componentes
    • Componentes JSFchevron-right
  • LambdaMetaFactory
    • LambdaMetaFactorychevron-right
  • Patrones de Diseño
    • Patrones de Diseño
    • Builder
  • @Producer Reducir Repository
    • @Producer Reducir Repository
    • Validar en el inicio del controller con nuevo esquema
    • AdminFaceschevron-right
    • Cargar archivo propiedades
    • Maven Crear arquetipo en base a un proyectochevron-right
    • PayaraMicro
    • Archivos de propiedades con adminfaces
  • Web Socket
    • WebSocketchevron-right
    • Pagina de Inicio en Java EE
    • Control de Viajeschevron-right
    • Vehiculos recomendados
  • DBUtils
  • Archivos Properties
  • MICROSERVICES
    • MICROSERVICESchevron-right
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

Was this helpful?

  • Pagina
  • imprimir()
  • Reporte

Was this helpful?

<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();
            }
       }