本文整理汇总了Java中javax.print.attribute.HashDocAttributeSet类的典型用法代码示例。如果您正苦于以下问题:Java HashDocAttributeSet类的具体用法?Java HashDocAttributeSet怎么用?Java HashDocAttributeSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashDocAttributeSet类属于javax.print.attribute包,在下文中一共展示了HashDocAttributeSet类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import javax.print.attribute.HashDocAttributeSet; //导入依赖的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());
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:PrintSEUmlauts.java
示例2: printText2Action
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
private void printText2Action()
{
printStr = area.getText().trim();
if(printStr != null && printStr.length() > 0)
{
PAGES = getPagesCount(printStr);
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
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", -1, 2);
}
}
开发者ID:h819,项目名称:spring-boot,代码行数:26,代码来源:PrintTest.java
示例3: PrintHelper
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
/**
* Creates a new <code>PrintHelper</code> instance using the specified
* doc and print attribute sets. This constructor offers the most flexibility
* as it allows the attributes sets to be pre configured. This method
* should only be used by advanced users.
*
* @param container parent container uses to center print dialog.
* @param pageTree document page tree.
* @param userRotation rotation of view
* @param docAttributeSet MediaSizeName constant of paper size to print to.
* @param printRequestAttributeSet quality of the print job, draft, quality etc.
*/
public PrintHelper(Container container, PageTree pageTree,
float userRotation,
HashDocAttributeSet docAttributeSet,
HashPrintRequestAttributeSet printRequestAttributeSet) {
this.container = container;
this.pageTree = pageTree;
this.userRotation = userRotation;
// blindly assign doc and print attribute sets.
this.docAttributeSet = docAttributeSet;
this.printRequestAttributeSet = printRequestAttributeSet;
// find available printers
services = lookForPrintServices();
// default setup, all pages, shrink to fit and no dialog.
setupPrintService(0, this.pageTree.getNumberOfPages(), 1, true, false);
}
开发者ID:pdf4j,项目名称:icepdf,代码行数:28,代码来源:PrintHelper.java
示例4: printContent
import javax.print.attribute.HashDocAttributeSet; //导入依赖的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);
}
}
开发者ID:h819,项目名称:spring-boot,代码行数:38,代码来源:LocatePrint.java
示例5: printFileAction
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
private void printFileAction()
{
// 构造一个文件选择器,默认为当前目录
JFileChooser fileChooser = new JFileChooser();
int state = fileChooser.showOpenDialog(null);//弹出文件选择对话框
if (state == fileChooser.APPROVE_OPTION)//如果用户选定了文件
{
File file = fileChooser.getSelectedFile();//获取选择的文件
//构建打印请求属性集
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//设置打印格式,因为未确定文件类型,这里选择AUTOSENSE
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//查找所有的可用打印服务
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
//定位默认的打印服务
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
//显示打印对话框
PrintService service = ServiceUI.printDialog(null, 200, 200, printService
, defaultService, flavor, pras);
if (service != null)
{
try
{
DocPrintJob job = service.createPrintJob();//创建打印作业
FileInputStream fis = new FileInputStream(file);//构造待打印的文件流
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);//建立打印文件格式
job.print(doc, pras);//进行文件的打印
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
开发者ID:h819,项目名称:spring-boot,代码行数:39,代码来源:LocatePrint.java
示例6: printFileAction
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
private void printFileAction()
{
JFileChooser fileChooser = new JFileChooser(System.getProperty("USER_DIR"));
// fileChooser.setFileFilter(new JavaFilter());
int state = fileChooser.showOpenDialog(this);
if(state == 0)
{
File file = fileChooser.getSelectedFile();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if(service != null)
try
{
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(file);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
开发者ID:h819,项目名称:spring-boot,代码行数:29,代码来源:PrintTest.java
示例7: testLookupMultiDocPrintServices
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testLookupMultiDocPrintServices() throws Exception {
System.out
.println("============= START LookupMultiDocPrintServicesTest ================");
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
MultiDocPrintService[] services;
FileInputStream fis;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
aset.add(new Copies(2));
aset.add(MediaSizeName.ISO_A4);
daset.add(MediaName.ISO_A4_WHITE);
daset.add(Sides.TWO_SIDED_LONG_EDGE);
services = PrintServiceLookup.lookupMultiDocPrintServices(
new DocFlavor[] { psFlavor }, aset);
if (services != null && services.length > 0) {
fis = new FileInputStream("/Resources/1M.GIF");
doc = new SimpleDoc(fis, psFlavor, daset);
pj = services[0].createPrintJob();
pj.print(doc, aset);
System.out.println(fis.toString() + " printed on "
+ services[0].getName());
} else {
System.out.println("services not found");
}
System.out.println("============= END LookupMultiDocPrintServicesTest ================");
}
开发者ID:shannah,项目名称:cn1,代码行数:34,代码来源:LookupMultiDocPrintServicesTest.java
示例8: testPrintJpeg
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testPrintJpeg() throws Exception {
System.out.println("======== START PrintJpegTest ========");
PrintService[] services;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
daset.add(MediaSizeName.ISO_A4);
DocFlavor df = DocFlavor.INPUT_STREAM.JPEG;
InputStream fis = this.getClass().getResourceAsStream(
"/Resources/JPEG.jpg");
services = PrintServiceLookup.lookupPrintServices(df, aset);
TestUtil.checkServices(services);
for (int j = 0; j < services.length; j++) {
PrintService printer = services[j];
if (printer.toString().indexOf("print-to-file") >= 0) {
doc = new SimpleDoc(fis, df, daset);
pj = printer.createPrintJob();
pj.print(doc, aset);
System.out.println(fis.toString() + " printed on "
+ printer.getName());
break;
}
}
System.out.println("====== END PrintJpegTest ========");
}
开发者ID:shannah,项目名称:cn1,代码行数:33,代码来源:PrintJpegTest.java
示例9: testLookupDefaultPrintService
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testLookupDefaultPrintService() throws Exception {
System.out
.println("======= START LookupDefaultPrintServiceTest ======");
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
PrintService service;
InputStream fis;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
aset.add(new Copies(2));
aset.add(MediaSizeName.ISO_A4);
daset.add(MediaName.ISO_A4_WHITE);
daset.add(Sides.TWO_SIDED_LONG_EDGE);
service = PrintServiceLookup.lookupDefaultPrintService();
if (service != null) {
if (service.isDocFlavorSupported(psFlavor)) {
if (service.getUnsupportedAttributes(psFlavor, aset)==null) {
fis = this.getClass().getResourceAsStream(
"/Resources/GIF.gif");
doc = new SimpleDoc(fis, psFlavor, daset);
pj = service.createPrintJob();
pj.print(doc, aset);
System.out.println(fis.toString() + " printed on "
+ service.getName());
}
} else {
System.out.println("flavor is not supported");
}
} else {
System.out.println("service not found");
}
System.out.println("======= END LookupDefaultPrintServiceTest =======");
}
开发者ID:shannah,项目名称:cn1,代码行数:40,代码来源:LookupDefaultPrintServiceTest.java
示例10: testSimpleDoc
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testSimpleDoc() {
startTest("SimpleDoc class testing...");
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
InputStream reader =
getClass().getResourceAsStream("/Resources/picture.gif");
if (reader == null) {
fail("/Resources/picture.gif resource is not found!");
}
DocAttributeSet aSet = new HashDocAttributeSet();
Doc doc = new SimpleDoc(reader, flavor, aSet);
assertEquals(doc.getAttributes(), aSet);
aSet.add(OrientationRequested.LANDSCAPE);
aSet.add(MediaName.NA_LETTER_WHITE);
assertEquals(doc.getAttributes(), aSet);
assertEquals(doc.getDocFlavor(), DocFlavor.INPUT_STREAM.GIF);
try {
assertTrue(doc.getPrintData() instanceof java.io.InputStream);
assertNull(doc.getReaderForText());
assertEquals(doc.getStreamForBytes(), reader);
} catch(Exception e) {
e.printStackTrace();
fail("Exception found: "+e);
}
}
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:ValueTests.java
示例11: testPrintAutosense
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testPrintAutosense() throws Exception {
System.out.println("======== START PrintAutosenseTest ========");
PrintService[] services;
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
daset.add(MediaSizeName.ISO_A4);
DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE;
InputStream fis = this.getClass().getResourceAsStream(
"/Resources/hello_ps.ps");
services = PrintServiceLookup.lookupPrintServices(df, null);
TestUtil.checkServices(services);
for (int j = 0; j < services.length; j++) {
PrintService printer = services[j];
if (printer.toString().indexOf("print-to-file") >= 0) {
doc = new SimpleDoc(fis, df, null);
pj = printer.createPrintJob();
pj.print(doc, null);
System.out.println(fis.toString() + " printed on "
+ printer.getName());
break;
}
}
System.out.println("====== END PrintAutosenseTest ========");
}
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:PrintAutosenseTest.java
示例12: testLookupPrintServices
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testLookupPrintServices() throws Exception {
System.out.println("======== START LookupPrintServicesTest ========");
PrintService[] services;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
Object[][] filetoprint = { { "/Resources/JPEG.jpg",
DocFlavor.INPUT_STREAM.JPEG },
{ "/Resources/GIF.gif", DocFlavor.INPUT_STREAM.GIF } };
DocFlavor df;
InputStream fis;
for (int i = 0; i < filetoprint.length; i++) {
df = (DocFlavor) filetoprint[i][1];
services = PrintServiceLookup.lookupPrintServices(df, aset);
TestUtil.checkServices(services);
for (int j = 0; j < services.length; j++) {
fis = this.getClass().getResourceAsStream(
(String) filetoprint[i][0]);
doc = new SimpleDoc(fis, df, daset);
PrintService printer = services[j];
pj = printer.createPrintJob();
pj.print(doc, aset);
System.out.println(fis.toString() + " printed on "
+ printer.getName());
}
}
System.out.println("====== END LookupPrintServicesTest ========");
}
开发者ID:shannah,项目名称:cn1,代码行数:38,代码来源:LookupPrintServicesTest.java
示例13: testLookupMultiDocPrintServices
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testLookupMultiDocPrintServices() {
System.out
.println("============= START LookupMultiDocPrintServicesTest ================");
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
MultiDocPrintService[] services;
FileInputStream fis;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
aset.add(new Copies(2));
aset.add(MediaSizeName.ISO_A4);
daset.add(MediaName.ISO_A4_WHITE);
daset.add(Sides.TWO_SIDED_LONG_EDGE);
try {
services = PrintServiceLookup.lookupMultiDocPrintServices(
new DocFlavor[] { psFlavor }, aset);
if (services != null && services.length > 0) {
fis = new FileInputStream("/Resources/1M.GIF");
doc = new SimpleDoc(fis, psFlavor, daset);
pj = services[0].createPrintJob();
pj.print(doc, aset);
System.out.println(fis.toString() + " printed on "
+ services[0].getName());
} else {
System.out.println("services not found");
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
System.out
.println("============= END LookupMultiDocPrintServicesTest ================");
}
开发者ID:freeVM,项目名称:freeVM,代码行数:40,代码来源:LookupMultiDocPrintServicesTest.java
示例14: testPrintJpeg
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testPrintJpeg() {
System.out.println("======== START PrintJpegTest ========");
PrintService[] services;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
daset.add(MediaSizeName.ISO_A4);
try {
DocFlavor df = DocFlavor.INPUT_STREAM.JPEG;
InputStream fis = this.getClass().getResourceAsStream(
"/Resources/JPEG.jpg");
services = PrintServiceLookup.lookupPrintServices(df, aset);
TestUtil.checkServices(services);
for (int j = 0; j < services.length; j++) {
PrintService printer = services[j];
if (printer.toString().indexOf("print-to-file") >= 0) {
doc = new SimpleDoc(fis, df, daset);
pj = printer.createPrintJob();
pj.print(doc, aset);
System.out.println(fis.toString() + " printed on "
+ printer.getName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
System.out.println("====== END PrintJpegTest ========");
}
开发者ID:freeVM,项目名称:freeVM,代码行数:38,代码来源:PrintJpegTest.java
示例15: testPrintAutosense
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public void testPrintAutosense() {
System.out.println("======== START PrintAutosenseTest ========");
PrintService[] services;
HashDocAttributeSet daset = new HashDocAttributeSet();
DocPrintJob pj;
Doc doc;
daset.add(MediaSizeName.ISO_A4);
try {
DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE;
InputStream fis = this.getClass().getResourceAsStream(
"/Resources/hello_ps.ps");
services = PrintServiceLookup.lookupPrintServices(df, null);
TestUtil.checkServices(services);
for (int j = 0; j < services.length; j++) {
PrintService printer = services[j];
if (printer.toString().indexOf("print-to-file") >= 0) {
doc = new SimpleDoc(fis, df, null);
pj = printer.createPrintJob();
pj.print(doc, null);
System.out.println(fis.toString() + " printed on "
+ printer.getName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
System.out.println("====== END PrintAutosenseTest ========");
}
开发者ID:freeVM,项目名称:freeVM,代码行数:37,代码来源:PrintAutosenseTest.java
示例16: getAttributes
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
public DocAttributeSet getAttributes() {
return new HashDocAttributeSet();
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:PageableDoc.java
示例17: print
import javax.print.attribute.HashDocAttributeSet; //导入依赖的package包/类
/************************************************************************
* 打印
*/
public void print() throws Exception {
try {
//搜寻打印机
PrintService printer = this.lookupPrinter();
if (printer == null) {
throw new NullPointerException("printer == null. 没有找到默认打印机!!!");
}
//日志输出打印机的各项属性
AttributeSet attrs = printer.getAttributes();
logger.info("****************************************************");
for (Attribute attr : attrs.toArray()) {
String attributeName = attr.getName();
String attributeValue = attrs.get(attr.getClass()).toString();
logger.info("*"+attributeName + " : " + attributeValue);
}
logger.info("****************************************************");
//创建打印数据
// DocAttributeSet docAttr = new HashDocAttributeSet();//设置文档属性
// Doc myDoc = new SimpleDoc(psStream, psInFormat, docAttr);
DocAttributeSet das = new HashDocAttributeSet();
Object printData = this.prepareData();
logger.info("#print. 开始打印, 数据资源-printData: "+printData);
if (printData == null) {
throw new NullPointerException("printData == null. 准备数据失败!!!");
}
doc = new SimpleDoc(printData, printFormat, das);
//创建文档打印作业
long start = System.currentTimeMillis();
logger.info("#print. 开始打印, 请稍候...");
DocPrintJob job = printer.createPrintJob();
job.print(doc, attributeSet);
logger.info("#print. 完成打印, 共耗时: "+(System.currentTimeMillis() - start)+" 毫秒.");
} catch (Exception e) {
// TODO: handle exception
logger.error("#print. print error.", e);
throw new Exception("打印过程中出现异常情况,打印没有完成,请检查!!!", e);
}
}
开发者ID:hanwwh,项目名称:xqres,代码行数:48,代码来源:CommonPrinter.java
注:本文中的javax.print.attribute.HashDocAttributeSet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论