本文介绍了贾斯珀报告。如何使用指定的打印机驱动程序打印到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在控制面板中,我的打印机端口配置为文件:。
例如,我可以使用 PrintServiceAttributeSet 选择打印机,但打印时无法设置输出文件名。我不使用 JRXlsExporter JRPdfExporter 或类似的东西,只需 JRPrintServiceExporter

In Control Panel my printer's port was configured to "FILE:".For example, I can select a printer using PrintServiceAttributeSet, but there is no way to set an output filename when printing. I don't use JRXlsExporter or JRPdfExporter or something like that, just JRPrintServiceExporter.

  PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
  printServiceAttributeSet.add(new PrinterName("Xerox DocuPrint 100 EPS PS3", null));
  //...
  exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
  exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
  //...
  exporter.exportReport();

驱动程序在PostScript中输出文件,但始终显示输出文件名窗口。如果我手动在窗口中设置文件名,则打印机会成功打印到文件。

The driver outputs files in PostScript, but a window "Output file name" appears all the time. If I set a filename in the window manually, then printer prints to a file successfully.

知道如何以编程方式设置文件名吗?

Any idea how to set a filename programmatically?

推荐答案

javax.print.attribute.standard »有帮助。

解决方案:

  //...
  import javax.print.attribute.standard.Destination;
  //...

  JRExporter exporter = new JRPrintServiceExporter();

  //--- Set print properties
  PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
  printRequestAttributeSet.add(MediaSizeName.ISO_A4);

  //----------------------------------------------------
  printRequestAttributeSet.add(new Destination(new java.net.URI("file:d:/output/report.ps")));
  //----------------------------------------------------

  PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
  printServiceAttributeSet.add(new PrinterName("Xerox DocuPrint 100 EPS PS3", null));

  //--- Set print parameters
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
  exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
  exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
  exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
  exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);

  //--- Print the document
  try{
      exporter.exportReport();
  }
  catch(JRException e){
      e.printStackTrace();
  }

这篇关于贾斯珀报告。如何使用指定的打印机驱动程序打印到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:34