Hi All,
I want to Print (Hard Copy) of my context Data,ie
I want to print data on local printer .
I tried by lots of ways but i could't get succes.
one of the way is that
One blank text file is copied to projects src/mime/component
folder and write the context data to that file.then send that file to printer,reading and writing of the file is woking fine but can't get the printout.
**Used Code**
public void onActionPrintData(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionPrintData(ServerEvent)
// method to print a file from the server
// a empty text file is created in src
mimes
Components
<package name>\<filename>
// the context data is written to this file in an event and then the file is directed towards the printer
try {
// creating a copy of the file on the server
File obj = new File("temp
webdynpro
web
local
TestTableEdit
Components
com.gpk.examples.testtableedit.TestTableEditApp
printData.txt");
FileWriter obj1 = new FileWriter(obj);
// looping through the context data.
obj1.write("Account Number");
obj1.write("\t");
obj1.write("Name of The Account Holder");
obj1.write("\t");
obj1.write("Available Balance");
obj1.write("\n");
for (int i = 0;i < wdContext.nodeResultAllAccountDetails().size();i++) {
obj1.write(wdContext.nodeResultAllAccountDetails().getResultAllAccountDetailsElementAt(i)
.getAccountNumber());
obj1.write("\t");
obj1.write(
wdContext
.nodeResultAllAccountDetails()
.getResultAllAccountDetailsElementAt(i)
.getName());
obj1.write("\t");
obj1.write(
wdContext.nodeResultAllAccountDetails()
.getResultAllAccountDetailsElementAt(i)
.getBalance()+ "");
obj1.write("\n");
}
obj1.close();
//reading the file
File obj5 =new File("temp
webdynpro
web
local
TestTableEdit
Components
com.gpk.examples.testtableedit.TestTableEditApp
printData.txt");
java.io.FileReader obj3 = new java.io.FileReader(obj5);
int count = (int) obj5.length();
char obj4[] = new char[count];
obj3.read(obj4);
wdContext.currentContextElement().setReadData(new String(obj4));
obj3.close();
} catch (Exception e) {
e.printStackTrace();
}
//*Printing Code*
FileInputStream psstream = null;
try {
psstream =new FileInputStream("temp
webdynpro
web
local
TestTableEdit
Components
com.gpk.examples.testtableedit.TestTableEditApp
printData.txt");
} catch (FileNotFoundException ffne) {
}
if (psstream == null) {
return;
}
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST ;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));
Doc myDoc = new SimpleDoc (psstream,psInFormat,null);
wdComponentAPI.getMessageManager().reportSuccess(myDoc.toString());
PrintService services = PrintServiceLookup.lookupDefaultPrintService();
PrintServiceLookup.lookupPrintServices(psInFormat, aset);
if (services.length > 0) {
DocPrintJob job = services.createPrintJob() ;
try {
job.print(myDoc, aset);
} catch (PrintException pe) {
}
}
//@@end
}
Its an uregent.
Plz Help me.
Thanx,
Sanjay