Jump to content

Recommended Posts

Posted

Hello
i have a report build by parameters, with 3 colums and same value.

After that, break page.

I want print this report with X number of copies automatic.

PS: cant loop the same document. i really need insert "number of copies" of this documents.

Thanks

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted
SOLVED
 
public void imprimir(String codigo, String tamanho, Integer qtd) throws JRException{
        
        String arquivo = "relatorios_ireport/etiqueta_pausa.jasper"; //arquivo de relatorio
        
        java.io.InputStream file = getClass().getClassLoader().getResourceAsStream(arquivo); //carrego o arquivo
 
        //NUMERO DE REPETIÇÕES
        ArrayList array_qtd = new ArrayList();
        
        //completar as 3 colunas com mesmo valor
        for(int i = 0; i < 3; i++){  
                array_qtd.add("Número" + i);  
        }
        
        
        
        JRBeanCollectionDataSource dados_qtd = new JRBeanCollectionDataSource(array_qtd);  
        
        
        Map parametros = new HashMap(); 
        
        //parametro 1 (codigo)
        parametros.put("codigo", codigo);
        
        //parametro 2 (tamanho)
        parametros.put("tamanho", tamanho);
        
        
        
        //CRIANDO
        JasperPrint printer = null;
        printer = JasperFillManager.fillReport(file, parametros, dados_qtd); 
        
        //exportar para pdf
           //JasperExportManager.exportReportToPdfFile(printer,"D://sample_report.pdf");
        
            if (jCheckBox_visualizar.isSelected()){
            
            //CHAMAR VIEW 1 DE CADA VEZ (FECHOU ABRE O OUTRO)
            JRViewer view = new JRViewer(printer); //preview
            JDialog dialog = new JDialog(); //jdialog que contem o preview
 
            dialog.getContentPane().add(view); //adiciono o preview
            dialog.setSize(600,300);
            dialog.setLocationRelativeTo(jPanel2);
            dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            dialog.setModal(true);
            dialog.setVisible(true);
            //CHAMAR VIEW DIRETO(TODOS AS QTD DE UMA VEZ)
            //JasperViewer.viewReport(printer, false);
            
            }else{
           
            //PROBLEM SOLVED WITH EXPORTER ATRIBUTESET.ADD(NEW Copies(qtd)) qtd = number of copies i want :D
 
                PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
                //printRequestAttributeSet.add(MediaSizeName.ISO_A4);
                printRequestAttributeSet.add(new Copies(qtd));
 
                PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
                //printServiceAttributeSet.add(new PrinterName("Argox_OS-214_plus_series_PPLA", null));
                //printServiceAttributeSet.add(new PrinterName("Argox OS-214 plus series PPLA em pcestamparia", Locale.getDefault()));
                printServiceAttributeSet.add(new PrinterName("Argox OS-214 plus series PPLA", Locale.getDefault()));
                //printServiceAttributeSet.add(new PrinterName("////pcestamparia//Argox OS-214 plus series PPLA", null));
                //printServiceAttributeSet.add(new PrinterName("//pcestamparia/Argox OS-214 plus series PPLA", null));
                //printServiceAttributeSet.add(new PrinterName("////pcestamparia//Argox_OS-214_plus_series_PPLA", Locale.getDefault()));
                JRPrintServiceExporter exporter = new JRPrintServiceExporter();
 
                exporter.setExporterInput(new SimpleExporterInput(printer));
                SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
                configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
                configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
                exporter.setConfiguration(configuration);
                //true para aprecer opções
                configuration.setDisplayPageDialog(false);
                configuration.setDisplayPrintDialog(false);
 
                exporter.setConfiguration(configuration);
 
                System.out.println("Inicializando impressão");  
                exporter.exportReport();  
                System.out.println("Impressão finalizada"); 
            
                   
                
            //IMPRIMIR DIRETO
            //JasperPrintManager.printReport(printer,false);
            }
        
        
    }//fim imprimir

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...