Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2016 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package net.sf.jasperreports.engine.export;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.ArrayList;
import java.util.List;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.Attribute;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.HashPrintServiceAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.PrintServiceAttributeSet;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.OrientationRequested;
import javax.print.attribute.standard.PageRanges;
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
import net.sf.jasperreports.engine.DefaultJasperReportsContext;
import net.sf.jasperreports.engine.JRAbstractExporter;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRPropertiesUtil;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.print.JRPrinterAWT;
import net.sf.jasperreports.export.ExporterInputItem;
import net.sf.jasperreports.export.ExporterOutput;
import net.sf.jasperreports.export.PrintServiceExporterConfiguration;
import net.sf.jasperreports.export.PrintServiceReportConfiguration;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleGraphics2DExporterOutput;
import net.sf.jasperreports.export.SimpleGraphics2DReportConfiguration;
/**
* Prints a JasperReports document using the Java Print Service API.
*
* There are four ways of using the Java Print Service with the Java 2D API:
*
*
Printing 2D graphics using java.awt.print.PrinterJob
*
Streaming 2D graphics using java.awt.print.PrinterJob
*
Printing 2D graphics using javax.print.DocPrintJob and a service-formatted javax.print.DocFlavor
*
Streaming 2D graphics using javax.print.DocPrintJob and a service-formatted javax.print.DocFlavor
*
*
* The {@link net.sf.jasperreports.engine.export.JRPrintServiceExporter}
* implementation takes the first approach and uses some of the methods added to the
* java.awt.print.PrinterJob class:
*
*
Static convenience methods to look up print services that can image 2D graphics,
* which are returned as an array of PrintService or
* StreamPrintServiceFactory objects depending on the method
*
Methods to set and get a PrintService on a PrinterJob
*
A pageDialog() method that takes a PrintRequestAttributeSet parameter
*
A printDialog()() method that takes a PrintRequestAttributeSet parameter
*
A print method that takes a PrintRequestAttributeSet parameter
*
*
Looking Up a Printing Service
* This exporter tries to find a print service that supports the necessary attributes. The set of
* attributes can be supplied to the exporter in the form of a
* javax.print.attribute.PrintServiceAttributeSet object that is passed as the
* value for the special
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#getPrintServiceAttributeSet() getPrintServiceAttributeSet()}
* exporter configuration setting. For more
* details about the attributes that can be part of such an attribute set, check the Java Print
* Service API documentation.
*
* The lookup procedure might return one or more print services able to handle the
* specified print service attributes. If so, the exporter uses the first one in the list. If no
* suitable print service is found, then the exporter throws an exception. As an alternative, a
* javax.print.PrintService instance can be passed in using the
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#getPrintService() getPrintService()}
* exporter configuration setting when users do not want the Java Print Service to search for an
* available print service.
*
Configuring the Printer Job
* Once a print service has been located, it is associated with a PrinterJob instance.
* Further customization is made by passing a
* javax.print.attribute.PrintRequestAttributeSet instance when calling the
* print() method on the PrinterJob object to start the printing process.
*
* To supply the javax.print.attribute.PrintRequestAttributeSet object
* containing the desired javax.print.attribute.PrintRequestAttribute values to
* the exporter, set the special
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#getPrintRequestAttributeSet() getPrintRequestAttributeSet()}
* exporter configuration setting.
*
Displaying Print Dialogs
* If this exporter is invoked by a desktop or client-side Java application, you can offer the
* end user a final chance to customize the printer job before the printing process actually
* starts. The exporter has two other predefined configuration settings:
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPageDialog() isDisplayPageDialog()}
* and
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPrintDialog() isDisplayPrintDialog()},
* both receiving java.lang.Boolean values, which show or
* suppress the page dialog and/or the print dialog associated with the PrinterJob
* instance.
*
* The two dialogs are cross-platform. They enable users to alter the print service attributes
* and the print request attributes that are already set for the current print service and printer
* job. They also allow canceling the current printing procedure altogether. When batch
* printing a set of documents, if
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPageDialog() isDisplayPageDialog()} or
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPrintDialog() isDisplayPrintDialog()} are
* set to true, a dialog window will pop up each time a document in the list is to be
* printed. This is very useful if you intend to set different printing options for each
* document. However, setting the same page/printing options each time would quickly
* become cumbersome. If same settings are intended for all documents in the list, the
* exporter provides two additional predefined export configuration settings:
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPageDialogOnlyOnce() isDisplayPageDialogOnlyOnce()} and
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPrintDialogOnlyOnce() isDisplayPrintDialogOnlyOnce()}. These
* are only effective if the corresponding
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPageDialog() isDisplayPageDialog()} or
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPrintDialog() isDisplayPrintDialog()} are
* set to true.
*
* If {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPageDialogOnlyOnce() isDisplayPageDialogOnlyOnce()}
* is true, then the page dialog will open only
* once, and the export options set within will be preserved for all documents in the list.
* The same thing happens when
* {@link net.sf.jasperreports.export.PrintServiceExporterConfiguration#isDisplayPrintDialogOnlyOnce() isDisplayPrintDialogOnlyOnce()}
* is set to true - the print dialog will open only once.
*
* Below is an example of configuring the print service exporter taken from the supplied
* /demo/ samples/printservice sample:
*