format.add(new JobName(jobName, null));
jobAttrs.add(new JobName(jobName, null)); if (endUserName != null && queue.isAttributeCategorySupported(RequestingUserName.class))
jobAttrs.add(new JobName(jobName, null)); if (endUserName != null && queue.isAttributeCategorySupported(RequestingUserName.class))
public void print() throws IOException, PrintException { DocFlavor inputFlavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8; // Lookup a print factory to convert from desired input to output. StreamPrintServiceFactory[] psfactories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories( inputFlavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); if (psfactories.length == 0) { System.err.println("Ack! No StreamPrintFactory found for this job!"); } StreamPrintService printService = psfactories[0].getPrintService(new FileOutputStream("demo.ps")); PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet(); attrs.add(OrientationRequested.LANDSCAPE); attrs.add(MediaSizeName.NA_LETTER); attrs.add(new Copies(1)); attrs.add(new JobName(INPUT_FILE_NAME, null)); InputStream is = getClass().getResourceAsStream(INPUT_FILE_NAME); if (is == null) { throw new NullPointerException( "Input Stream is null: file not found?"); } Doc doc = new SimpleDoc(is, inputFlavor, null); DocPrintJob printJob = printService.createPrintJob(); printJob.print(doc, attrs); } }
/** * Asks the user for a printer and settings and return the pageformat.<br> * Does not print! Use {@link #printJob(java.awt.print.PrinterJob, javax.print.attribute.PrintRequestAttributeSet, boolean)} to print. * * @param job is the new printerjob * @param jobName is the jobname, null = none * @param aset is an initialized (and possibly empty) attribute set, must not be null, because its returned! * @return the pageformat and possibly updated aset, null if printing aborted */ public static PageFormat print(PrinterJob job, String jobName, PrintRequestAttributeSet aset) { if (aset.get(Media.class) == null) { aset.add(mediaSizeName); } if (aset.get(MediaPrintableArea.class) == null) { aset.add(area); } if (jobName != null) { aset.add(new JobName(jobName, Locale.getDefault())); job.setJobName(jobName); } if (job.printDialog(aset)) { return getPageFormat(aset); } return null; }
/** * Asks the user for a printer and settings and prints a printable. * * @param printable the printable * @param jobName the name of the job * @return true if printed, false if error or user aborted */ public static boolean print(Printable printable, String jobName) { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(mediaSizeName); aset.add(area); PrinterJob job = PrinterJob.getPrinterJob(); if (jobName != null) { aset.add(new JobName(jobName, Locale.getDefault())); job.setJobName(jobName); } job.setPrintable(printable); if (job.printDialog(aset)) { try { // this does the trick to use the format of the print dialog! job.print(aset); return true; } catch(PrinterException pe) { FormError.showException(PrintSwingPrintBundle.getString("PRINTING FAILED!"), pe); } } return false; }