java网络打印机_Java直接打印到Postscript网络打印机

I am not sure you can do it without extra library.

This example shows you how to send the file to a network printer, but requieres an adobe library (based on commercial J2EE Livecycle ES though, so not a generic "free" solution...).

import com.adobe.livecycle.output.client.*;

import java.util.*;

import java.io.File;

import java.io.FileInputStream;

import com.adobe.idp.Document;

import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;

public class SendToPrinter {

public static void main(String[] args) {

try{

//Set LiveCycle ES service connection properties

Properties ConnectionProps = new Properties();

ConnectionProps.setProperty("DSC_DEFAULT_EJB_ENDPOINT", "jnp://localhost:1099");

ConnectionProps.setProperty("DSC_TRANSPORT_PROTOCOL","EJB");

ConnectionProps.setProperty("DSC_SERVER_TYPE", "JBoss");

ConnectionProps.setProperty("DSC_CREDENTIAL_USERNAME", "administrator");

ConnectionProps.setProperty("DSC_CREDENTIAL_PASSWORD", "password");

//Create a ServiceClientFactory object

ServiceClientFactory myFactory = ServiceClientFactory.createInstance(ConnectionProps);

//Create an OutputClient object

OutputClient outClient = new OutputClient(myFactory);

//Reference XML data that represents form data

FileInputStream fileInputStream = new FileInputStream("C:\\Adobe\\Loan_data.xml");

Document inputXML = new Document(fileInputStream);

//Set print run-time options

PrintedOutputOptionsSpec printOptions = new PrintedOutputOptionsSpec();

printOptions.setPrinterURI("\\\\Printer1\\Printer");

printOptions.setCopies(2);

//Send a PostScript print stream to printer

OutputResult outputDocument = outClient.generatePrintedOutput(

PrintFormat.PostScript,

"Loan.xdp",

"C:\\Adobe",

"C:\\Adobe",

printOptions,

inputXML);

//Write the results of the operation to OutputLog.xml

Document resultData = outputDocument.getStatusDoc();

File myFile = new File("C:\\Adobe\\OutputLog.xml");

resultData.copyToFile(myFile);

}

catch (Exception ee)

{

ee.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值