gpt4 book ai didi

java - 打印 Jasper 报告/ireport 份数

转载 作者:行者123 更新时间:2023-12-01 11:30:58 25 4
gpt4 key购买 nike

我有一个按参数构建的报告,包含 3 列和相同的值。

之后,分页。

我想自动打印这份报告 X 份。

PS:不能循环同一文档。我确实需要插入此文档的“份数”。

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

//NUMBER OF REPEAT
ArrayList array_qtd = new ArrayList();

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

JasperPrint printer = null;
printer = JasperFillManager.fillReport(file, parametros, dados_qtd);

//SHOW DIALOG REPORT
JRViewer view = new JRViewer(printer); //preview
JDialog dialog = new JDialog();

dialog.getContentPane().add(view);
dialog.setSize(600,300);
dialog.setLocationRelativeTo(jPanel2);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setModal(true);
dialog.setVisible(true);

//DIRECT PRINT
//JasperPrintManager.printReport(printer,false);
}//fim imprimir

最佳答案

已解决

$public void imprimir(String codigo, String tamanho, Integer qtd) 抛出 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

$

现在,我的问题是从远程计算机打印,本地网络中另一台计算机上的打印机。

此代码仅适用于本地计算机:

printServiceAttributeSet.add(new PrinterName("Argox OS-214 plus 系列 PPLA", Locale.getDefault()));

关于java - 打印 Jasper 报告/ireport 份数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com