本文整理匯總了Java中javax.print.PrintException類的典型用法代碼示例。如果您正苦於以下問題:Java PrintException類的具體用法?Java PrintException怎麽用?Java PrintException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PrintException類屬於javax.print包,在下文中一共展示了PrintException類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pageableJob
import javax.print.PrintException; //導入依賴的package包/類
public void pageableJob(Pageable pageable,
PrintRequestAttributeSet attributes)
throws PrintException {
try {
synchronized(this) {
if (job != null) { // shouldn't happen
throw new PrintException("already printing");
} else {
job = new PSPrinterJob();
}
}
job.setPrintService(getPrintService());
job.setPageable(pageable);
job.print(attributes);
notifyEvent(PrintJobEvent.JOB_COMPLETE);
return;
} catch (PrinterException pe) {
notifyEvent(PrintJobEvent.JOB_FAILED);
throw new PrintException(pe);
} finally {
printReturned = true;
}
}
示例2: pageableJob
import javax.print.PrintException; //導入依賴的package包/類
public void pageableJob(Pageable pageable) throws PrintException {
try {
synchronized(this) {
if (job != null) { // shouldn't happen
throw new PrintException("already printing");
} else {
job = new PSPrinterJob();
}
}
job.setPrintService(getPrintService());
job.setCopies(copies);
job.setJobName(jobName);
job.setPageable(pageable);
job.print(reqAttrSet);
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
return;
} catch (PrinterException pe) {
notifyEvent(PrintJobEvent.JOB_FAILED);
throw new PrintException(pe);
} finally {
printReturned = true;
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
}
}
示例3: run
import javax.print.PrintException; //導入依賴的package包/類
public Object run() {
try {
if (mDestType == UnixPrintJob.DESTFILE) {
spoolFile = new File(mDestination);
} else {
/* Write to a temporary file which will be spooled to
* the printer then deleted. In the case that the file
* is not removed for some reason, request that it is
* removed when the VM exits.
*/
spoolFile = Files.createTempFile("javaprint", "").toFile();
spoolFile.deleteOnExit();
}
result = new FileOutputStream(spoolFile);
return result;
} catch (IOException ex) {
// If there is an IOError we subvert it to a PrinterException.
notifyEvent(PrintJobEvent.JOB_FAILED);
pex = new PrintException(ex);
}
return null;
}
示例4: run
import javax.print.PrintException; //導入依賴的package包/類
public OutputStream run() {
try {
if (mDestType == UnixPrintJob.DESTFILE) {
spoolFile = new File(mDestination);
} else {
/* Write to a temporary file which will be spooled to
* the printer then deleted. In the case that the file
* is not removed for some reason, request that it is
* removed when the VM exits.
*/
spoolFile = Files.createTempFile("javaprint", "").toFile();
spoolFile.deleteOnExit();
}
result = new FileOutputStream(spoolFile);
return result;
} catch (IOException ex) {
// If there is an IOError we subvert it to a PrinterException.
notifyEvent(PrintJobEvent.JOB_FAILED);
pex = new PrintException(ex);
}
return null;
}
示例5: actionPerformed
import javax.print.PrintException; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent e)
{
try {
if (selectedDriver == null)
return;
PrintService ps = (PrintService)printers.getSelectedItem();
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
attr.add(new Copies(1));
attr.add((Media)ps.getDefaultAttributeValue(Media.class)); // set to default paper from printer
attr.add(OrientationRequested.LANDSCAPE);
SimpleDoc doc = new SimpleDoc(activeLabel, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
ps.createPrintJob().print(doc, attr);
} catch (PrintException ex) {
log.log(Level.SEVERE, "\bBarcode print failed: " + ex.getMessage(), ex);
}
}
示例6: printReport
import javax.print.PrintException; //導入依賴的package包/類
/**
* Prints the given string either the appropriate printer name (from
* the computers table), or the default printer on the server.
* @param reportText Text of report
* @param clientIPAddress Client computer's IP address
* @return String Result message
*/
public String printReport(String reportText, String clientIPAddress) {
if (enablePrintingFromServer != null && enablePrintingFromServer) {
Computer client = computerService.findComputerByIP(clientIPAddress);
ReportPrintFormatter formatter =
new ReportPrintFormatter(reportText, client.getxOffset(), client.getyOffset());
try {
printDocument(formatter.getStream(), client.getPrinterName(), false);
return "Printed to " + client.getPrinterName();
} catch (PrintException e) {
log.error(String.format("Error printing report for %s: %s",
clientIPAddress, e.getMessage()), e);
return("Error printing. No printers found? More information in server logs");
}
} else {
return("Printing from server not enabled.");
}
}
示例7: print
import javax.print.PrintException; //導入依賴的package包/類
/**
* Prints the pages.
*/
public void print() throws PrinterException
{
if( printable == null && pageable == null ) // nothing to print?
return;
PostScriptGraphics2D pg = new PostScriptGraphics2D( this );
SpooledDocument doc = pg.spoolPostScript( printable, pageFormat,
pageable );
cancelled = false;
printJob = printer.createPrintJob();
try
{
printJob.print(doc, attributes);
}
catch (PrintException pe)
{
PrinterException p = new PrinterException();
p.initCause(pe);
throw p;
}
// no printjob active.
printJob = null;
}
示例8: assignPrintAttributes
import javax.print.PrintException; //導入依賴的package包/類
private PrintRequestAttributeSet assignPrintAttributes() throws PrintException {
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
if (config.getCopies() >= 1) {
printRequestAttributeSet.add(new Copies(config.getCopies()));
} else {
throw new PrintException("Number of print copies should be greater than zero");
}
printRequestAttributeSet.add(config.getMediaSizeName());
printRequestAttributeSet.add(config.getInternalSides());
printRequestAttributeSet.add(config.getInternalOrientation());
if (config.getMediaTray() != null) {
MediaTray mediaTray = resolveMediaTray(config.getMediaTray());
if (mediaTray == null) {
throw new PrintException("mediatray not found " + config.getMediaTray());
}
printRequestAttributeSet.add(mediaTray);
}
return printRequestAttributeSet;
}
示例9: print
import javax.print.PrintException; //導入依賴的package包/類
/**
* Prints the pages.
*/
public void print() throws PrinterException
{
if( printable == null && pageable == null ) // nothing to print?
return;
PostScriptGraphics2D pg = new PostScriptGraphics2D( this );
SpooledDocument doc = pg.spoolPostScript( printable, pageFormat,
pageable );
cancelled = false;
printJob = printer.createPrintJob();
try
{
printJob.print(doc, attributes);
}
catch (PrintException pe)
{
PrinterException p = new PrinterException();
p.initCause(pe);
throw p;
}
// no printjob active.
printJob = null;
}
示例10: run
import javax.print.PrintException; //導入依賴的package包/類
public Object run() {
try {
if (mDestType == UnixPrintJob.DESTFILE) {
spoolFile = new File(mDestination);
} else {
/* Write to a temporary file which will be spooled to
* the printer then deleted. In the case that the file
* is not removed for some reason, request that it is
* removed when the VM exits.
*/
spoolFile = File.createTempFile("javaprint", ".ps", null);
spoolFile.deleteOnExit();
}
result = new FileOutputStream(spoolFile);
return result;
} catch (IOException ex) {
// If there is an IOError we subvert it to a PrinterException.
notifyEvent(PrintJobEvent.JOB_FAILED);
pex = new PrintException(ex);
}
return null;
}
示例11: print
import javax.print.PrintException; //導入依賴的package包/類
public void print(final Doc doc, final PrintRequestAttributeSet attributes)
throws PrintException {
synchronized (lock) {
if (printer != null) {
throw new PrintException("Printer is busy"); //$NON-NLS-1$
} else {
final DocFlavor flavor = doc.getDocFlavor();
if ((flavor == null) || !service.isDocFlavorSupported(flavor)) {
throw new PrintException("Doc flavor is not supported"); //$NON-NLS-1$
}
printer = new Printer(doc, attributes);
printer.print();
}
}
}
示例12: getPrinterState
import javax.print.PrintException; //導入依賴的package包/類
public static PrinterState getPrinterState(final long handle)
throws PrintException {
final long status = getPrinterStatus(handle);
if ((status & (PRINTER_STATUS_PRINTING | PRINTER_STATUS_PROCESSING)) != 0) {
return PrinterState.PROCESSING;
} else if ((status & (PRINTER_STATUS_DOOR_OPEN | PRINTER_STATUS_ERROR
| PRINTER_STATUS_NO_TONER
| PRINTER_STATUS_NOT_AVAILABLE | PRINTER_STATUS_OFFLINE
| PRINTER_STATUS_OUT_OF_MEMORY
| PRINTER_STATUS_OUTPUT_BIN_FULL
| PRINTER_STATUS_PAPER_JAM | PRINTER_STATUS_PAPER_OUT
| PRINTER_STATUS_PAPER_PROBLEM | PRINTER_STATUS_USER_INTERVENTION)) != 0) {
return PrinterState.STOPPED;
} else if ((status & PRINTER_STATUS_SERVER_UNKNOWN) != 0) {
return PrinterState.UNKNOWN;
} else {
return PrinterState.IDLE;
}
}