Ìܼ¡ | Á°¤Î¹àÌÜ | ¼¡¤Î¹àÌÜ JavaTM °õºþ¥µ¡¼¥Ó¥¹ API ¥æ¡¼¥¶¥¬¥¤¥É


PrinterJob ¤ò»ÈÍѤ·¤¿¥°¥é¥Õ¥£¥Ã¥¯¥¹¤Î°õºþ¤Þ¤¿¤Ï¥¹¥È¥ê¡¼¥àÇÛ¿®

¿·¤·¤¤ API injava.awt.print ¤Ï¡¢¼¡¤Î¿·¤·¤¤ PrinterJob ¥á¥½¥Ã¥É¤«¤é¹½À®¤µ¤ì¤Þ¤¹¡£

¿·¤·¤¤ printDialog ¤ª¤è¤Ó pageDialog ¥á¥½¥Ã¥É¤Ë¤Ï°À­¥»¥Ã¥È¤ò»ØÄê¤Ç¤­¤ë¤¿¤á¡¢¥æ¡¼¥¶¤Ï¥À¥¤¥¢¥í¥°¤«¤é°À­¤Î½é´üÀßÄê¤òÊѹ¹¤Ç¤­¤Þ¤¹¡£

¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤«¤é PrinterJob ¤ò»ÈÍѤ¹¤ì¤Ð¡¢2D ¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò¥×¥ê¥ó¥¿¤Þ¤¿¤Ï½ÐÎÏ¥¹¥È¥ê¡¼¥à¤Ë°õºþ¤Ç¤­¤Þ¤¹¡£lookupPrintServices ¥á¥½¥Ã¥É¤Ï¡¢PrintService ¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£³Æ¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢2D ¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò°õºþ¤Ç¤­¤ë¥×¥ê¥ó¥¿¤òɽ¸½¤·¤Þ¤¹¡£lookupStreamPrintServices ¥á¥½¥Ã¥É¤Ï¡¢StreamPrintServiceFactory ¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£³Æ¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢StreamPrintService ¤òÊÖ¤¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤«¤é StreamPrintService ¤ò»ÈÍѤ¹¤ë¤È¡¢°õºþ¥Ç¡¼¥¿¤¬½ÐÎÏ¥¹¥È¥ê¡¼¥à¤ËÁ÷¿®¤µ¤ì¤Þ¤¹¡£StreamPrintService ¤Ç¤Ï¡¢¥É¥­¥å¥á¥ó¥È¤ò°õºþ¤¹¤ë°Ê³°¤Ë¡¢2D ¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò¾¤Î½ñ¼°¤ËÊÑ´¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤³¤³¤Ç¤Ï¡¢PrinterJob ¤ò»ÈÍѤ·¤Æ¡¢2D ¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò¥×¥ê¥ó¥¿¤Þ¤¿¤Ï½ÐÎÏ¥¹¥È¥ê¡¼¥à¤ËÁ÷¿®¤¹¤ëÊýË¡¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Þ¤¹¡£


2D ¥°¥é¥Õ¥£¥Ã¥¯¥¹¤Î°õºþ

¿·¤·¤¤ pageDialog¡¢printDialog¡¢¤ª¤è¤Ó pring ¥á¥½¥Ã¥É¤ò»ÈÍѤ¹¤ì¤Ð¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤«¤é°õºþÀßÄê¤ò½é´ü²½¤·¤Æ¥À¥¤¥¢¥í¥°¤ËÅϤ¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥æ¡¼¥¶¤Ï¡¢°õºþ¤ÎÀßÄêÃͤò¹¹¿·¤·¤Æ¤«¤é¡¢°õºþÍ×µá¤òÁ÷¿®¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥³¡¼¥ÉÎã¤òµó¤²¤Þ¤¹¡£

// Step 1: Set up initial print settings.
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
// Step 2: Obtain a print job.
PrinterJob pj = PrinterJob.getPrinterJob();
// Step 3: Find print services.
PrintService []services = PrinterJob.lookupPrintServices();
if (services.length > 0) {
	System.out.println("selected printer: " + services[0]);
	try {
	pj.setPrintService(service[0]); 
	// Step 2: Pass the settings to a page dialog and print dialog.
	pj.pageDialog(aset);
	if (pj.printDialog(aset)) {
		// Step 4: Update the settings made by the user in the dialogs.
		// Step 5: Pass the final settings into the print request.
		pj.print(aset);
	}
	} catch (PrinterException(pe)) {
		System.err.println(pe):
	}
} 

¥¢¥×¥ê¥±¡¼¥·¥ç¥óÁ´ÂΤˤĤ¤¤Æ¤Ï¡¢¡ÖÎã: Print2DPrinterJob.java¡×¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

