本文整理匯總了Java中javax.print.attribute.PrintRequestAttributeSet.add方法的典型用法代碼示例。如果您正苦於以下問題:Java PrintRequestAttributeSet.add方法的具體用法?Java PrintRequestAttributeSet.add怎麽用?Java PrintRequestAttributeSet.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.print.attribute.PrintRequestAttributeSet
的用法示例。
在下文中一共展示了PrintRequestAttributeSet.add方法的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: 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();
}
}
示例3: 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");
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: print
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
/**
*
*/
public void print() throws JRException
{
long start = System.currentTimeMillis();
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A4);
PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
//printServiceAttributeSet.add(new PrinterName("Epson Stylus 820 ESC/P 2", null));
//printServiceAttributeSet.add(new PrinterName("hp LaserJet 1320 PCL 6", null));
//printServiceAttributeSet.add(new PrinterName("PDFCreator", null));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setExporterInput(new SimpleExporterInput("build/reports/PrintServiceReport.jrprint"));
SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
configuration.setDisplayPageDialog(false);
configuration.setDisplayPrintDialog(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
示例9: printTest
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
private static void printTest() {
PrinterJob pj = PrinterJob.getPrinterJob();
PageableHandler handler = new PageableHandler();
pj.setPageable(handler);
PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
pSet.add(DialogTypeSelection.COMMON);
pj.printDialog(pSet);
}
示例10: printTest
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
private static void printTest() {
PrinterJob job = PrinterJob.getPrinterJob();
if (job.getPrintService() == null) {
System.out.println("No printers. Test cannot continue");
return;
}
job.setPrintable(new DlgAttrsBug());
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(5));
aset.add(new PageRanges(3,4));
aset.add(DialogTypeSelection.NATIVE);
job.printDialog(aset);
}
示例11: printWithCustomImageareaSize
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
private static void printWithCustomImageareaSize() {
final JTable table = createAuthorTable(18);
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(DialogTypeSelection.NATIVE);
printAttributes.add(new Copies(1));
printAttributes.add(new MediaPrintableArea(
0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}")
);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog(printAttributes);
if (printAccepted) {
try {
job.print(printAttributes);
closeFrame();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("User cancels the printer job!");
}
}
示例12: main
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
public static void main(String args[]) {
PrinterJob job;
job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
// Here you could see the PageFormat with an empty PrintRequestAttributeSet
PageFormat pf2 = job.getPageFormat(pras);
System.out.println((pf2.getImageableX() / 72f) + " "
+ (pf2.getImageableY() / 72f) + " "
+ (pf2.getImageableWidth() / 72f) + " "
+ (pf2.getImageableHeight() / 72f)
);
// Set left margin to 2.0
pras.add(new MediaPrintableArea(2.0f,
(float)(pf2.getImageableY() / 72f),
(float) ((pf2.getImageableWidth() / 72f) - 1.0f),
(float) (pf2.getImageableHeight() / 72f),
MediaPrintableArea.INCH));
pf2 = job.getPageFormat(pras);
System.out.println((pf2.getImageableX() / 72f) + " "
+ (pf2.getImageableY() / 72f) + " "
+ (pf2.getImageableWidth() / 72f) + " "
+ (pf2.getImageableHeight() / 72f)
);
// check if returned left margin of imageable area is 2.0 as set earlier
if (pf2.getImageableX() / 72f != 2.0f) {
throw new RuntimeException("getPageFormat doesn't apply specified "
+ "MediaPrintableArea attribute");
}
}
示例13: main
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
public static void main(String args[]) {
PrinterJob job = PrinterJob.getPrinterJob();
if (job == null) {
return;
}
PrintRequestAttributeSet pSet =
new HashPrintRequestAttributeSet();
pSet.add(DialogTypeSelection.NATIVE);
job.printDialog(pSet);
try {
job.pageDialog(pSet);
} catch (StackOverflowError e) {
throw new RuntimeException("StackOverflowError is thrown");
}
}
示例14: printWorks
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
public void printWorks(String[] args)
{
PrinterJob job=PrinterJob.getPrinterJob();
job.setPrintable(this);
PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();
PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI);
if (args.length > 0 && (args[0].compareTo("600") == 0)) {
pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI);
System.out.println("Adding 600 Dpi attribute");
} else {
System.out.println("Adding 300 Dpi attribute");
}
PrintService ps = job.getPrintService();
boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null);
System.out.println("Is "+pr+" supported by "+ps+"? "+resolutionSupported);
if (resolutionSupported) {
System.out.println("Resolution is supported.\nTest is not applicable, PASSED");
}
settings.add(pr);
if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) {
settings.add(Fidelity.FIDELITY_TRUE);
System.out.println("Adding Fidelity.FIDELITY_TRUE attribute");
}
if (job.printDialog(settings))
{
try {
job.print(settings);
} catch (PrinterException e) {
e.printStackTrace();
}
}
}
示例15: printContent
import javax.print.attribute.PrintRequestAttributeSet; //導入方法依賴的package包/類
public void printContent() {
printStr = "打印測試內容";// 獲取需要打印的目標文本
if (printStr != null && printStr.length() > 0) // 當打印內容不為空時
{
PAGES = 1; // 獲取打印總頁數
// 指定打印輸出格式
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
// 定位默認的打印服務
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
// PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
// Toolkit.getDefaultToolkit().getPrintJob
// 創建打印作業
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
//PrintService service = ServiceUI.printDialog(null, 200, 200, printService, printService , flavor, pras);
//DocPrintJob job = printService.createPrintJob();
DocPrintJob job = service.createPrintJob();
// 設置打印屬性
// PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
// 設置紙張大小,也可以新建MediaSize類來自定義大小
pras.add(MediaSizeName.ISO_A4);
DocAttributeSet das = new HashDocAttributeSet();
// 指定打印內容
Doc doc = new SimpleDoc(this, flavor, das);
// 不顯示打印對話框,直接進行打印工作
try {
job.print(doc, pras); // 進行每一頁的具體打印操作
} catch (PrintException pe) {
pe.printStackTrace();
}
} else {
// 如果打印內容為空時,提示用戶打印將取消
JOptionPane.showConfirmDialog(null,"Sorry, Printer Job is Empty, Print Cancelled!", "Empty", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
}
}