本文整理汇总了Java中javax.print.attribute.PrintRequestAttributeSet类的典型用法代码示例。如果您正苦于以下问题:Java PrintRequestAttributeSet类的具体用法?Java PrintRequestAttributeSet怎么用?Java PrintRequestAttributeSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrintRequestAttributeSet类属于javax.print.attribute包,在下文中一共展示了PrintRequestAttributeSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printDocument
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
public static void printDocument() throws IOException, PrinterException
{
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(Sides.TWO_SIDED_SHORT_EDGE);
PDDocument input = PDDocument.load(new File("Karteikarten.pdf"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(input));
if (job.printDialog(pras)) {
job.print(pras);
}
}
示例2: printWorksheetLevel
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
public void printWorksheetLevel() {
PrinterJob print = PrinterJob.getPrinterJob();
PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
set.add(OrientationRequested.LANDSCAPE);
print.setPrintable(oscilloscope);
if(print.printDialog(set))
try { print.print(); }
catch(PrinterException e) {}
}
示例3: _printCrossPlatform
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
/** Print using the cross platform dialog.
* FIXME: this dialog is slow and is often hidden
* behind other windows. However, it does honor
* the user's choice of portrait vs. landscape
*/
protected void _printCrossPlatform() {
// Build a set of attributes
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(plot);
if (job.printDialog(aset)) {
try {
job.print(aset);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Printing failed:\n" + ex.toString(),
"Print Error", JOptionPane.WARNING_MESSAGE);
}
}
}
示例4: pageableJob
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的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;
}
}
示例5: addPaperSize
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
private void addPaperSize(PrintRequestAttributeSet aset,
int dmIndex, int width, int length) {
if (aset == null) {
return;
}
MediaSizeName msn =
((Win32PrintService)myService).findWin32Media(dmIndex);
if (msn == null) {
msn = ((Win32PrintService)myService).
findMatchingMediaSizeNameMM((float)width, (float)length);
}
if (msn != null) {
aset.add(msn);
}
}
示例6: setAttributes
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
@Override
protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
super.setAttributes(attributes);
if (attributes == null) {
return;
}
PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class);
if (isSupportedValue(pageRangesAttr, attributes)) {
SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class);
// If rangeSelect is not null, we are using AWT's print dialog that has
// All, Selection, and Range radio buttons
if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) {
int[][] range = pageRangesAttr.getMembers();
// setPageRange will set firstPage and lastPage as called in getFirstPage
// and getLastPage
setPageRange(range[0][0] - 1, range[0][1] - 1);
}
}
}
示例7: printWithoutPrintDialog
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
private static void printWithoutPrintDialog() {
final JTable table = createAuthorTable(42);
PrintRequestAttributeSet pras
= new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
try {
boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"),
false, pras, false);
closeFrame();
if (!printAccepted) {
throw new RuntimeException("User cancels the printer job!");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: setAttributes
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
@Override
protected void setAttributes(PrintRequestAttributeSet attributes)
throws PrinterException {
super.setAttributes(attributes);
if (attributes == null) {
return; // now always use attributes, so this shouldn't happen.
}
Attribute attr = attributes.get(Media.class);
if (attr instanceof CustomMediaTray) {
CustomMediaTray customTray = (CustomMediaTray)attr;
String choice = customTray.getChoiceName();
if (choice != null) {
mOptions = " InputSlot="+ choice;
}
}
}
示例9: setAttributes
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
@Override
protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
super.setAttributes(attributes);
if (attributes == null) {
return;
}
PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class);
if (isSupportedValue(pageRangesAttr, attributes)) {
SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class);
// If rangeSelect is not null, we are using AWT's print dialog that has
// All, Selection, and Range radio buttons
if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) {
int[][] range = pageRangesAttr.getMembers();
// setPageRange will set firstPage and lastPage as called in getFirstPage
// and getLastPage
setPageRange(range[0][0] - 1, range[0][1] - 1);
} else {
// if rangeSelect is SunPageSelection.ALL
// then setPageRange appropriately
setPageRange(-1, -1);
}
}
}
示例10: printWithoutPrintDialog
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
private static void printWithoutPrintDialog() {
final JTable table = createAuthorTable(50);
PrintRequestAttributeSet pras
= new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
try {
boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"),
false, pras, false);
closeFrame();
if (!printAccepted) {
throw new RuntimeException("User cancels the printer job!");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: doTest
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
private static void doTest() {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(Chromaticity.MONOCHROME);
MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
Paper paper = new Paper();
paper.setSize(size[0] * 72.0, size[1] * 72.0);
paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
PageFormat pf = new PageFormat();
pf.setPaper(paper);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
if (job.printDialog()) {
try {
job.print(aset);
} catch (PrinterException pe) {
throw new RuntimeException(pe);
}
}
}
示例12: main
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String[] instructions =
{
"Visual inspection of the dialog is needed. ",
"It should be a Printer Job Setup Dialog",
"Do nothing except Cancel",
"You must NOT press OK",
};
SwingUtilities.invokeAndWait(() -> {
JOptionPane.showMessageDialog(
(Component) null,
instructions,
"information", JOptionPane.INFORMATION_MESSAGE);
});
PrinterJob pj = PrinterJob.getPrinterJob();
PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
pSet.add(DialogTypeSelection.NATIVE);
if ((pj.pageDialog(pSet)) != null) {
throw
new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
+ " does not return null when dialog is cancelled");
}
}
示例13: printTest
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
private static void printTest() {
MediaTray tray = null;
//tray = getMediaTray( prservices, "Bypass Tray" );
tray = getMediaTray( prservices, "Tray 4" );
PrintRequestAttributeSet atrset = new HashPrintRequestAttributeSet();
//atrset.add( MediaSizeName.ISO_A4 );
atrset.add(tray);
PrinterJob pjob = PrinterJob.getPrinterJob();
pjob.setPrintable(new TestMediaTraySelection());
try {
pjob.print(atrset);
} catch (PrinterException e) {
e.printStackTrace();
fail();
}
}
示例14: print
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的package包/类
public void print() {
getPrintJob().setPrintable(this, getPage());
boolean res;
PrintRequestAttributeSet attr_set
= new HashPrintRequestAttributeSet();
if (page_range.x == 0) {
res = getPrintJob().printDialog();
} else {
PrintRequestAttributeSet attr_set2
= new HashPrintRequestAttributeSet();
attr_set2.add(new PageRanges(page_range.x, page_range.y));
res = getPrintJob().printDialog(attr_set2);
}
if (res) {
try {
getPrintJob().print(attr_set);
} catch (PrinterException pe) {
System.out.println("Error printing: " + pe);
}
//page = getPrintJob().getPageFormat(null);
}
}
示例15: actionPerformed
import javax.print.attribute.PrintRequestAttributeSet; //导入依赖的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);
}
}