本文整理汇总了Java中javax.print.attribute.HashPrintRequestAttributeSet类的典型用法代码示例。如果您正苦于以下问题:Java HashPrintRequestAttributeSet类的具体用法?Java HashPrintRequestAttributeSet怎么用?Java HashPrintRequestAttributeSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HashPrintRequestAttributeSet类属于javax.print.attribute包,在下文中一共展示了HashPrintRequestAttributeSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printDocument
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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.HashPrintRequestAttributeSet; //导入依赖的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.HashPrintRequestAttributeSet; //导入依赖的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: updatePageAttributes
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的package包/类
protected void updatePageAttributes(PrintService service,
PageFormat page) {
if (this.attributes == null) {
this.attributes = new HashPrintRequestAttributeSet();
}
updateAttributesWithPageFormat(service, page, this.attributes);
}
示例5: printWithoutPrintDialog
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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);
}
}
示例6: main
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
GraphicsEnvironment.getLocalGraphicsEnvironment();
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
StreamPrintServiceFactory[] factories =
StreamPrintServiceFactory.
lookupStreamPrintServiceFactories(flavor, mime);
if (factories.length == 0) {
System.out.println("No print service found.");
return;
}
FileOutputStream output = new FileOutputStream("out.ps");
StreamPrintService service = factories[0].getPrintService(output);
SimpleDoc doc =
new SimpleDoc(new PrintSEUmlauts(),
DocFlavor.SERVICE_FORMATTED.PRINTABLE,
new HashDocAttributeSet());
DocPrintJob job = service.createPrintJob();
job.addPrintJobListener(new PrintJobAdapter() {
@Override
public void printJobCompleted(PrintJobEvent pje) {
testPrintAndExit();
}
});
job.print(doc, new HashPrintRequestAttributeSet());
}
示例7: printWithoutPrintDialog
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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);
}
}
示例8: doTest
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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);
}
}
}
示例9: init
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的package包/类
private static void init()
{
//*** Create instructions for the user here ***
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",
};
Sysout.createDialog( );
Sysout.printInstructions( instructions );
PrinterJob pjob = PrinterJob.getPrinterJob();
boolean rv = pjob.printDialog(new HashPrintRequestAttributeSet());
if (rv) {
throw new RuntimeException("User pressed cancel, but true returned");
}
}
示例10: main
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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");
}
}
示例11: main
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
String[] instructions
= {
"Select Pages Range From instead of All in print dialog. ",
"Then select Print"
};
SwingUtilities.invokeAndWait(() -> {
JOptionPane.showMessageDialog((Component) null,
instructions, "Instructions",
JOptionPane.INFORMATION_MESSAGE);
});
HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
PrinterJob j = PrinterJob.getPrinterJob();
j.setPageable(new PrintAttributeUpdateTest());
as.add(DialogTypeSelection.NATIVE);
j.printDialog(as);
if (as.containsKey(PageRanges.class) == false) {
throw new RuntimeException("Print Dialog did not update "
+ " attribute set with page range");
}
Attribute attrs[] = as.toArray();
for (int i = 0; i < attrs.length; i++) {
System.out.println("attr " + attrs[i]);
}
j.print(as);
}
示例12: printTest
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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();
}
}
示例13: printTest
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的package包/类
/**
* Starts the application.
*/
public static void printTest() {
System.out.println("\nDefault print service: " +
PrintServiceLookup.lookupDefaultPrintService());
System.out.println("is flavor: "+flavor+" supported? "+
services[0].isDocFlavorSupported(flavor));
System.out.println("is Page Ranges category supported? "+
services[0].isAttributeCategorySupported(PageRanges.class));
System.out.println("is PageRanges[2] value supported ? "+
services[0].isAttributeValueSupported(
new PageRanges(2), flavor, null));
HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
//prSet.add(new PageRanges(2));
PrintService selService = ServiceUI.printDialog(null, 200, 200,
services, services[0], flavor, prSet);
System.out.println("\nSelected Values\n");
Attribute attr[] = prSet.toArray();
for (int x = 0; x < attr.length; x ++) {
System.out.println("Attribute: " + attr[x].getName() +
" Value: " + attr[x]);
}
}
示例14: print
import javax.print.attribute.HashPrintRequestAttributeSet; //导入依赖的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.HashPrintRequestAttributeSet; //导入依赖的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);
}
}