¾å¤Î¥³¡¼¥ÉÎã¤Î¡ÖStep 4¡×¤Ï¡¢ÆÃÄê¤Î¥³¡¼¥É¹Ô¤ËÂбþ¤·¤Æ¤¤¤Þ¤»¤óáá×îŸíÕâ±â¹áA¥À¥¤¥¢¥í¥°Æâ¤Ç°õºþÀßÄê¤ò¹¹¿·¤·¡¢¹¹¿·¤·¤¿Ãͤ¬¡ÖPrintRequestAttributeSet, aset¡×¤ËÊݸ¤µ¤ì¤Þ¤¹¡£

¤³¤³¤Ç¡¢Java 2D ¤È Java °õºþ¥µ¡¼¥Ó¥¹¤ò»ÈÍѤ¹¤ë¤È¤­¤Ë¡¢°õºþÉô¿ô¤Ê¤É¤Î°À­¤òξÊý¤Î API ¤ËÄêµÁ¤·¤¿¾ì¹ç¤òÁÛÄꤷ¤Þ¤¹¡£¤³¤Î¤è¤¦¤Ê°À­¤ò PrintRequestAttributeSet ¤ËÄêµÁ¤·¤¿¾ì¹ç¤Ï¡¢PrinterJob ¤Ë»ØÄꤷ¤¿Æ±¤¸Â°À­¤¬Í¥À褵¤ì¤Þ¤¹¡£¥æ¡¼¥¶¤¬°õºþ¥À¥¤¥¢¥í¥°Æâ¤Ç°õºþÉô¿ô¤ò¹¹¿·¤·¤¿¾ì¹ç¤Ï¡¢PrinterJob ¤¬¼«Æ°Åª¤Ë¹¹¿·¤ª¤è¤ÓÈ¿±Ç¤µ¤ì¤Þ¤¹¡£¤³¤Î¤È¤­¡¢´û¸¤ÎÆ°ºî¤ÎºÆ³Îǧ¤ò¥æ¡¼¥¶¤ËÍ׵ᤷ¤Þ¤¹¡£

¤Þ¤¿¡¢PageFormat ¤Î»ÅÍͤ⡢Java °õºþ¥µ¡¼¥Ó¥¹¤Î Media¡¢MediaPrintableArea¡¢¤ª¤è¤Ó OrientationRequested °À­¤È½ÅÊ£¤·¤Æ¤¤¤Þ¤¹¡£¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤«¤é Printable ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤È print(PrintRequestAttributeSet) ¥á¥½¥Ã¥É¤ò»ÈÍѤ¹¤ë¤È¡¢Â°À­¥»¥Ã¥È¤Ë´Þ¤Þ¤ì¤ëÇÞÂΡ¢°õºþÊý¸þ¡¢¤ª¤è¤Ó¥¤¥á¡¼¥¸¥ó¥°²ÄǽÎΰè¤Î°À­¤¬¡¢¿·¤·¤¤ PageFormat ¤ËÄɲ䵤ì¤Þ¤¹¡£ PageFormat ¤Ï¡¢Printable ¥ª¥Ö¥¸¥§¥¯¥È¤Î°õºþ¥á¥½¥Ã¥É¤ËÅϤµ¤ì¤Þ¤¹¡£¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç Pageable ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò»ÈÍѤ·¤¿¾ì¹ç¤Ï¡¢PageFormat ¤ÏÊѹ¹¤µ¤ì¤Þ¤»¤ó¡£


2D ¥°¥é¥Õ¥£¥Ã¥¯¥¹¤Î¥¹¥È¥ê¡¼¥àÇÛ¿®

¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢PrinterJob ¤ª¤è¤Ó StreamPrintService ¤ò»ÈÍѤ·¤Æ¡¢°õºþ¥Ç¡¼¥¿¤ò½ÐÎÏ¥¹¥È¥ê¡¼¥à¤ËÁ÷¿®¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£¼¡¤ÎÎã¤ÏÁ°¤ÎÀá¤ÎÎã¤È»÷¤Æ¤¤¤Þ¤¹¤¬¡¢PrintService ¤ÎÂå¤ï¤ê¤Ë StreamPrintService ¤¬»ÈÍѤµ¤ì¤Æ¤¤¤Þ¤¹¡£

PrinterJob job = PrinterJob.getPrinterJob();
String psMimeType = "application/postscript";
FileOutputStream outstream; 
StreamPrintService psPrinter; 
StreamPrintServiceFactory []spsFactories =
	PrinterJob.lookupStreamPrintServices(psMimeType);
if (factories.length > 0) { 
	try { 
		outstream = new File("out.ps"); 
		psPrinter = factories[0].getPrintService(fos); 
		// psPrinter can now be set as the service on a PrinterJob 
	} catch (FileNotFoundException e) { } 
} 
job.setPrintService(service[0]); // if app wants to specify this printer.
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(2));
job.print(aset);
} 



Ìܼ¡ | Á°¤Î¹àÌÜ | ¼¡¤Î¹àÌÜ
Copyright © 2001 Sun Microsystems, Inc. All Rights Reserved.