I can not export invoice to the txt file

0

Dear Friends: I'm trying to export my invoice to the txt file to be printed on the dot matrix printer from javaweb JSF (JavaFaces) and I get a message error: javax.faces.el.EvaluationException: net.sf.jasperreports.engine.JRRuntimeException: Character width in pixels or page width in characters must be specified and must be greater than zero. Please I need you to guide me, in which I have failed.

Here I show you my code: ReporteFactura.java

   public void exportarFacturaText(String ruta, String archivo, Integer codF, BigDecimal toTales, String simMone) throws ClassNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, IOException, Exception {
    Connection conexion;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/erpcarbonstar?useSSL=false", "root", "10260429");
    HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    response.setHeader("Content-Disposition", "attachment; filename=" + archivo);
    ServletOutputStream outstream = response.getOutputStream();

    Locale milocal = new Locale("en", "PE");
    this.totaligv = new BigDecimal("0");
    this.totales = new BigDecimal("0");
    int x = 1;

    this.session = HibernateUtil.getSessionFactory().openSession();
    parametroDao parDao = new parametroDaoImp();
    this.transaction = this.session.beginTransaction();

    this.parametro = parDao.obtenerDatosParametro(this.session, x);
    if (this.parametro.getIdParametro().equals(x) && this.parametro.getMonedaParametro1().equals(simMone)) {
        BigDecimal dividoigv = this.parametro.getImpuestoParametroDec().divide(new BigDecimal(100.0));
        BigDecimal igv = toTales.multiply(dividoigv);
        this.totaligv = igv;
        this.txtmonedas = this.parametro.getDesignacionParametro1();
    } else if (this.parametro.getIdParametro().equals(x) && this.parametro.getMonedaParametro2().equals(simMone)) {
        BigDecimal dividoigv = this.parametro.getImpuestoParametroDec().divide(new BigDecimal(100.0));
        BigDecimal igv = toTales.multiply(dividoigv);
        this.totaligv = igv;
        this.txtmonedas = this.parametro.getDesignacionParametro2();
    }
    this.totales = toTales.add(this.totaligv);
    DecimalFormat df = new DecimalFormat("######0.00");
    conversionMontoLetra numletra = new conversionMontoLetra();
    String montosletras = numletra.Convertir(df.format(this.totales), true);
    String txtmontosletras = "SON : " + montosletras + this.txtmonedas;

    //Se definen los parametros que el reporte necesita
    Map parameter = new HashMap();
    parameter.put("numerosfacturas", codF);
    parameter.put("igv", this.totaligv);
    parameter.put("totales", this.totales);
    parameter.put("montoletra", txtmontosletras);
    parameter.put(JRParameter.REPORT_LOCALE, milocal);
    parameter.put(JRTextExporterParameter.PAGE_WIDTH, 800);
    parameter.put(JRTextExporterParameter.PAGE_HEIGHT, 400);

    try {
        File file = new File(ruta);

        JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(file.getPath());
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, conexion);
        JRTextExporter exporter = new JRTextExporter();
        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        exporter.setExporterOutput(new SimpleWriterExporterOutput(outstream));
        exporter.exportReport();

        outstream.flush();
        outstream.close();

    } catch (JRException ex) {
        ex.printStackTrace(System.out);
    } finally {
        if (conexion != null) {
            try {
                conexion.close();
            } catch (SQLException ex) {
                ex.printStackTrace(System.out);
            }
        }
    }
}

FacturaBean.java is a part of the code:

    public void verFacturaMatrixNavegadorPDF() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {

    int cf = this.numerofact;
    BigDecimal tt = this.toTaless;
    String mm = this.simmon;
    DecimalFormat serie = new DecimalFormat("000000");

    reporteFactura rFactura = new reporteFactura();

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
    String ruta = servletContext.getRealPath("/Reportes/facturamatrixReport.jasper");
    String archivo = "FacturaNro" + serie.format(cf) + ".txt";

    //rFactura.verFacturaPDF(ruta, archivo, cf, tt, mm);
    rFactura.exportarFacturaText(ruta, archivo, cf, tt, mm);
    FacesContext.getCurrentInstance().responseComplete();

}

small code of the part of the view:

                            <h:outputText value=" "/>
                        <h:commandLink id="reportefactura3" target="_blank" actionListener="#{facturaBean.pedirFactura(ft.numeroFactura, ft.totalVenta, ft.moneda.simboloMoneda)}"                                           
                                       title="Imprimir en la impresora Matricial" action="#{facturaBean.verFacturaMatrixNavegadorPDF()}" >
                            <h:graphicImage value="/resources/Imagenes/impresoramatricial.png" width="20" height="20"/>
                        </h:commandLink>
    
asked by Croelanjr 11.01.2018 в 18:06
source

2 answers

0
___ erkimt ___ I can not export invoice to the txt file ______ qstntxt ___

Dear Friends: I'm trying to export my invoice to the txt file to be printed on the dot matrix printer from javaweb JSF (JavaFaces) and I get a message error: javax.faces.el.EvaluationException: net.sf.jasperreports.engine.JRRuntimeException: Character width in pixels or page width in characters must be specified and must be greater than zero. Please I need you to guide me, in which I have failed.

Here I show you my code: ReporteFactura.java

parameter.put(TextReportConfiguration.PROPERTY_CHARACTER_WIDTH, 7.238);
parameter.put(TextReportConfiguration.PROPERTY_CHARACTER_HEIGHT, 13.948);

FacturaBean.java is a part of the code:

parameter.put(TextReportConfiguration.PROPERTY_CHARACTER_WIDTH, 7.238);
parameter.put(TextReportConfiguration.PROPERTY_CHARACTER_HEIGHT, 13.948);

small code of the part of the view:

%pre%     
______ ___ azszpr130460

Try adding 2 more properties:

%pre%

The following link can help you TextReportConfiguration

    
______ azszpr130495 ___

Thanks for the information. I have already tried to put to the indicated thing. In the end I had to add this code in the ireport jrxml file and with that it works.

%pre%     
___
answered by 11.01.2018 в 20:23
0

Thanks for the information. I have already tried to put to the indicated thing. In the end I had to add this code in the ireport jrxml file and with that it works.

<property name="net.sf.jasperreports.export.text.character.width" value="7.238"/>
<property name="net.sf.jasperreports.export.text.character.height" value="13.948"/>
    
answered by 11.01.2018 в 22:23